Book a Demo

Author Topic: Code addition problems using the grammar editor  (Read 4304 times)

nsteve

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Code addition problems using the grammar editor
« on: June 26, 2014, 05:28:40 pm »
Hi,
I am trying to create a grammar for a language, that uses out of class definitions for methods like in C++:

class MyClass {
   void MyMethod();
};

void MyClass::MyMethod()  {
  .... Code/Behavior
}


How do I get the Code/Behavior into the AST?
Everything works using node("Methode", attribute("Code" , ...) ) in the grammar rules
when the method definition is inline.

They problem arises, when the method  definition does not appear inside the class definition.

Somehow I fail to associate the Method with the class.
I am stuck here - can you help.

Thanks.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Code addition problems using the grammar edito
« Reply #1 on: June 27, 2014, 08:52:39 am »
You'll need to specify in the options of your MDG technology file that EA needs to look for an implementation. You then need to ensure that your methods provide their qualified name to EA. It should be in the help doco but from memory you have two choices:
1. QUALIFIER=MyClass, NAME=MyMethod
2. NAMEPART=MyClass, NAMEPART=MyMethod

RoyC

  • EA Administrator
  • EA Practitioner
  • *****
  • Posts: 1297
  • Karma: +21/-4
  • Read The Help!
    • View Profile
Best Regards, Roy

nsteve

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: Code addition problems using the grammar edito
« Reply #3 on: June 27, 2014, 10:11:03 pm »
Thanks for your answers,
I tried your suggestions but am still stuck.
The implementation of the class methods is not in an extra file as in Delphi.
However I did try activating the flag in the CodeOptions with no observable changes.
I have attached the results of the grammar debugger - maybe you can spot my error (the dotted indentations represent the hierarchy levels)

Code: [Select]
FILE([173-957][0:0])
...PACKAGE073-957][6:1]): {NAME = Foo}
......CLASS([209-458][12:3])
.........DECLARATION([209-221][12:3]): {NAME = TFoo}
.........BODY([225-457][13:3])
............SCOPE([225-263][13:3]): {NAME = protected}
............SCOPE([267-450][15:3]): {NAME = public}
...............FIELD([279-294][16:5]) DECLARATOR([279-285][16:5]): {NAME = FCount} TYPE([287-294][16:13]): {NAME = Integer}
...............METHOD([301-318][17:5]) DECLARATION([301-318][17:5]): {NAME = Testlt}
...............METHOD([324-353][18:5]) DECLARATION([324-353][18:5]): {NAME = Create}
...............METHOD([359-403][19:5])
..................DECLARATION([359-403][19:5]): {NAME = Create}
.....................MULTI_PARAMETER([378-391][19:24])
.....................PARAMETER([378-385][19:24]): {NAME = theTFoo}
.....................TYPE([387-391][19:33]): {NAME = TFoo}
...............METHOD([409-428][20:5]) I>
...............METHOD([434-450][21:5])
......METHOD([508-581][28:1]): {CODE = begin
.........DECLARATION([520-546][28:13]): {QUALIFIER = TFoo, NAME = Create}
............MULTI_PARAMETER([532-545][28:25]) PARAMETER([532-539][28:25]): {NAME = theTFoo} TYPE([541-545][28:34]): {NAME = TFoo}
......METHOD([602-695][34:1]): {CODE = var b : integer;
.........DECLARATION([612-623][34:11]): {QUALIFIER = TFoo, NAME = Testlt}
......METHOD([716-774][43:1]): {CODE = begin
.........DECLARATION([728-739][43:13]): {QUALIFIER = TFoo, NAME = Create}
......METHOD([797-834][50:1]): {CODE = begin
.........DECLARATIONC808-82000:12]): {QUALIFIER = TFoo, NAME = Destroy}
......METHOD([857-949][56:1]): {CODE = var a: integer;
.........DECLARATIONC867-87706:111): {QUALIFIER = TFoo, NAME = Fuzzy}

Also I tried several variations of this using attributes instead of a declaration node, and using the NAME node instead of METHOD for the implementation.

Hope you can help.

Cheers, Stephan

nsteve

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: Code addition problems using the grammar edito
« Reply #4 on: July 11, 2014, 04:57:50 pm »
Hi everyone.

started from scratch, followed your advice to the letter and -
everything works fine now.

The problem was, that the code options somehow did not get through.
So I deleted all MDG technology files and in the model and regenerated them. This was obviously the problem - the grammar was not. Now I can round-trip with the latest Embarcadero Radstudio XE6 without problems.


Thank you!  :)