[antlr-interest] Syntactic predicate - simple case
Timothy Washington
timothyjwashington at yahoo.ca
Tue Sep 5 15:47:16 PDT 2006
Hey all, I'm trying to write some lexer rules for XML
<starttag> and <emtytag/>. Now both tags can start
with "<tag (attr)*". A start tag ends with ">" while
an empty tag ends with "/>". Having similar lexer
rules for both gives me a lexical non-determinism for
the first chunk of text. I think I can use a syntactic
predicate for this problem, but I'm still getting
errors with the following syntax:
I'missing something basic here. If I want to match on
the ">" for the EMTYTAG, should my rule look like A.
B. or C.
A. ( STARTCHUNK (WS)? "/>" )=> g:( STARTCHUNK
(WS)? "/>" )
B. ( STARTCHUNK )=> g:( STARTCHUNK (WS)?
"/>" )
C. ( STARTCHUNK )=> g:( "/>" )
Lexer Rules:
EMPTYTAG:
( STARTCHUNK (WS)? "/>" )=> g:( STARTCHUNK
(WS)? "/>" ) //*** line 150
{ System.out.println("EMTYTAG: "+g.getText());
};
STARTTAG:
( STARTCHUNK (WS)? '>' )=> g:( STARTCHUNK
(WS)? '>' )
{ System.out.println("STARTTAG:
"+g.getText()); };
STARTCHUNK:
( '<' g:NAME ( WS )? ( ATTR ( WS )? )* )
{ System.out.println("STARTCHUNK:
"+g.getText()); } ;
Errors:
grammar/bookkeeping.lexer.g: warning:lexical
nondeterminism between rules EMPTYTAG and STARTCHUNK
upon
...
grammar/bookkeeping.lexer.g: warning:lexical
nondeterminism between rules EMPTYTAG and STARTTAG
upon
...
grammar/bookkeeping.lexer.g: warning:lexical
nondeterminism between rules STARTCHUNK and STARTTAG
upon
...
grammar/bookkeeping.lexer.g:150: warning:Syntactic
predicate ignored for single alternative ()
Tim
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
More information about the antlr-interest
mailing list