[antlr-interest] Need help on optional rule parts and stringtemplates

Lothar Burow lothar at b-welcome.de
Wed Aug 22 14:17:23 PDT 2007


Gurus,

I hope that's not too much an RTFM (or RTDAR :-)) question, but as a new ANTLR fan, I'm stuck with the problem below and would appreciate any help.

I'm trying to use ANTLR and Stringtemplates (great!) to write a little compiler for a 20 year-old processor, understanding an assembly-like language for process control systems. I would like to implement a sort of step chain with an if-else construct. My AST has the following structure:
^('if' ^(EXPR logExp) statement (^('elsif' ^(EXPR logExp) statement))*)

(where 'statement' is also a block of statements).

How do I need to set up my string templates in order to get the optional elsif subtrees emitted? I could probably split up the rule (first hack didn't work for me, though), but this looks not quite elegant to me. Is there a way to translate those constructs directly to stringtemplate syntax?

My next problem then is that I need to identify (and pass it to the stringtemplate) the "current block number" I'm in, while executing the statement block, to implement some memory management (number to be used as a reference to a memory cell). Any good advice on how to do this?

Any help will be very much appriciated. I'm a real newbie (and,yes, a book reader) in ANTLR and I like it very much, since I've collected some experience with lex and yacc in the "good old days" :-)



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


More information about the antlr-interest mailing list