[antlr-interest] lexical nondeterminism question.

Trey Spiva Trey.Spiva at embarcadero.com
Tue Jun 25 07:21:17 PDT 2002


I need to be able to support the syntax.
 
&h<HEX DIGITS>
&h<HEX DIGITS>&
&o<OCTAL_DIGITS>
&o<OCTAL_DIGITS>&
 
The problem is that I also need to support the string concatenation syntax
 
<STRING> & <STRING>
 
Notice that I need to be able to use the amperstand for hex numbers, octal
numbers and string concatenation.
So, I have tried the following lexer rules.  
 
NUM_INT
options {
   paraphrase = "number";
}
            {boolean isDecimal=false;}
            :           
      ( options { warnWhenFollowAmbig=false; greedy=true; } 
      :
         '.' {_ttype = DOT;} (('0'..'9')+ (EXPONENT)? { _ttype = NUM_FLOAT;
})?
                  |     ('0'..'9') ('0'..'9')*  {isDecimal=true; _ttype =
NUM_INT;}                   // non-zero decimal
                              ( // only check to see if it's a float if
looks like decimal so far
                                 {isDecimal}? ( '.' ('0'..'9')* (EXPONENT)?
{ _ttype = NUM_FLOAT; }
                                              | EXPONENT { _ttype =
NUM_FLOAT; }
                            | '&'     // indicates that the number is of
type Long
                            | // Nothing.  This will be the else part.
                            )
                              )?
          |  ('&' 'h')=>'&' 'h' HEX_INT ('&')?   {_ttype = NUM_INT;}
          |  ('&' 'o')=>'&' 'o' OCTAL_INT ('&')? {_ttype = NUM_INT;}
      )
            ;
 
 
AMPER          :  '&'     ;
 
Understandably I get the following warning
 
warning: lexical nondeterminism between rules NUM_INT and AMPER upon
k==1:'&'
k==2:<end-of-token>
k==3:<end-of-token>
 
I thought that since I have the syntactic predicate before the hex and octal
options that the lexer would correctly map the string concatenation operator
as a AMPER however it is recognizing 
 
<STRING> & <STRING> 
 
as <STRING> NUM_INT <STRING> does any one have any ideas.
 
Trey Spiva
Senior Software Engineer
trey.spiva at embarcadero.com
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20020625/99001b8b/attachment.html


More information about the antlr-interest mailing list