|
Re: If, then and else Structure [message #635843 is a reply to message #635810] |
Thu, 28 October 2010 10:53 |
Bodo Messages: 27 Registered: August 2010 |
Junior Member |
|
|
Hi Fran Blanco,
you reproduced the old and famous dangling else problem.
The parser generator can't decide how to reduce a sentence to a non terminal in this case, because if you write this:
IF ( a ) THEN IF ( b) THEN DO .. ENDDO ELSE S where shall the 'S' belong to? To the 1st or the 2nd THEN?
You can solve this by let the IF-THEN-ELSE clause end with some thing like ENDIF
Bodo
[Updated on: Thu, 28 October 2010 10:55] Report message to a moderator
|
|
|
Re: If, then and else Structure [message #635961 is a reply to message #635810] |
Thu, 28 October 2010 18:12 |
Sebastian Zarnekow Messages: 3118 Registered: July 2009 |
Senior Member |
|
|
Hi Fran,
Bodo is right. Either introduce an explicit end-token for your
if-statement or enable backtracking.
Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
Am 28.10.10 10:22, schrieb Fran Blanco:
> Hi everyone,
>
> Im creating the if, then and else structure and i have a little problem
> with i have added the else estructure...
>
> Here we go:
>
>
>
> IF:
> if='IF'
> ('COND')? '(' ID ')' '+'?
> 'THEN'? then=(GRUPODO |COMANDOUNICO);
> GRUPODO:
> '(' 'DO' ')' (comandos+=Statements)+ 'ENDDO' |
> 'DO' (comandos+=Statements)+ 'ENDDO';
>
> COMANDOUNICO:
> '(' comando=Statements ')' |
> comando=Statements;
>
> No errors.
>
> When I add else structure:
>
>
> IF:
> if='IF'
> ('COND')? '(' ID ')' '+'?
> 'THEN'? then=(GRUPODO |COMANDOUNICO)
> ('ELSE' else=(GRUPODO |COMANDOUNICO))?;
>
> GRUPODO:
> '(' 'DO' ')' (comandos+=Statements)+ 'ENDDO' |
> 'DO' (comandos+=Statements)+ 'ENDDO';
>
> COMANDOUNICO:
> '(' comando=Statements ')' |
> comando=Statements;
>
> Errors or Warnings:
>
> warning(200):
> ../org.xtext.clanguage/src-gen/org/xtext/parser/antlr/intern
> al/InternalCLanguage.g:2096:2: Decision can match input such as "'ELSE'"
> using multiple alternatives: 1, 2
> As a result, alternative(s) 2 were disabled for that input
> 10911 [main] INFO or.validation.JavaValidatorFragment - executing
> generate for org.eclipse.xtext.generator.validation.JavaValidatorFragment
> warning(200):
> ../org.xtext.clanguage.ui/src-gen/org/xtext/ui/contentassist
> /antlr/internal/InternalCLanguage.g:6185:1: Decision can match input
> such as "'ELSE'" using multiple alternatives: 1, 2
> As a result, alternative(s) 2 were disabled for that input
> 13224 [main] INFO .emf.mwe2.runtime.workflow.Workflow - Done.
>
>
> What could I put Else structure to avoid this warnings?
>
> Thzzz
>
> B
|
|
|
|
|
|
Re: If, then and else Structure [message #637426 is a reply to message #637118] |
Fri, 05 November 2010 12:50 |
Jan Koehnlein Messages: 760 Registered: July 2009 Location: Hamburg |
Senior Member |
|
|
Hint: There's an MWE2 file close to your grammar ;-)
Am 04.11.10 10:33, schrieb Fran Blanco:
> I dont know how to find this fragments :S
> Where should i look for? :S
>
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
---
Get professional support from the Xtext committers at www.typefox.io
|
|
|
Powered by
FUDForum. Page generated in 0.03762 seconds