Generation into my language Follow
I wanted to define a generator from my sourceLanguage into targetLanguage, but can't figure out how to define a template in targetlanguage.
In popup menu "Create Root Node" there is only TLBase. In model properties for "templates" I have targetLanguage.structure imported.
could you advise what is wrong?
Please sign in to leave a comment.
Hi, add the 'targetLanguage' to the template model's languages (because you are going to use this language to write templates).
importing of targetLanguage.structure is not necessary.
It was already added automatically when I started to define a generator sourceLanguage->targetLanguage, but I can't create template in targetLanguage..
do you have 'root'-able concepts in your targetLanguage?
Now I have and it looks much better now - I can define the template.
But I face another problem now - when I run the generator, it complains about generator class, and none of existing generator classes seems suitable...
What generator class should I use?
Is there any tutorial on how to generate from language A to language B, not only to java?
In the project attached you will find myxml (source language), myFunctions (target language) and generator myxml --> myFunctions.
Generation of model "mps.forum.recursivegen.myxml.test1" (in solution 'test') will produce file 'A.function'.
Take a look at myFunctions language's properties: there are two differences comparing to properties of a regular language:
- plugin class : mps.forum.myFunctions.plugin.MyFunctionsPlugin
- target of generator :
generator class : mps.forum.myFunctions.generator.target.MyFunctionsGenerator
Also, there is some staff written in java (in 'source' folder): generator.target, plugin and textGen.
I hope this will help.
Do I have to write my own generator for each pair (source language, target language)? Is there something like generic generator that uses templates+queries?
Do you mean 'generator class'?
I'll add the default one. check in next buid. Thanx for feedback!
I've tried that example and came up with a few more questions
- class Function_TextGen is not referenced from any mps project file. Is there some sort of name convention?
- 'Generate text' and 'Generate file' generate the same content, just 'Generate file' outputs it to the file, right? What if I want to generate not the text, but binary data? Is related to custom model persistence?
- My idea is to generate not the file, but another MPS model (or root node) in targetLanguage, in the same solution, perhaps stored using custom persistence mechanism. Can I do that?
Sorry for lots of questions, but I have a few more :-)
What I want to create is a language describing configuration of certain hardware periperals, and then describe certain hardware configurations of different hardware.
Typically, modern harware has a bunch of registers, typically 8 bits long. These registers control the hardware behaviour - certain combination of bits in these registers define how the hardware works.
Example of a typical register file:
bit7: 1=enable periperal X, 0=disable
bits 6-0: value for periperal X
bits 7-4: reserved
bits 3-2: value A for periperal Y
bits 1-0: value B for periperal Y
What I was thinking about, is defining a small but generic language "Bit field definition language", BFDL, that will be used to define other specific "register file definition languages" for different types of hardware.
Configuration A1 of Hardware A: A1 is model in language A.
Configuration A2 of Hardware A: A2 is model in language A.
Configuration B1 of Hardware B: B1 is model in language B.
Configuration B2 of Hardware B: B2 is model in language B.
At the same time, languages A and B are also models, defined in BFDL.
Can I do that? First, to define a language in structureLanguage, and then define new languages not in structureLanguage but in my language?
Yes it is.
package = and classname = _TextGen
Custom persistence would help. Unfortunately, MPS doesn't support generation to output model so far. At least it doesn't support it well.
I can only propose to encode the binary data into a string somehow and generate transient files. Then process those files with an external utility which would decode 'text' and write final binary files.