[antlr-interest] nondeterminism issue for dummies ?
Loring Craymer
craymer at warpiv.com
Mon Jul 10 01:10:06 PDT 2006
ANTLR can't see past the leading whitespace; you want to do something like
( ( (WS)* "axi.") => (WS)* "axi." // include
whitespace in synpred
( "locate"
|
"reject"
)
|
(~('a')) (~('\n'|'\r'))*
)
CRLF
The non-determinism is real in this case.
--Loring
_____
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Michiel Vermandel
Sent: Monday, July 10, 2006 12:59 AM
To: antlr-interest at antlr.org
Subject: [antlr-interest] nondeterminism issue for dummies ?
Hi,
another nondeterminism issue...
The issue is in deciding between a single-line comment rule or a directive
rule.
A single-line comment is "--" (two minus signs) followed by anything untill
the end of the line.
A directive is "--"(two minus signs) follwed by spaces or tabs, then
followed by some reserved words such as "axi.locate" or "axi.reject"
So:
"-- hello world" CRLF
is a comment
"-- axi.locate blabla" CRLF
is a directive.
My rule works though gives a nondeterminism warning.
Rule:
--------------------------------
SL_COMMENT
: "--"! (
(
(' '| '\t')*
(
("axi.locate") => ( "axi.locate" { _ttype =
AXI_DIRECTIVE; } )
|("axi.reject") => ( "axi.reject" { _ttype =
AXI_DIRECTIVE; } )
)
)
| (~('a')) (~('\n'|'\r'))*
)
CRLF
;
Warning:
------------------------------
ANTLR Parser Generator Version 2.7.5rc2 (2005-01-08) 1989-2005 jGuru.com
FormsLexerSnip.g:20:24: warning:lexical nondeterminism between alts 1 and 2
of block upon
FormsLexerSnip.g:20:24: k==1:'\t',' '
FormsLexerSnip.g:20:24: k==2:'\t',' ','a','x'
FormsLexerSnip.g:20:24: k==3:'\t',' ','a','i','x'
FormsLexerSnip.g:20:24: k==4:'\t',' ','.','a','i','x'
Any ideas how to rewrite this rule so it parses without warning?
Or just ignore the warning?
Thanks a lot!
Have a great weekend!
Michiel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20060710/58c77458/attachment-0001.html
More information about the antlr-interest
mailing list