[antlr-interest] non-determinism error

Jay O'Leary j_f_oleary at yahoo.com
Wed Sep 14 15:09:10 PDT 2005


Hello:
 
I'm new to ANTLR and I'm trying to construct a very simple grammar that can parse a string in the form "A / B C /D" to produce a boolean query.  The twist is that if A,B, C, or D is in the form <city>,<stateabbrev>  (eg: orlando, FL)  I have to handle that specially.
 
I'm starting with a very simple lexer to handle WORDS, COMMAS, AND SLASH and a very simple parser which will print out the tokens.
 
However, when I compile the grammar file, I get the error:
foo.g:3: warning:nondeterminism between alts 1 and 2 of block upon
foo.g:3:     k==1:"FL",WORD
 
I have tried various predicates to work around the conflict to no avail.
 
Also, if I have a string such as "a b / c d / e" the whole string is parsed.
However, as soon as I add a state abbreviation such as "a b / FL c d / e" everything after and including the state abbreviation seems to get swallowed up.
 
I realize this is a "newbie" question but if anyone could point me in the right direction, I would greatly appreciate it. 
 
Thanks,
Jay
 
GRAMMAR FILE BEGINS HERE:
=========================
class P extends Parser; 
expr 
     : subexpr (slash subexpr)* 
     | subexpr
     ; 
subexpr
     : word (word)* {System.out.println("in subexpr");}
     | subexpr2
     ;
subexpr2
     : stateabbrev
     ;
stateabbrev
     : "FL" {System.out.println("in state abbrev");}
     ;
word 
     : w:WORD {System.out.println("token: "+w.getText());}
        ;
slash
    : s:SLASH {System.out.println("slash: "+s.getText());}
    ;

class L extends Lexer; 
options {
 k=2;
}

SLASH: ('/');
WORD
    : ( 'a'..'z' | 'A'..'Z' | '0'..'9' | '\'' | '-')+ 
    ; 
COMMA: ( ',')
     ;
// whitespace 
WS : (
     ' '
     | '\t' 
     | '\r' '\n' { newline(); } 
     | '\n' { newline(); } ) 
     {$setType(Token.SKIP);} //ignore this token 
    ; 
 

		
---------------------------------
Yahoo! for Good
 Click here to donate to the Hurricane Katrina relief effort. 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20050914/ed0c5f29/attachment.html


More information about the antlr-interest mailing list