|
|
|
Re: Difficulty with a grammar [message #34159 is a reply to message #34045] |
Thu, 26 March 2009 06:57 |
Sebastian Zarnekow Messages: 3118 Registered: July 2009 |
Senior Member |
|
|
Hi Jonathan,
seems to me, that the type InstructionGroupContents is superflous in
your grammar. The parser does not know, if the a section belongs to the
same InstructionGroupContents instance (is a child of), or if a new
InstructionGroupContent has to be instantiated for the section, that was
found.
Consider the following input:
Directions :
InstructionGroup :
Section : <- igc = new InstructionGroupContents() ..
Section : <- belongs this one to igc or igc2?
I would either introduce a keyword for InstrGroupContents or ommit it at
all (I'ld prefer the latter):
Directions:
'Directions' ':'? instructionGroups+=InstructionGroup+
| contents+=Section+;
InstructionGroup:
'InstructionGroup' id=ID ':'? contents+=Section+;
Section
'Section' ':'?;
Hope that helps,
Sebastian
Jonathan Whitall schrieb:
> I'm running into a bit of trouble trying to create my DSL. In my case,
> I'm trying to express than a Directions type can contain a list of
> InstructionGroup types OR a list of Section types. I have tried to
> represent it like this:
>
> Directions :
> 'Directions' ':'?
> (instructionGroups+=InstructionGroup)+ |
> (instructionGroupContents+=InstructionGroupContents)+;
>
> InstructionGroup :
> 'InstructionGroup' id=ID ':'?
> (instructionGroupContents+=InstructionGroupContents)+;
> InstructionGroupContents :
> ((sections+=Section)+);
> Section :
> 'Section' ':'?;
>
> but I get this error from Antlr when I go to generate:
>
> warning(200):
> ./com.knitml.kel.grammar/src-gen/com/knitml/parser/antlr/int ernal/InternalKel.g:438:1:
> Decision can match input such as "'Section'" using multiple
> alternatives: 1, 2
> As a result, alternative(s) 2 were disabled for that input
>
> Is there a better way to express this in the grammar so that I don't get
> this warning?
>
> I'm using XText with Eclipse 3.5M6 (the package downloaded from Itemis's
> website yesterday evening.)
>
|
|
|
Re: Difficulty with a grammar [message #34297 is a reply to message #34159] |
Thu, 26 March 2009 07:10 |
Sebastian Zarnekow Messages: 3118 Registered: July 2009 |
Senior Member |
|
|
Must have been to eager and missed Heikos post, who mentioned almost the
same ...
- Sebastian
Sebastian Zarnekow schrieb:
> Hi Jonathan,
>
> seems to me, that the type InstructionGroupContents is superflous in
> your grammar. The parser does not know, if the a section belongs to the
> same InstructionGroupContents instance (is a child of), or if a new
> InstructionGroupContent has to be instantiated for the section, that was
> found.
>
> Consider the following input:
>
> Directions :
> InstructionGroup :
> Section : <- igc = new InstructionGroupContents() ..
> Section : <- belongs this one to igc or igc2?
>
> I would either introduce a keyword for InstrGroupContents or ommit it at
> all (I'ld prefer the latter):
>
> Directions:
> 'Directions' ':'? instructionGroups+=InstructionGroup+
> | contents+=Section+;
>
> InstructionGroup:
> 'InstructionGroup' id=ID ':'? contents+=Section+;
>
> Section
> 'Section' ':'?;
>
> Hope that helps,
> Sebastian
>
>
>
> Jonathan Whitall schrieb:
>> I'm running into a bit of trouble trying to create my DSL. In my case,
>> I'm trying to express than a Directions type can contain a list of
>> InstructionGroup types OR a list of Section types. I have tried to
>> represent it like this:
>>
>> Directions :
>> 'Directions' ':'?
>> (instructionGroups+=InstructionGroup)+ |
>> (instructionGroupContents+=InstructionGroupContents)+;
>>
>> InstructionGroup :
>> 'InstructionGroup' id=ID ':'?
>> (instructionGroupContents+=InstructionGroupContents)+;
>> InstructionGroupContents :
>> ((sections+=Section)+);
>> Section :
>> 'Section' ':'?;
>>
>> but I get this error from Antlr when I go to generate:
>>
>> warning(200):
>> ./com.knitml.kel.grammar/src-gen/com/knitml/parser/antlr/int ernal/InternalKel.g:438:1:
>> Decision can match input such as "'Section'" using multiple
>> alternatives: 1, 2
>> As a result, alternative(s) 2 were disabled for that input
>>
>> Is there a better way to express this in the grammar so that I don't
>> get this warning?
>>
>> I'm using XText with Eclipse 3.5M6 (the package downloaded from
>> Itemis's website yesterday evening.)
>>
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03132 seconds