[antlr-interest] Error in number recognition

shmuel siegel antlr at shmuelhome.mine.nu
Fri Mar 7 06:46:34 PST 2008


A few comments first.
0) I am guessing that antlr is complaining about a rule ambiguity (you 
don't say what the problem is). I am not sure since I can't duplicate 
what I think your problem is.
1) From your comment in parenthesis, it seems that you think that Lexer 
rules (those that start with a capital letter) are called from the 
parser. They are not. The lexer runs by itself to change a character 
string to a token string. The parser then sees if it recognizes the 
token string. So a lexer rule is ambiguous if the lexer doesn't know 
what token to generate.
2) The versions of ANTLR that I use object to referring to different 
parser rules with the same variable. So the expression rule generates 
bad code with regard to "r".

More seriously for me, I don't know why ANTLR is not complaining that 
Number, String and CompleteString are ambiguous. They look ambiguous to me.

Shmuel

Pierre Attar wrote:
> Hi,
>
> I hav a problem with number recognition. I use the following reduced 
> grammar for recognizing sentences such as tensor[1,char[x],char[y]].
>
> My problem ? When the DiacriticalNumber  is commented, everything goes 
> well ; when it is active, antlr complains (even if it is not formally 
> used in this reduced debugging grammar).
>
> It seems that I have a problem with the rule but I do not understand 
> which one.
>
> grammar mff;
> m : e=expression ;
> expression :  (r=atomOp  | r=tensorOp ) ;
> atomOp  :    (r=charact);
> charact : 'char[' String  ']';
> tensorOp      : 'tensor[' Number    ',' expression     (',' expression 
> )+ ']'    ;
>
> //DiacriticalNumber     : ('0'..'9')+  ','  ('0'..'9')+  ','  
> ('0'..'9')+  ','  ('0'..'9')+  ','  ('0'..'9')+;
>
> StringNumber
>    : ('\n0022'|'"') Number ('\n0022'|'"'); Number : ('0'..'9')+;
> Decimal : ('0'..'9')+ '.' ('0'..'9')+;
> String :     Letter+;
> CompleteString :     (Letter | '0'..'9')+;
> fragment Letter :     'a'..'z'|'A'..'Z';
>
>
> Thanks a lot for help, Pierre
>
>
>
>




More information about the antlr-interest mailing list