Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Assignments and function output have same sintax(non-LL(*) decision)
Assignments and function output have same sintax [message #985883] Fri, 16 November 2012 14:51 Go to next message
Tommaso De Sica is currently offline Tommaso De SicaFriend
Messages: 131
Registered: March 2012
Location: Italy
Senior Member

I've got a situation that can be summarized with this little code:

Instruction:
   EmptyInstruction | Assignment;

EmptyInstruction: ';';

Assignment:
   variable=[Variable]':='expression=Expression';' ;

Function:
   'FUNCTION' name=ID
   instructions+=Instruction*
   output=[Function]':='expression=Expression';' ;


I know where is the problem, but how can I resolve the non-LL decision?

Very thank you for help.

[Updated on: Fri, 16 November 2012 14:52]

Report message to a moderator

Re: Assignments and function output have same sintax [message #986163 is a reply to message #985883] Mon, 19 November 2012 09:22 Go to previous messageGo to next message
Boris Brodski is currently offline Boris BrodskiFriend
Messages: 112
Registered: July 2009
Senior Member
I see no problem with this (Xtext 2.3.1). Enhanced with some more rules it works for me:

Grammar:
Model:
	(functions += Function)*;
	
Instruction:
   EmptyInstruction | Assignment;

EmptyInstruction: {EmptyInstruction} ';';

Assignment:
   variable=[Variable]':='expression=Expression';' ;

Function:
   'FUNCTION' name=ID
   vars += Variable*
   instructions+=Instruction*
   output=[Function]':='expression=Expression';' ;

Variable: name=ID ';';
Expression: value=INT | var=[Variable];


DSL:
FUNCTION a
  b;
  c;
  b := 1;
  c := b;
  a := c;
Re: Assignments and function output have same sintax [message #986254 is a reply to message #986163] Mon, 19 November 2012 16:22 Go to previous messageGo to next message
Tommaso De Sica is currently offline Tommaso De SicaFriend
Messages: 131
Registered: March 2012
Location: Italy
Senior Member

I solve with option
backtrack=true


UPDATE:
Problem comes out also in this situation:
RealValue:
INT '.' INT;

Array:
name=ID 'ARRAY' '[' initial=INT '..' final=INT ']' ';';


When, in my DSL, I try to write something like this:
v ARRAY [1..10];


I'll receive an error: after the '.' it wants an INT.

Very thank you!

[Updated on: Mon, 19 November 2012 16:43]

Report message to a moderator

Re: Assignments and function output have same sintax [message #986265 is a reply to message #986254] Mon, 19 November 2012 16:41 Go to previous messageGo to next message
Tommaso De Sica is currently offline Tommaso De SicaFriend
Messages: 131
Registered: March 2012
Location: Italy
Senior Member

Problem comes out also in this situation:
RealValue:
INT '.' INT;

Array:
name=ID 'ARRAY' '[' initial=INT '..' final=INT ']' ';';


When, in my DSL, I try to write something like this:
v ARRAY [1..10];


I'll receive an error: after the '.' it wants an INT.

Very thank you!
Re: Assignments and function output have same sintax [message #986266 is a reply to message #986254] Mon, 19 November 2012 16:41 Go to previous messageGo to next message
Tommaso De Sica is currently offline Tommaso De SicaFriend
Messages: 131
Registered: March 2012
Location: Italy
Senior Member

Problem comes out also in this situation:
RealValue:
INT '.' INT;

Array:
name=ID 'ARRAY' '[' initial=INT '..' final=INT ']' ';';


When, in my DSL, I try to write something like this:
v ARRAY [1..10];


I'll receive an error: after the '.' it wants an INT.

Very thank you!
Re: Assignments and function output have same sintax [message #986325 is a reply to message #986266] Tue, 20 November 2012 00:36 Go to previous messageGo to next message
Boris Brodski is currently offline Boris BrodskiFriend
Messages: 112
Registered: July 2009
Senior Member
backtrack=true
is strongly discouraged. It suspends all those warnings, so you have no idea, something else is broken too.
Besides that, you have no control, which way the parse will take ignoring the warning. Consider using syntactic predicated '=>' instead.
Re: Assignments and function output have same sintax [message #986358 is a reply to message #986325] Tue, 20 November 2012 08:47 Go to previous messageGo to next message
Tommaso De Sica is currently offline Tommaso De SicaFriend
Messages: 131
Registered: March 2012
Location: Italy
Senior Member

Boris Brodski wrote on Tue, 20 November 2012 01:36
backtrack=true
is strongly discouraged. It suspends all those warnings, so you have no idea, something else is broken too.
Besides that, you have no control, which way the parse will take ignoring the warning. Consider using syntactic predicated '=>' instead.


Very thank you for suggest, I was able to disable the backtrack. For the moment it works fine.

Now I'm going to finish the grammar,
thanks!
Re: Assignments and function output have same sintax [message #986612 is a reply to message #985883] Wed, 21 November 2012 08:19 Go to previous messageGo to next message
Tommaso De Sica is currently offline Tommaso De SicaFriend
Messages: 131
Registered: March 2012
Location: Italy
Senior Member

Maybe solved.

[Updated on: Thu, 22 November 2012 09:58]

Report message to a moderator

Re: Assignments and function output have same sintax [message #987212 is a reply to message #986612] Sat, 24 November 2012 14:27 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
Ciao Tommaso

as they already told you, stay away from backtrack=true :)

you can find an example expression language here

http://xsemantics.sourceforge.net/xsemantics-documentation/Expressions-example.html#Expressions

hope this helps
Lorenzo

On 11/21/2012 09:19 AM, Tommaso De Sica wrote:
> Similar problem that I can't solve:
>
>
> Expression:
> (expression=NumericExpression) | (expression=BoolExpr)
> ;
>
> BoolExpr returns BoolExpr:
> OrExpr;
>
> OrExpr returns BoolExpr:
> AndExpr ({Or.left=current} 'OR' right=AndExpr)*;
>
> AndExpr returns BoolExpr:
> PrimaryExpr ({And.left=current} 'AND' right=PrimaryExpr)*;
>
> PrimaryExpr returns BoolExpr:
> '(' BoolExpr ')' | BoolLiteral;
>
> BoolLiteral:
> ...
> ;
>
> NumericExpression returns IntegerExpression:
> Multiplication ({NumericExpression.left=current} ('+'|'-')
> right=Multiplication)*;
>
> Multiplication returns IntegerExpression:
> Pow ({Multiplication.left=current} ('*'|'/'|'MOD') right=Pow)*;
>
> Pow returns IntegerExpression:
> Primary ({Pow.left=current} '**' right=Primary)*;
>
> Primary returns IntegerExpression:
> NumberLiteral |
> '(' NumericExpression ')' |
> '-'NumberLiteral;
>
> NumberLiteral:
> ...;
>
> error is the same, but I can't understand how use => in this case.
> Someone can halp me? Very thank you!


--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net


Re: Assignments and function output have same sintax [message #987389 is a reply to message #987212] Mon, 26 November 2012 12:05 Go to previous messageGo to next message
Tommaso De Sica is currently offline Tommaso De SicaFriend
Messages: 131
Registered: March 2012
Location: Italy
Senior Member

Yes, I was able to rewrite the grammar unambiguous.
backtrack=true is just a memory Confused

Thanks for replies!
Re: Assignments and function output have same sintax [message #987390 is a reply to message #987389] Mon, 26 November 2012 12:17 Go to previous message
Boris Brodski is currently offline Boris BrodskiFriend
Messages: 112
Registered: July 2009
Senior Member
Very well (y)
Previous Topic:Running the Xtext machinery outside the builder
Next Topic:Strategies for using embedded editor
Goto Forum:
  


Current Time: Tue Apr 16 21:03:52 GMT 2024

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

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

Back to the top