[antlr-interest] Return value as attribut is not found. Is it a bug?
yradenac at irisa.fr
yradenac at irisa.fr
Tue Aug 19 22:35:52 PDT 2008
Hi,
Maybe I have found a bug, or, since I am new to antlr, maybe I have missed
something...
In my project, I am using the antlr3 Java grammar provided on the antlr
wiki (in fact, I am only interested in a subset of the Java expressions).
When I run antlr it ends with the following error:
error(114): test.g:0:0: attribute is not a token, parameter, or return
value: expr
Error line 0, character 0 does not help, and since I have called many
return values "expr" it took me some time to find the problematic "expr".
I finally found that it comes from the following rules (I have simplified a
lot the code part to focus on the parameter/return value problem):
primary returns [Expression expr]
: parExpression
| 'this' ('.' Identifier)* identifierSuffix[$expr]? // <<<<==== Here
| 'super' superSuffix
| literal
| 'new' creator
| Identifier ('.' Identifier)* identifierSuffix[$expr]? //
<<<<==== and here
| primitiveType ('[' ']')* '.' 'class'
| 'void' '.' 'class'
;
identifierSuffix[Expression argExpr] returns [Expression expr]
: ('[' ']')+ '.' 'class'
| ('[' expression ']')+ // can also be matched by selector, but do here
| arguments
| '.' 'class'
| '.' explicitGenericInvocation
| '.' 'this'
| '.' 'super' arguments
| '.' 'new' innerCreator
;
I have noticed that if the options are removed (ie remove both question
marks), it does not generate the error (ie antlr finds the return value
name); if we change both '?' to '*' or '+', it still generates the error.
I have also noticed that using a token like
i=Identifier ('.' Identifier)* identifierSuffix[$i.text]?
does not yield an error, but generates a wrong Java code:
identifierSuffix($i.text);
Once again, removing the question mark "solves" the issue; still I do not
want to force an identifier suffix here.
I have used antlr-3.0.1 and antlr-3.1, both ends up with the same error.
I have attached the Java grammar that I have just edited with the above
modification (file test.g).
So, is it a bug ? or have I missed something ?
For the moment, I am investigating a workaround using a stack in the
parser class just for this problem.
Thanks for your help.
Yann.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.g
Type: application/octet-stream
Size: 18748 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20080820/10876b56/attachment.obj
More information about the antlr-interest
mailing list