|
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 |
Stefano Zanotti 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 ?
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 19:20 |
Henrik Lindberg 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;
|
|
|
|
Powered by
FUDForum. Page generated in 0.02979 seconds