[antlr-interest] Re: Calc example LPAREN/RPAREN

kemmerzehl malitrait at start.com.au
Mon Dec 24 21:28:16 PST 2001

--- In antlr-interest at y..., "kemmerzehl" <malitrait at s...> wrote:
> Hi,
>   This is my first exposure to parsing etc. so please excuse my 
> ignorance. As an excersize in trying and figure this stuff out i 
> myself the task of modifying the calc example to support input such 
> as "(5+4)*3;" but i cannot figure out what im supposed to do. I 
> you guys probably hate these messages but im having trouble getting 
> my head around this and i havent been able to find "The Complete 
> Idiots Guide to ANTLR" or "ANTLR for Dummies" anywhere. Any help 
> would be greatly appreciated.
>   I've also noticed that you have the lexer creating the tokens 
> LPAREN and RPAREN yet these tokens are not being referenced by the 
> parser, and the example doesn't accept them as valid input - if 
> are not being used why are the there?
> Thanks,
> -Kemmerzehl

Ignore previous message, after some sleep i conquered it. I must say 
it was alot easier than i thought. my parser now looks like this:

class CalcParser extends Parser;
options {
    buildAST = true;   // uses CommonAST by default
formula: expr SEMI!
expr:   mexpr (PLUS^ mexpr)*
    :   atom (STAR^ atom)*
atom:   (INT|pexpr)
pexpr: LPAREN! expr RPAREN!

Although, i am still a little confused as to why the LPAREN and 
RPAREN tokens were there in the first place, but that is beside the 

Sorry to be a bother and thanks Terence this is really quite cool!


Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 

More information about the antlr-interest mailing list