[antlr-interest] Bug in ANTLRv3.g

Terence Parr parrt at cs.usfca.edu
Tue Jul 29 15:35:06 PDT 2008


ooops. try this:

ragment
NESTED_ACTION :
	'{'
	(	options {greedy=false; k=2;}
	:	NESTED_ACTION
	|	SL_COMMENT
	|	ML_COMMENT
	|	ACTION_STRING_LITERAL
	|	ACTION_CHAR_LITERAL
	|	.
	)*
	'}'
    ;
Ter
On Jul 29, 2008, at 2:33 PM, Víctor Manuel Sánchez Cartagena wrote:

> Thank you very much. I changed the rule and now it doesn't fail in:  
> c[""]
> But it still fails in: $value= "class " + $ID.text + " n;" + "}n";
>
> In fact, ANTLR gives an error in every string that starts with }.
>
> In this case, I get the following output:
>
> line 26:0 mismatched character '<EOF>' expecting '"'
> line 19:62 no viable alternative at input 'n'
> BR.recoverFromMismatchedToken
>
>
> 2008/7/29 Terence Parr <parrt at cs.usfca.edu>
> Ooops. change rule
>
> fragment
> ACTION_STRING_LITERAL
>        :       '"' (ACTION_ESC|~('\\'|'"'))* '"'
>        ;
>
> + to *
>
> Ter
>
>
> On Jul 29, 2008, at 10:53 AM, Víctor Manuel Sánchez Cartagena wrote:
>
> I think I have found a bug in the ANTLRv3.g grammar.
> I build the lexer and the parser with ANTLR, and when I try to parse  
> the  following grammar, it fails, although the grammar is correct.
>
> grammar plp2;
> @members {
>  public String refactor_rename_this;
>  public String refactor_rename_to;
> }
> s returns [String value]
>    :
>                // It doesn't fail:
>                 c["aa"]
>                // It fails:
>                //c[""]
>    ;
> c[String ambito] returns [String value]
>    :    'class' ID
>        {
>                     // It doesn't fail:
>                      $value= "class " + $ID.text + " n;" + "{}n";
>                     // It fails:
>                     // $value= "class " + $ID.text + " n;" + "}n";
>                }
>    ;
> ID    :    ('a'..'z'|'A'..'Z')('a'..'z'|'A'..'Z'|'0'..'9')*
>    ;
> ENTERO    :    ('0'..'9')+
>    ;
>
> Could anyone help me to find out what's wrong in ANTLRv3.g?
>
>



More information about the antlr-interest mailing list