[antlr-interest] [C Target] Bug in AST walking , implementing control flow

Jim Idle jimi at temporal-wave.com
Tue Oct 27 06:08:54 PDT 2009


It probably is a bug I am afraid. 3.2.1 will be a 'catch up' release to ensure that everything works in C. You can make calls to LT() directly and so on though.

 

For index and related properties you should use the method calls rather than the fields directly, but if you know you will never override the structure types then you only have to worry if I change the names of the fields. This is not likely, but I don't guarantee not to do it. 

 

Nodes are valid between tree walks and rewrites so long as you do not free the node streams until you are completely done. You can dup a node outside the factory and then it will persist, but you need to free the memory.

 

Jim

 

From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Mohamed Yousef
Sent: Monday, October 26, 2009 10:42 PM
To: antlr-interest at antlr.org
Subject: [antlr-interest] [C Target] Bug in AST walking , implementing control flow

 

Hi,
on trying to implement control flow , in an AST walker grammar 
following this example : http://www.antlr.org/wiki/display/CS652/Tree-based+interpreters

ifstat


    :   ^('if' c=expr s=. e=.?) // ^('if' expr stat stat?)


in the C target the problem is that in the generated code , variables e,s are not defined! (yet they are assigned values )
and the compiler complains about that , when i do define them by hand (under the definition of variable c  )
the code compiles fine
so is this really a bug or i'm misusing ? any applicable workarounds ?
----
i have another question regarding control flow in c target
to get the index of say c in above example i write
c.tree->getToken(c)->index ,, right ? i can then SEEK to thins index , and i can save 
it in a symbol table , and it will be valid across different tree walks (walk filling symbol table and
the walk that really interprets code )  ,, right ?

Thanks,
Mohamed Yousef



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20091027/f6a1e575/attachment.html 


More information about the antlr-interest mailing list