how to write a generator

I've created a language describing the configuration of MCP25050 chip and a model written in this language, and would like to generate a binary file (~40 bytes) from the model.

Could you suggest how can one write this generator? In general, if a certain class just accepts SModel it would be enough, but it would still be a lot of coding...

Ideally, there should be a set of rules (mapping) saying something like

byte

{

   bits 7-2: the value of property Name1 of concept X1

   bits 1-0: the value of property Name2 of concept X2

}

byte

{

   bits 7-2: the value of property Name1 of concept X1

   bits 1-0: the value of property Name2 of concept X2

}

byte

{

   bits 7-0: bits 9-2 of the property Value of concept X3

}

Do I have to create this mapping language or can I "tune" the existing one? (TLBase?) Do I have to define a 'target language' for that? How can I define a language which is kust a collection of bytes? (even a fixed number of bytes)

I can post the specific examples if you want

3 comments
Comment actions Permalink

Do you really need a generator?

If your language semantically at the same level as data in binary files you rather need custom persistence for your models.

0
Comment actions Permalink

Well, it is not exactly at the same level..

What I have now is the abstract model of some "device" which is optimised for easy "programming"/configuration by human using an editor (mps). In real life, data is organized similarly but not exactly in the same way. There is the concept of "registry file", and all data are cut and spread over a set of 8-bit registers (bytes). So, I think, the proper way would require designing another language for modeling "low-level" device configuration and the transformation from "higher level" to this new "low level, close to real life" language, which would have easy and straightforward 1:1 custom persistence to a binary file.

Anyway, working with mps is not really convenient now, 'cause I have to restart it every 5 min otherwise memory is running out and mps hangs or corrupts project files. Defining an editor means that concept should be declared in advance and the whole language be regenerated, which takes a lot of time.. Especially enums - there is high risk that a project will be corrupted if enum is defined simultaneously with something else. So I'm not ready for designing another language right now but would like to try custom persistence if you suggest it.

I'm a little bit confused about the terms, though. *.java files are created in examples, will you call it "custom persistence of model in java language"? Does "generation" now mean "transformation from model m1 in language l1 into model m2 in language l2 and applying custom persistence for language l2"?

0
Comment actions Permalink

Anyway, working with mps is not really convenient

now, .... Defining an editor means that

concept should be declared in advance and the whole

language be regenerated, which takes a lot of time..

Especially enums - there is high risk that a project

will be corrupted if enum is defined simultaneously

with something else.

right. obviously, we need something like make

I'm a little bit confused about the terms, though.

*.java files are created in examples, will you call

it "custom persistence of model in java language"?

no, it is generation.

Does "generation" now mean "transformation from model

m1 in language l1 into model m2 in language l2 and

applying custom persistence for language l2"?

generation:

M1(L1) --> M2(L2) [-<reduce>-> M2(L2*)] -<tex?gen>-> persistence: --> M -->

as you can see, persistence supports roundtrip but generation is more powerful in oneway transformation.

Igor

0

Please sign in to leave a comment.