Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » If, then and else Structure
If, then and else Structure [message #635810] Thu, 28 October 2010 08:22 Go to next message
Fran Blanco is currently offline Fran BlancoFriend
Messages: 20
Registered: October 2010
Junior Member
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 #635843 is a reply to message #635810] Thu, 28 October 2010 10:53 Go to previous messageGo to next message
Bodo is currently offline BodoFriend
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 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
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 #636637 is a reply to message #635810] Tue, 02 November 2010 10:10 Go to previous messageGo to next message
Fran Blanco is currently offline Fran BlancoFriend
Messages: 20
Registered: October 2010
Junior Member
Hiii!

Thank you so much for your answer...!!

How can i enable backtracking? I dont want to add some token in the end of the if-else structure...!!!


Thankyou so much!!!

B
Re: If, then and else Structure [message #636691 is a reply to message #635810] Tue, 02 November 2010 13:31 Go to previous messageGo to next message
Pierre-Alain BOURDIL is currently offline Pierre-Alain BOURDILFriend
Messages: 25
Registered: September 2010
Junior Member
hi,

try adding :
  options = {
					backtrack = true
				}


in your XtextAntlrGeneratorFragment and XtextAntlrUiGeneratorFragment fragments.

Btw, is there any drawback of using backtracking, such as perf or mem consumption ?

Re: If, then and else Structure [message #637118 is a reply to message #635810] Thu, 04 November 2010 09:33 Go to previous messageGo to next message
Fran Blanco is currently offline Fran BlancoFriend
Messages: 20
Registered: October 2010
Junior Member
I dont know how to find this fragments :S
Where should i look for? :S
Re: If, then and else Structure [message #637426 is a reply to message #637118] Fri, 05 November 2010 12:50 Go to previous message
Jan Koehnlein is currently offline Jan KoehnleinFriend
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
Previous Topic:Can't get Importing Namespaces to work
Next Topic:mark "src-gen" as eclipse derived resource
Goto Forum:
  


Current Time: Fri Apr 19 12:58:10 GMT 2024

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

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

Back to the top