Help needed in Xtext [message #1049351] |
Thu, 25 April 2013 14:44  |
Eclipse User |
|
|
|
Hi All,
I need to implement something like below:
// a simple structure, there can be any no, similar to C
typedef struct
{
int a;
int b;
....
}emp;
//any no of instances of the structure
emp emp1;
emp emp2;
//assigning values to the instances
emp1.a=2;
emp2.b=3;
//function definition
void func(emp emp1)
{
x=1;
y=emp1.a;
}
The grammar that i wrote is:
Model:
((struct+=Struct) | (instance+=Instance) | (function+=Function))*
;
// a simple structure, there can be any no, similar to C
//typedef struct
//{
//int a;
//int b;
//....
//}emp;
Struct:
'typedef struct {'
(params+=Parameter)+
'}'name=ID ';'
;
Parameter:
'int' name=ID;
//emp emp1;
Instance:
struct=[Struct] name=ID';'
;
//i need to put something like emp1.a = 3; , which can be anywhere after the emp1 declaration, similar to the concept that variable can be used only after its defined. So how do i include it in grammar. Is it possible to do without any validator, by creating some grammar rule? How do i judge where to put in the rule as weel, as this statement can be basically anywhere afterwards
//Also for creating a variable such as emp1.a, i basically need to refer
name=[Instance]'.'param=[Parameter] '=' value=INT, but it gives some error in the editor, and doesnt consider the Parameter . Is it possible to refer it this way, or any other way
Function:
('void')? name=ID '(' ((struct+=[Struct] structVarName+=ID) (',' struct+=[Struct] structVarName+=ID)*)? ')' '{'
(assignments+=Assignment)+
'}'
;
Assignment:
name=ID '=' value=INT';'
;
Can someone please suggest?
Thanks,
Rohit
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.25732 seconds