[antlr-interest] (newbie) how do action codes work?
ali azimi
aliaazimi at yahoo.com
Mon Sep 3 09:27:49 PDT 2007
Hello,
I have a problem which I have not been able to solve yet. Could you please have a look at it and give me your suggestions if any. Thank you very much in advance.
I have built a parser grammar, AST and tree walker which work fine. The parser parses a language called SDL-CIF which basically contains a series of symbols and their coordinates in SDL diagrams. For example:
/* CIF NextState (300,400) */
nextstate Generate ;
The above says: draw the symbol nextstate and label it Generate with the coordinates of 300 and 400.
Now I have embedded the codes to draw the symbols within tree walker as following:
{System.out.println(some codes);}
The output of the test rig when run will be some codes which will be executed and draw the graph. I have written the drawing codes as templates like the following:
(the language in blue is written in a drawing software environment)
nextstate:^(SLIST nextstatebody)
{System.out.println("nod4[shape=X, label='Y', pos='Z!', width=V, height=W, peripheries=0];");}
;
The X, Y, Z, V, W in the above need to get the information from AST to look something like the following:
nod4[shape=sdl_state,label='Generate',pos='2.5,5!',width=0.8,height=0.6,peripheries=0];
How can I tell the tree walker to do that? (I need to produce this kind of codes for many different shapes and their connections which are straight lines)
An exmple: I know I can use something like pos=$i ,$j to get the position for "pos" considering the rule b26a in my grammar:
b26 :b26a ;
b26a :i=INT ',' j=INT;
But is it correct? The INTs in b26a contain different integers at different times as the input contains different integer values. How can $i get the right information for a shape considering that many rules use the rule 26a and the INTs in b26a match different integers including page numbers, different shapes positions other than nextstate?
Best regards,
Al
---------------------------------
Got a little couch potato?
Check out fun summer activities for kids.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070903/70b2332e/attachment-0001.html
More information about the antlr-interest
mailing list