Making an typed expression system, how to go about it?

Good day, 

I am creating DSL. For the calculations, I want to build expressions. I have a limited set of types for the results. So far I have created simple expressions, but they don't work nicely because I have to declare everything specifically. I can't just type 1 + 1 and be done with it. I have been thinking of reusing an existing system (such as from the BaseLanguage) but I have no idea on how to go about it and I have trouble finding information that makes this clear to me. 

I want to be able to create variables like so:

<Type> <Name> = <Expression>

Where the <Expression> can be constructed from sub-expressions, combined through operands. I'm sure you get the general idea.

Can anyone help me with achieving this?

1
7 comments

You need to make your language extend BaseLanguage and your concept for variables declare "initializer" to be "Expression" from BaseLanguage. Obviously, Java will be generated for your expressions.

 

1
Avatar
Permanently deleted user

Ah, yeah, I just got something like that working. Is there a way I could rename some of the BaseLanguage concepts? To make it fit better with the required DSL.

0

You can change the visual appearance of nodes by defining a new editor for them in your language.

1
Avatar
Permanently deleted user

Alright, thank you very much! If I were to reuse the variable assignment as well (since it works the same), how could I block out all the unused classes? 
I am just making an example, so it wouldn't be such an issue if they were stil visible, but it would be nice.

0
Avatar
Permanently deleted user

Is there also a way to replace the used aliases?

0

To customise the completion menus, you'd have to re-define the editors and attached your own transform menus. The way to define them is described at https://confluence.jetbrains.com/display/MPSD20171/Transformation+Menu+Language

1
Avatar
Permanently deleted user

Thank you!

0

Please sign in to leave a comment.