[antlr-interest] not parsing to end of input

shmuel siegel antlr at shmuelhome.mine.nu
Mon Dec 10 13:25:38 PST 2007


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).



More information about the antlr-interest mailing list