[antlr-interest] Bug in ANTLRv3.g
Víctor Manuel Sánchez Cartagena
vitaka at gmail.com
Thu Aug 7 11:26:45 PDT 2008
Thanks Terr. I modified the grammar as you suggested and it doesn't fail
now.
But I discovered a new bug:
If I add a "header" action with a comment inside, I get the following error:
BR.recoverFromMismatchedToken
line 6:0 mismatched input '@' expecting ACTION
But if I remove the comment, I get no errors.
This is the grammar:
grammar plp2;
@header
{ //comment
import java.lang.String;
}
@members {
public String refactor_rename_this;
public String refactor_rename_to;
}
s returns [String value]
:
c[""]
;
c[String ambito] returns [String value]
: 'class' ID
{
$value= "class " + $ID.text + " n;" + "} n";
}
;
ID : ('a'..'z'|'A'..'Z')('a'..'z'|'A'..'Z'|'0'..'9')*
;
ENTERO : ('0'..'9')+
;
2008/7/30 Terence Parr <parrt at cs.usfca.edu>
> 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?
>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080807/0fa20bd8/attachment-0001.html
More information about the antlr-interest
mailing list