[antlr-interest] Re: nondeterminism warning?
Xue Yong Zhi
seclib at seclib.com
Thu Jan 26 10:57:33 PST 2006
To understand this warning you have to be very familiar with "linear
approximate lookahead".
I recommend the following articles:
http://www.antlr.org/doc/glossary.html#Linear_approximate_lookahead
and related entries in antlr's FAQ.
http://seclib.blogspot.com/2005/11/linear-approximate-lookahead.html
In your case, antlr needs to compute exit branch to know when to leave a
loop, and it will use linear approximate lookahead(instead of full
LL(K)) to do that. Normally there are several exit paths for a rule, for
example:
"[ assembly {"
and "[ xxx :"
With linear approximate lookahead, antlr will compress them so you get
the warning for "[ assembly :".
You can check the generated code so if it is actually correct(there are
a great chance it does even with the warning), if so we can shutdown the
warning. Otherwise, use semantic predict or syntax predict.
Dima wrote:
>>>
>>>With this part, I become this warning:
>>> nondeterminism upon k==1:LBRACK k==2:"assembly" between alt 1 and
>>>exit branch of block
>>>
>>
>>Please be more clear with your question, which rule causes this
>>warning(copy the entire antlr output please)?
>
>
>>If the warning comes from c_unit, it is because global_attributes and
>>attribute_section can both start with LBRACK "assembly", and antlr can
>>not distinguish when k = 2.
>>
>
>
> Ok sorry, with k=2 it can't work, but I use k>=3.
> It's true, the warning comes from c_unit.
> With this rules global_attributes must be:
> [ assembly : ... (for k=3)
> But attributes can be:
> [ assembly ] ... or
> [ assembly , ... or
> [ assembly ( ... or
> [ type : ...
> That's all not the same
>
> If I make attributes rule like this:
> LBRACK "type" COLON RBRACK
> I get the same warning.
> Antlr output:
> test1.g:39: warning:nondeterminism upon
> test1.g:39: k==1:LBRACK
> test1.g:39: k==2:"assembly"
> test1.g:39: k==3:COLON
> test1.g:39: between alt 1 and exit branch of block
>
>
> Thanks!
>
> Dima
>
>
--
Xue Yong Zhi
http://seclib.blogspot.com
More information about the antlr-interest
mailing list