Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Xtext Grammar - Referencing
Xtext Grammar - Referencing [message #1044805] Fri, 19 April 2013 07:14 Go to next message
Eclipse UserFriend
I need something like what we do in a programming language, wherein we define a variable and then assign some value to it later.(i need only type int for now)


int a;
int b;

//some functions/other statements etc
....
....

//

a=10;
b=10;

Leaving aside the functions and other statements that may exist, i wrote something like,

Model:
Defintion|Assignment|OtherStatements;

Definition:
'int' name=ID ';

OtherStatements :
//TODO, for now think it is only a name=ID
name=ID
;

Assignment:
definition=[Definition] '=' INT ';'


I have a problem in here. Since the assignment can come anywhere after the Definition how do i ensure that it comes only after definition..


So something like definition followed by assignment
works, which is correct..

int a;
int b;

//other statements
...
...

a=10;

-----------------------------------------------------------------------------

This also works,i.e the definition after assignment
a=10;

...
...

int a;

which is obviously incorrect.

I think there must be some way to resolve it. Can anyone please help as i am relatively new to Xtext.

Thanks in Advance.

Rohit


Re: Xtext Grammar - Referencing [message #1044821 is a reply to message #1044805] Fri, 19 April 2013 07:34 Go to previous messageGo to next message
Eclipse UserFriend
HI,

you have to customize scoping or introduce a semantic validation for that
Re: Xtext Grammar - Referencing [message #1044827 is a reply to message #1044805] Fri, 19 April 2013 07:40 Go to previous messageGo to next message
Eclipse UserFriend
That's something that you probably don't want to define in your grammar specifically.

It's possible if you define all declarations to occur before all assignment calls and link the two, but that means inline declarations are out the window.

It's usually better if you handle such a thing within your validation routines. You can leverage INode.getStartLine and INode.getEndLine to check the line numbers of nodes, and you can access nodes using the NodeModelUtils set of routines.

Re: Xtext Grammar - Referencing [message #1046623 is a reply to message #1044827] Mon, 22 April 2013 02:35 Go to previous message
Eclipse UserFriend
Thanks Steve and Chreistian.. I wrote a custom validator instead.
Previous Topic:content assist grammar with external lexer
Next Topic:Is it possible to export the behaviors in the .dmodel file into diagram like UML's activity diagram?
Goto Forum:
  


Current Time: Mon Jul 14 22:50:37 EDT 2025

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

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

Back to the top