Thank You, now I understand my mistake. However, can You give me a bit bigger example? All relevant tutorials seem to be for ANTLR v2 ( http://www.antlr.org/wiki/display/ST/Language+Translation+Using+ANTLR+and+StringTemplate ) and syntax seems to bee changed more than I can understand.
Georg Jim Idle <[email protected]> wrote on 26 May 2010, 06:43 PM: Subject: Re: [antlr-interest] parsing rules >Your s: rule needs to set $st to something too or it will return an empty >template :-) >Jim > >> -----Original Message----- >> From: [email protected] [mailto:antlr-interest- >> [email protected]] On Behalf Of George Soom >> Sent: Wednesday, May 26, 2010 4:01 AM >> To: [email protected] >> 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 > 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 [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=en.
