[antlr-interest] unexpected token when AST rewrite is used

Terence Parr parrt at cs.usfca.edu
Sun Jun 15 06:14:06 PDT 2008


Oh, right. on a rule ref?  What would that mean?  Onlyworks on tokens.
Ter
On Jun 14, 2008, at 5:39 AM, Bernardo Elayda wrote:

> Hi!
> I switched to 3.1b1 but still got the same error:
> $ java org.antlr.Tool Test.g
> ANTLR Parser Generator  Version 3.1b1 (May 20, 2008)  1989-2008
> error(100): Test.g:11:27: syntax error: antlr: Test.g:11:27:  
> unexpected token: 0
>
> Looks like it still doesn't like the rule with the argument as a  
> child node of a rewrite. I'm including the grammar here.
>
> Any suggestions are welcome.  I'm gonna refactor my grammar.
> tia,
> Bernardo Elayda
> ----------------------------
> grammar Test;
>
> options {
>     output=AST;
> }
>
> tokens {
>     MYPROGRAM;
> }
>
> a : b[0]+ -> ^(MYPROGRAM b[0]+)
>   ;
>
> b[int i] : .
>          ;
>
>     NUMBER : DIGIT+ ('.' DIGIT+)? ;
> IDENTIFIER : ('a'..'z'|'A'..'Z') ('a'..'z'|'A'..'Z'|'0'..'9')* ;
>    COMMENT : '#' (options {greedy=false;} :.)*  
> '\n' {$channel=HIDDEN;} ;
>         WS : ('\n'|'\r'|' '|'\t') {$channel=HIDDEN;} ;
>
> fragment DIGIT : '0'..'9' ;
>
>
> On Fri, Jun 13, 2008 at 1:06 AM, Terence Parr <parrt at cs.usfca.edu>  
> wrote:
> I'd suggest trying 3.1b1.
> Ter
>
> On Jun 13, 2008, at 9:58 AM, Bernardo Elayda wrote:
>
> Hi,
> Why does Antlr 3.0.1 complain that a token is unexpected for the  
> rule called B which has a single argument:
>
> a : b[0]+ -> ^(MYPROGRAM b[0]+)
>   ;
>
> I can only get Antlr to accept the above rule if I do this:
>
> a : b[0] -> ^(MYPROGRAM b+)
>
> Are rules with arguments not allowed as child nodes in an Antlr AST?
>
> tia,
> Bernardo Elayda
>
>
>



More information about the antlr-interest mailing list