[antlr-interest] Help Needed with multiple alternatives

Jim Idle jimi at temporal-wave.com
Tue Feb 26 07:00:37 PST 2008


Woah there! You are being misguided a bit here I think. Such warnings
are real in that there are two ways that ANTLR could decide your grammar
is structured and it is telling you that it is going to assume the alt
other than the one it tells you is disabled. However, it is usually
telling you this for a good reason. The reason is either that there is
something actually wrong with your grammar, or that there is something
wrong with the structure of your grammar. You should certainly not
ignore such messages as they are far from irrelevant.

 

Here, I think you need to look at the precedence of your operators with
respect to let. Then you probably would still end up with a warning
because at a glance it seems there is a real ambiguity in the language.
You can probably get rid of the warnings (once you rework this  a
little) with small precedents if there is a real ambiguity in your
language. I tend to do this just so I get a clean analysis and don’t
miss any new warning that comes up. If you are the author of your
language then consider that you might change it so that there are no
ambiguities. For instance, is let really a part of the expression tree?

 

There is a (known) need to be able to turn off a particular warning for
a particular decision in ANTLR, but of course you should only do this
when you absolutely understand what it means and realize why you can
turn it off. Don’t train yourself to ignore such warnings, learn how to
turn them off as this will increase your knowledge of what is going on.

 

In your grammar, the operators it is complaining of can associate with
the expr that ends the let expr, which is probably what you are
expecting, or the expr that contains the let as an expr. Your grammar
allows let to be the expr that is part of a let, so you can have let x
in let y in let b in g ->yyyy  etc . SO, which let clause did you mean
it to belong to? That is what ANTLR is telling you.

 

Jim

 

From: Alexander Gängel [mailto:alexander at gaengel.de] 
Sent: Tuesday, February 26, 2008 6:29 AM
To: antlr-interest at antlr.org
Subject: Re: [antlr-interest] Help Needed with multiple alternatives

 

So it's not an "error" in my Grammar.
If this is so I'm glad, I spend hours to find a Way around this Message.

I was starting to think I just don't understand what Antlr is doing.

So I just discard dis Message.

Alexander

shmuel siegel schrieb: 

I am not 100% sure that I am reading the red diagram correctly but this
is my take on the problem. The green diagram says that an ARROW can
follow an exp_direct as part of the dotorarrow rule. The red diagram
says that the exit condition of dotorarrow (that is, a set of null
transitions) can also lead to ARROW. This is caused by letexpression
ending in exp which can ultimately be a dotorarrow. I don't know how to
avoid the warning but I think both alternatives are equivalent.
Alternative 1, the green arrow, is computationally more efficient and is
probably what you want.

The bottom line is that there is an annoying irrelevant warning message
that is hard to circumvent.
I would also appreciate any feedback on methods to avoid this kind of
ambiguity.

Shmuel

Alexander Gängel wrote: 

I still have this Problem but I think I search in the wrong spot.

can somebody explain me which rule makes the Problem?

Thanks
Alexander

Alexander Gängel schrieb: 

I found the problem but still have no working solution. 

I tried to get around it by using scoping and Semantic Predicates. 

so I set a scope with a boolean man variable and wanted to make a
decision like {$exp::name}=> ... | so that the rule chooses the first
alternative when $exp::name is set true and the other solution if it is
false. 

Is this possible, cause right now it's not working, but there may be
some other error still in the rule. 

Alexander 

Alexander Gängel schrieb: 



I just can't get my grammar to work without having a multiple
alternatives problem. 

I have some nested expression rules to get the precedence of the
different operations. 

The problem occures since I added the letexpression  rule to exp_direct 

I hope someone can give me a hint how to solve this. 

Thanks Alexander 

 

 


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080226/2ba116df/attachment.html 


More information about the antlr-interest mailing list