0

I'm going to write an inferrer for my dsl and I have some questions that I could not solve with only the help of documentation.

First one: I need to create static void main() from a feature: how can I add static with .toMethod()?

Second one: Suppose I have a rule in my dsl like this:

Sequence:
    'SEQ' name=ID '{'
        statements+=Statement*
    '}'
;

Where Statement:

Statement:
    Sequence | others...
;

Sequence must be mapped to a void method and the body of that method is composed from the traslation of statements. But the problem is this: when inside a Sequence I'll find another Sequence I have to create a method for the new sequence and add a call in super sequence.

For example:

SEQ first {
   instructions...
   SEQ second {
      other instructions....
   }
   instructions...
}

Must generate:

void first(){
   instructions(translated)...
   second();
   instructions(translated)...
}
void second(){
   other instructions(translated)...
}

Is it possible to realize it?

Tommaso DS
  • 211
  • 2
  • 14
  • 1
    I am not sure these two questions are linked. If they are not, you'd better ask to separate questions – rds Jan 02 '13 at 09:30

1 Answers1

1

First question:

ctx.toMethod('main', ctx.newTypeRef(Void.Type)) [
  static = true
  ….
]

Second question:

Implying that with 'instructions' you mean instances of 'XExpression', you need to trick a bit, as it is currently not possible to compose new expressions during inference. What you coudl basically do is to make your Sequence a subtype of XExpression. Then during JvmModelInference you need to walk over your expression tree (Statement) and create methods for Sequences. you need to override the XbaseTypeComputer as well as the XbaseCompiler and add type computation and compile strategies for your expressions. The latter would be a call to the method created during inference.

Sven Efftinge
  • 3,065
  • 17
  • 17