[antlr-interest] not parsing to end of input

Mark Volkmann r.mark.volkmann at gmail.com
Mon Dec 10 13:51:15 PST 2007


Thanks to both Shmuel and Tom! That fixed it.

On Dec 10, 2007 3:25 PM, shmuel siegel <antlr at shmuelhome.mine.nu> wrote:
> Mark Volkmann wrote:
> > Okay, here's a new, short grammar that illustrates the problem. Try
> > feeding the following two lines into it using the ANTLRWorks debugger.
> > You'll see that it stops before the semicolon on the first line and
> > doesn't parse the rest.
> >
> > print f(x);
> > print a;
> >
> > ---
> >
> > grammar problem;
> >
> > options {
> >   output = AST;
> > }
> >
> > tokens {
> >   PRINT;
> >   SCRIPT;
> > }
> >
> > print
> >   : 'print' NAME '(' v=(NUMBER | NAME) ')' -> ^(PRINT NAME $v)
> >   | 'print' NAME -> ^(PRINT NAME)
> >   ;
> >
> > script: (print TERMINATOR)* EOF -> ^(SCRIPT print*);
> >
> > NAME: 'a'..'z';
> > NEWLINE: '\r'? '\n' { $channel = HIDDEN; };
> > NUMBER: '0'..'9';
> > TERMINATOR: ';';
> > WHITESPACE: (' '|'\t')+ { $channel = HIDDEN; };
> >
> >
>
> The rewrite rule doesn't know what to do with $v. Define v as (v=NUMBER
> | v=NAME).
>
>



-- 
R. Mark Volkmann
Object Computing, Inc.


More information about the antlr-interest mailing list