[antlr-interest] backtracking and return value error: attribute is not a token, parameter or return value, bug?

Charles Hymans charles.hymans at gmail.com
Wed Jul 14 10:05:21 PDT 2010


I am trying to return a value for a rule in a grammar with backtrack set to
true. Strangely, Antrl (version 3.1.2) does not accept me to set the return
value and outputs the following error:
error(114): Bug.g:11:19: attribute is not a token, parameter, or return
value: value

Is this a bug? Am I doing something wrong? Or is it simply a known
limitation?
How am I suppose to proceed to make my grammar work with return values ?
(I want to avoid rewriting my grammar into LL form, since I care more about
the clarity of the grammar than performances + I don't want to invest too
much time in grammar hacking)

Here is the full grammar (in a file named Bug.g):

// this problem seems to be related to backtract = true!!
grammar Bug;

options
{
    language   = CSharp2;
    backtrack  = true;
}

compilation_unit returns [int value]:
  identifier '1'  { $value = 1; }
| identifier '2'  { $value = 2; }
;


identifier:
  'x'
| 'x' '.' identifier
;


More information about the antlr-interest mailing list