Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtext Grammar - Referencing
Xtext Grammar - Referencing [message #1044805] Fri, 19 April 2013 11:14 Go to next message
rohit ahuja is currently offline rohit ahujaFriend
Messages: 27
Registered: February 2013
Junior Member
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 11:34 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
HI,

you have to customize scoping or introduce a semantic validation for that


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xtext Grammar - Referencing [message #1044827 is a reply to message #1044805] Fri, 19 April 2013 11:40 Go to previous messageGo to next message
Steve Kallestad is currently offline Steve KallestadFriend
Messages: 62
Registered: March 2013
Member
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 06:35 Go to previous message
rohit ahuja is currently offline rohit ahujaFriend
Messages: 27
Registered: February 2013
Junior Member
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: Wed Apr 24 21:26:17 GMT 2024

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

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

Back to the top