Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Decision can match input such as "'.'" using multiple alternatives: 1, 2
Decision can match input such as "'.'" using multiple alternatives: 1, 2 [message #819165] Mon, 12 March 2012 15:23 Go to next message
Steffen Schuette is currently offline Steffen SchuetteFriend
Messages: 26
Registered: August 2010
Junior Member
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 16:45 Go to previous messageGo to next message
Stefano Zanotti is currently offline Stefano ZanottiFriend
Messages: 22
Registered: March 2012
Junior Member
(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;
Re: Decision can match input such as "'.'" using multiple alternatives: 1, 2 [message #819322 is a reply to message #819227] Mon, 12 March 2012 19:20 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
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;
Re: Decision can match input such as "'.'" using multiple alternatives: 1, 2 [message #819709 is a reply to message #819165] Tue, 13 March 2012 08:26 Go to previous message
Steffen Schuette is currently offline Steffen SchuetteFriend
Messages: 26
Registered: August 2010
Junior Member
Hi,

of course *duh*. I should have figured out myself. Sorry.

The solution with many dots "..." is not nice, as you already said.
But as i need more than 2 levels of nesting, I will introduce some terminal symbol for a nesting level.

Thanks,

Steffen
Previous Topic:How to set file encoding of generated file from my dsl file
Next Topic:SetExpressions: Lists and Ranges
Goto Forum:
  


Current Time: Wed Apr 01 12:14:25 GMT 2020

Powered by FUDForum. Page generated in 0.02153 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top