JetBrains MPS just to create highlighting? - mps

Is it true that MPS was made not to create a programming language, but to create syntax for an already created language (highlight)?

No, that is not true. You can make any language (generic programming language or domain specific language) in MPS that you could also make with your own custom parser/compiler, and more. Because MPS supports multiple notations (provided you install some plugins like the diagram, tables, or math notation plugins), you can make languages with directly editable concrete syntaxes, which are not only textual, but for example a diagram, a math formula, a table, a tree, or a mix of various notations.

Related

TextGen generate different programming langugages code from one concept

I have a concept (let's call it A) that is being generated into a Ruby class using TextGen. I want to have the possibility to generate the same concept into other languages e.g Python. Could someone describe how to do it or some hint?
I recommend you use plaintextgen plugin (https://plugins.jetbrains.com/plugin/8444-com-dslfoundry-plaintextgen) for this. You can then just use reduction rules to generate the text. A tutorial for this can be found here: https://dslfoundry.com/plaintextgen-tutorial/
Using textgen aspect is also possible, but is much more involved for your use case, because it requires either that you have an existing MPS language for each text-based target language (Python, Ruby, C#, etc.) or that you implement a minimum version (at least containing the concepts and textgen aspects for the constructs you need in your generation result) of such a target language yourself.

Is it possible to make a proxy between IDE and language server?

Say, I want to slightly change the behavior of some language.
Can this be done? Has it been done before?
UPD: Typescript has very limited possibilites to work with property names (for example you can not with the help of typescript create a propname that is derived from another one, e.g. uppercased or with a prefix prepended), whereas Javascript (which is what Typescript compiles to) is very flexible. So I wanted with the help of LSP to modify some of the Typescript's LSP messages that carry autocompletion options.
Yes, but how to do that is operating system specific. From the compiler's point of view, the proxy would appear as your IDE. LSP is a network protocol
I want to slightly change the behavior of some language.
So you want to change the semantics of some language (and you don't tell which). Then LSP is not the best place to do so.
For example, in some simple cases, with GCC, writing your GCC plugin is more appropriate.
In most cases, changing the "behavior" is really changing the language itself. Then you might need to make your own implementation of that language. Sometimes, you might patch an existing free software implementation of the original languages. In other cases, you'll need to make your language implementation by yourself. Then read the Dragon Book and consider compiling or transpiling to C your language in your language implementation. Be sure to specify it on paper first.
Don't confuse a programming language (which is a specification, generally written in English - perhaps with some formalization in some specific notation, e.g. n1570 for C11, R5RS for Scheme) with its implementation (which is a software). Read Scott's Programming Language Pragmatics.
Don't confuse an IDE with a language implementation. For example, all C or C++ compilers I know about don't have any IDE and are command line programs (e.g. GCC, Clang, etc...), and most of them don't even know about LSP. The IDE might start the C++ compiler, but it is not a compiler. You can code (in C, C++, Java, C#, Ocaml, ....) with a plain source code editor (even a simple language-agnostic one such as Notepad on Windows, or Leafpad or nano on Linux).
Most programming languages are defining source programs as a set of "translation units", practically of "source files", each being a sequence of characters with some complex syntax and semantics. How these source files are created is outside of the scope of the programming language specification (you could use editors, you could write your own generators for these source files, ....)
LSP is a proposal for a protocol between "IDE"s and language implementations.
Notice that autocompletion (mentioned in your comment) is not a feature of the programming language (and is not part of the semantics of C or C++). It might be a feature of some IDEs (not all of them). It could be done in a language neutral way (e.g. in Emacs).

Tool for automated porting and language that can compile into others

I'm just asking this out of curiosity :
Is there any tool that can automatically convert a source code of reasonable complexity from one language to another ?
Is there any "meta-language" that can compile into several other languages ? For example CoffeeScript compiles into Javascript.
If you know any open-source example, it'd be great !
Thank you for your time.
PS: No idea how to tag this. Feel free to edit.
GCC converts complex C++ code into machine code and thus technically is an answer to your question. In fact, there are lots of compiler like this, but I don't think these are what you intended to ask.
There are tools that are hardwired to translate just one language to another as source code (another poster suggested "f2C", which is a perfect example). These are just like compilers... but rarer.
There are virtually no tools that will map from one language to many others, out of the box. The problem is that languages have different execution models, data types, and execution schemes, which such a translator has to simulate properly in the target language.
The are "code generators" that claim to do this, but they are largely IMHO specifications of rather simple functions that translate trivially to simple code in the target langauge.
If you want to translate one language to another in a sort of general way, you need a program transformation system, e.g., a system that can parse arbitrary langauges, and for which you can provide translation rules that map to other languages in a sort of straightforward way.
Our DMS Software Reengineering Toolkit is one of these. This SO What kinds of patterns could I enforce on the code to make it easier to translate to another programming language? discusses the issues in more detail.
You can convert Fortran code to C using the f2c tool.
For python, you can convert a subset of the language to C++ using shedskin.
The vala language is converted to C before the real compilation.

Distinctive characteristics of programming languages [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
Beyond the syntax of each language (e.g. print v. echo), what are some key distinctive characteristics to look out for to distinguish a programming language?
As a beginner in programming, I'm still confused between the strengths and weaknesses of each programming language and how to distinguish them beyond their aliases for common native functions. I think it's much easier to classify languages based on a set of distinctive characterstics e.g. OOP v. Functional.
There are many thing that define a PL, here I'l list a few:
Is it procedural, OO, imperative?
Does it has strong type checking(C#, C++, Delphi) or dynamic(PHP, Pythong, JS)
How are references handled? (Does it hide pointers like C#?)
Does it require a runtime (C#, Java) or is it native to the OS(C, C++)
Does it support threads (E.g Eiffel needs extra libraries for it)
There are may others like the prescense of garbage collectors, the handling of params, etc. The Eiffel language has an interesting feature which is Design By Contract, I haven't seen this on any other language(I think C# 4.0 has it now), but it can be pretty useful if well used.
I would recommend you to take a look on Bertrand Meyer's work to get a deeper understanding on how PL's work and the things that define them. Another thing that can define a PL is the interaction level with the system, this what makes the difference between low-level languages and high-level languages.
Hope I can help
In a domain (imperative, functional, concatenative, term rewriting), sometimes its best to look at the presence or absence of any particular set of functionality. For example, for the main stream imperative.
First order functions
Closures
Built in classes, prototypical inheritance, or toolkit (Example: C++, Self/JavaScript, Lua/Perl)
Complex data types (more than array)
In-built concurrency primitives
Futures
Pass by values, pass by name, pass by reference or an combination thereof
Garbage collected or not? What kind?
Event-based
Interface based types, class based types, or no user types (Go, Java, Lua)
etc
You can consider things like:
Can you call functions?
Can you pass functions to other functions?
Can you create new functions? (In C you can pass function pointers to functions, but you cannot create new functions)
Can you create new data types?
Can you create new data types with functions that operate on them? (the typical basis for "OO" languages)
Can you execute code that was not available at compile-time (using an eval function, maybe)?
Must all types be known at compile-time?
Are types available at run-time?
The difference between low-level and high-level languages. (Even though "low" and "high" are relative terms.)
A high-level language will use an abstraction to hide details that low-level languages would expose to the user. For example, in Matlab or Python, you can initialize an N-dimensional array in a single command. Not so in C or assembly.
IMHO the strength of a language is given by how many things you can do with it; how fast and how easy can you accomplish the goals.
The weaknesses of a language are the sum of constraints (of various types) that you encounter while you try to achieve your goal.
There are many features that a programming language may support. Additionally these features aren't always mutually exclusive. For example OCaml and F# are both functional and object oriented. Also writing a list here of all the paradigms that a language can support would be exhaustive, however there is a book Programming Language Pragmatics that is a comprehensive treatment of many paradigms found in programming languages.
However, for me the important things I need to know when working with a language are the following:
Is it dynamically or statically typed
Is it a typed language, and if it is typed is strong or weak?
Is it garbage collected
Does it support pass by value or pass by reference semantics or both?
Does it support first order functions (i.e. can functions be treated as variables)
Is it object-oriented
Polymorphism. Is it parametric or ad-hoc.
How expressive is the type system (i.e. can I create non-leaky abstractions)
Overloaded methods
Generics (templates)
Exception handling.
Type system (typed vs untyped, statically vs dynamically typed, weakly and strongly typed).
Supported paradigms (procedural, object-oriented, functional, logic, multi).
Default implementation (compiler vs interpreter vs JIT-compiler).
Memory management (manual vs automatic (reference counting or GC)).
Intended domain of use (number crunching, prototyping, scripting, DSL, ...).
Generation (1GL, 2GL, 3GL, 4GL, 5GL).
Used natural language (English vs Non-English-based). However, it's about syntax.
General remark: many of this classification scheme are not comprehensive and are not that good. And links are mostly at Wikipedia. So be aware.
You can consider other characteristics such as:
Strong vs weak and static vs dynamic typing, support for generic typing
How memory is handled (is it abstracted or do you have direct control over your data, pass by ref vs pass by value)
Compiled vs interpreted vs a bit of both
The forms of user-defined types available... classes, structures, tuples, lists etc.
Whether threading facilities are inbuilt or you need to turn to external libraries
Facility for generative coding... C++ template metaprogramming is a form of this
In the case of OOP, single vs multi inheritance, interfaces, anonymous/inner classes etc.
Whether a language is multi-paradigm (i.e. C# and its support for functional programming)
Availability of reflection
The verbosity of a language or the amount of 'syntactic sugar'... e.g. C++ is quite verbose when it comes to iterating over a vector. Java is quite succinct when anonymous inner classes are used for event-handling. Python's list comprehensions save a lot of typing.

Textual representation for UML class diagrams - DSL for UML

UML classdiagrams are a standard graphical notation to describe classes and their relationships.
Is there a standard textual notation (DSL) to describe the same? Don't say XMI or EMF;-)
I think you could do that with Corba IDL and use Interfaces for classes, but this is somehow too much on the Corba side. You could use Java Interfaces, but this is too Java.
Background of my question is writing generators. I think it is easier to write a generator based on the syntax tree of a DSL than to parse a graphical notation. A graphical notation first has to be translated into a syntax tree (that would be the same you'd get from the corresponding DSL). I think translating a graphical notation into the syntax tree is harder than to translate a DSL (where you can use ANTLR).
You've got the answer already, but I'd like to clarify. There is a standard notation, it's called HUTN, and nobody uses it.
Check this complete list of textual notations to describe UML models. Btw, the reasons to create one of these tools (in particular TextUML) can be find here.
It is no coincidence that UML separates abstract and concrete syntax.
Tying up code generation to a user-facing notation is a bad idea. Tools (code generators) and people (modelers) have totally distinct needs, so no single syntax can serve both audiences well. Not to mention you lose the ability of applying the same code generator to models created using different notations.
TextUML is a concrete syntax tailored to modelers. XMI is a much better notation for tools, and the UML2 object model makes it very easy to handle.
Rafael
http://abstratt.com/blog
No standard notation to my knowledge but a good summary of options here.
hth.

Resources