Decision can match input such as "'.'" using multiple alternatives: 1, 2 [message #819165] |
Mon, 12 March 2012 11:23  |
Eclipse User |
|
|
|
Hi,
I'm using Xtext for more than a year but I still don't get it. I reade several other threads with examples and solutions for this problem but I cannot transfer it to my problem. I'm using Xtext 2.0 and have the following grammar:
-------------
Model:
(PlanungsKategorien);
PlanungsKategorien:
{PlanungsKategorien}
'PlanungsKategorien'
planungsKategorien += PlanungsKategorie*;
PlanungsKategorie:
name=INT text=STRING ('.'subkategorie+=PlanungsKategorie)*;
-------------
And, as you experts may already see, I get the following error:
warning(200): /parser/antlr/internal/InternalDsl.g:217:2: Decision can match input such as "'.'" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
I don't see the problem. I also visualized this using the ANTLR Workbench.
The DSL usage should look like this:
1 "Category1"
.1 "Subcategory1"
.2 "Subcategory2"
Where is the ambiguity?
Thanky so much
Steffen
|
|
|
Re: Decision can match input such as "'.'" using multiple alternatives: 1, 2 [message #819227 is a reply to message #819165] |
Mon, 12 March 2012 12:45   |
Eclipse User |
|
|
|
(first of all, I'm not sure, but maybe you should wrap this in parens: (planungsKategorien += PlanungsKategorie)*)
It's like a dangling-else problem: where does C belong to? To A or B ?
i.e. is it
[like 1 "A" (2 "B" 3 "C")]
or
[like 1 "A" (2 "B" (3 "C"))]
I think that this is easily solvable only if every '.' means "subcategory of the very last typed category", but this doesn't seem the case.
Do you want to allow for arbitrary nesting?
i.e.
1 "A"
.2 "B"
.3 "C"
..4 "D"
If this is the case, you should add something (like further '.'), in order to tell which nesting level a category belongs to.
I have no idea about how to do this via syntax only; I can only think of this (followed by a validation that counts the dots and assign each subcategory to its parent category):
PlanungsKategorien:
'PlanungsKategorien'
('.'* INT STRING)*;
That's not a nice solution, maybe others can think of something better.
Or, if you simply want to allow for a single level of nesting, you should introduce another rule, to avoid recursion:
PlanungsKategorie:
INT STRING (PlanungsKategorieLevel2)*;
PlanungsKategorieLevel2:
'.' INT STRING;
|
|
|
Re: Decision can match input such as "'.'" using multiple alternatives: 1, 2 [message #819322 is a reply to message #819227] |
Mon, 12 March 2012 15:20   |
Eclipse User |
|
|
|
As Stefano points out it is the "dangle else" problem.
You can solve it by requiring that a sub category is terminated with a
token, or always interpret '.' as either a sub category (or sibling) -
and then allow the user to use some way to escape that decision.
Or use different tokens.
Regards
- henrik
On 2012-12-03 17:45, Stefano Zanotti wrote:
> (first of all, I'm not sure, but maybe you should wrap this in parens:
> (planungsKategorien += PlanungsKategorie)*)
>
>
> It's like a dangling-else problem: where does C belong to? To A or B ?
> 1 "A"
> 2 "B"
> 3 "C"
> i.e. is it
> 1 "A"
> .2 "B"
> .3 "C"
> [like 1 "A" (2 "B" 3 "C")]
>
> or
> 1 "A"
> .2 "B"
> .3 "C"
> [like 1 "A" (2 "B" (3 "C"))]
>
> I think that this is easily solvable only if every '.' means
> "subcategory of the very last typed category", but this doesn't seem the
> case.
> Do you want to allow for arbitrary nesting?
> i.e.
> 1 "A"
> .2 "B"
> .3 "C"
> ..4 "D"
> If this is the case, you should add something (like further '.'), in
> order to tell which nesting level a category belongs to.
> I have no idea about how to do this via syntax only; I can only think of
> this (followed by a validation that counts the dots and assign each
> subcategory to its parent category):
> PlanungsKategorien:
> 'PlanungsKategorien'
> ('.'* INT STRING)*;
> That's not a nice solution, maybe others can think of something better.
>
> Or, if you simply want to allow for a single level of nesting, you
> should introduce another rule, to avoid recursion:
> PlanungsKategorie:
> INT STRING (PlanungsKategorieLevel2)*;
> PlanungsKategorieLevel2:
> '.' INT STRING;
|
|
|
|
Powered by
FUDForum. Page generated in 0.23658 seconds