[antlr-interest] Building hierarchical grammars

Mike Lischke lists at lischke-online.de
Sun Mar 28 06:32:18 PST 2004


Hi again,

Another little issue I currently encounter is a warning for lexical nondeterminism for rules like:

INTEGER_LITERAL: DECIMAL_NUMBER_LITERAL | HEX_NUMBER_LITERAL | OCTAL_NUMBER_LITERAL;
...	

LITERAL:    INTEGER_LITERAL | FLOATING_POINT_LITERAL | CHARACTER_LITERAL | STRING_LITERAL;

I have many similar rules where I build parts of a complex rule in subrules and glue them then together to the main rule. Unfortunately, I get now for each of these compositions a lexical nondeterminism warning, in this case:

V:\Eclipse projects\ParserTest\Grammar\Test.g: warning:lexical nondeterminism between rules INTEGER_LITERAL and LITERAL upon
V:\Eclipse projects\ParserTest\Grammar\Test.g:     k==1:'0'..'9'
V:\Eclipse projects\ParserTest\Grammar\Test.g:     k==2:<end-of-token>,'0'..'9','l','x'

Sure is there a kind of ambiguity since certain input sequences can be detected by both rules. But that is the very nature of hierarchical grammar building, isn't it. How am I supposed to write this down and still keep the same level of readability? Btw: defining INTEGER_LITERAL as protected would help but is not a general solution. In this very case I even need both rules for my parser (in different parser rules).

Help is much appreciated.

Mike
--
www.soft-gems.net




 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
     antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/
 



More information about the antlr-interest mailing list