Skip to main content



      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 09:51 Go to next message
Eclipse UserFriend
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 09:52] by Moderator

Re: Assignments and function output have same sintax [message #986163 is a reply to message #985883] Mon, 19 November 2012 04:22 Go to previous messageGo to next message
Eclipse UserFriend
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 11:22 Go to previous messageGo to next message
Eclipse UserFriend
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 11:43] by Moderator

Re: Assignments and function output have same sintax [message #986265 is a reply to message #986254] Mon, 19 November 2012 11:41 Go to previous messageGo to next message
Eclipse UserFriend
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 11:41 Go to previous messageGo to next message
Eclipse UserFriend
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] Mon, 19 November 2012 19:36 Go to previous messageGo to next message
Eclipse UserFriend
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 03:47 Go to previous messageGo to next message
Eclipse UserFriend
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 03:19 Go to previous messageGo to next message
Eclipse UserFriend
Maybe solved.

[Updated on: Thu, 22 November 2012 04:58] by Moderator

Re: Assignments and function output have same sintax [message #987212 is a reply to message #986612] Sat, 24 November 2012 09:27 Go to previous messageGo to next message
Eclipse UserFriend
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 07:05 Go to previous messageGo to next message
Eclipse UserFriend
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 07:17 Go to previous message
Eclipse UserFriend
Very well (y)
Previous Topic:Running the Xtext machinery outside the builder
Next Topic:Strategies for using embedded editor
Goto Forum:
  


Current Time: Wed Jul 16 05:23:49 EDT 2025

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

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

Back to the top