Your s: rule needs to set $st to something too or it will return an empty 
template :-)
Jim

> -----Original Message-----
> From: antlr-interest-boun...@antlr.org [mailto:antlr-interest-
> boun...@antlr.org] On Behalf Of George Soom
> Sent: Wednesday, May 26, 2010 4:01 AM
> To: antlr-interest@antlr.org
> Subject: [antlr-interest] parsing rules
> 
> Hi,
> 
> I have to rewrite several files with mathematical text in them. Text
> substitutions are really simple (e.g. 'a=4' -> 'a:=4;' and similar).
> Input is in form:
> ----
> a=4
> b=3
> draw(a)
> draw(b)
> ----
> 
> Needed output
> -----
> a:=4;
> b:=3;
> draw(a, "constant arguments")
> draw(b, "constant arguments")
> ----
> 
> The best option I have found is to use StringTemplate. At chapter 9.3
> in
> book 'The Definitive ANTLRD reference' has a suitable example.
> To explain my probelm I will add lines from two examples:
> Grammar:
> 
> grammar T;
> options {output=template;}
> s : ID '=' INT ';' -> assign(x={$ID.text},y={$INT.text}) ;
> ---lexer part not pasted---
> 
> Test.java
> --header, input, parser-lexer generation etc. not pasted---
> parser.setTemplateLib(templates); // give parser templates
> TParser.s_return r = parser.s();      // parse rule s
> StringTemplate output = r.getTemplate();
> System.out.println(output.toString());// emit translation
> 
> This will work fine. But if I change rule s to
> s: assign+;
> assign: ID '=' INT ';' -> assign(x={$ID.text},y={$INT.text}) ;
> 
> I have to call parse.assign() to get correct results. How can i still
> parse
> starting from rule 's' and get desired output?
> 
> George
> 
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address




List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to