Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [Grammar] Declaration and definition of variables for a DSL
[Grammar] Declaration and definition of variables for a DSL [message #555421] Thu, 26 August 2010 14:31 Go to next message
Michael Frey is currently offline Michael FreyFriend
Messages: 48
Registered: August 2010
Member
Hi,

I'm working on a DSL where it should be possible to differ between a declaration of a element and the definition of a element. For example:

int a;
int b = 42;
a = 12;

So, I've started with the following construct

VariableDecl:
type=DataType name=ID ';';

whereas DataType refers to my defined data types. I've thought it might be an idea to use cross references like in the following fragment

VariableDef:
name=[VariableDecl] '=' INT;

But that's not working and I doubt that this is the right way. So far, what I really want is to "extend" the already defined element VariableDecl (and Variable might be a better name). I'm new to Xtext and so this question might be quite stupid. Maybe somebody has an idea or can point me into the right direction? Thanks in advance!

Best regards,
Michael
Re: [Grammar] Declaration and definition of variables for a DSL [message #555441 is a reply to message #555421] Thu, 26 August 2010 14:45 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
> VariableDef:
> name=[VariableDecl] '=' INT;
should be more like
VariableDef:
ref=[VariableDecl] '=' value=INT;

but otherwise it looks fine to me. Could you be more specific about
*what" is not working?

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: [Grammar] Declaration and definition of variables for a DSL [message #555551 is a reply to message #555441] Fri, 27 August 2010 07:12 Go to previous messageGo to next message
Michael Frey is currently offline Michael FreyFriend
Messages: 48
Registered: August 2010
Member
Hi,

thanks for the quick reply. Hm, my problem was maybe a problem of general understanding. So far, I've build the following

Variable:
	VariableDeclaration | VariableDefinition;

VariableDeclaration:
	type=DataType name=ID';';

VariableDefinition:
	AlreadyDeclaredVariable | NewVariableDefinition;

AlreadyDeclaredVariable:
	ref=[VariableDeclaration] '=' value=NUMBER ';';

NewVariableDefinition:
	type=DataType name=ID '=' value=NUMBER ';';


But MWE2 in the generator is complaining about

Decision can match input such as "'int' RULE_ID '=' RULE_NUMBER ';'" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input


So the problem might be parsing "int foo = 42" and "int foo"?

Best regards,
Michael
Re: [Grammar] Declaration and definition of variables for a DSL [message #555560 is a reply to message #555551] Fri, 27 August 2010 07:35 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

i cannot reproduce this since you didn't post your rules for DataType (and number).

Variables: variables+=Variable*;

Variable:
	VariableDeclaration | VariableDefinition;

VariableDeclaration:
	type=ID name=ID';';

VariableDefinition:
	AlreadyDeclaredVariable | NewVariableDefinition;

AlreadyDeclaredVariable:
	ref=[VariableDeclaration] '=' value=INT ';';

NewVariableDefinition:
	type=ID name=ID '=' value=INT ';';


works fine so i think this has to do something with your datatype rule

Regards
Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Fri, 27 August 2010 07:36]

Report message to a moderator

Re: [Grammar] Declaration and definition of variables for a DSL [message #555644 is a reply to message #555560] Fri, 27 August 2010 13:32 Go to previous messageGo to next message
Michael Frey is currently offline Michael FreyFriend
Messages: 48
Registered: August 2010
Member
Hi,

Quote:

works fine so i think this has to do something with your datatype rule



yepp, you're right. That was the problem!

Thanks,
Michael
Re: [Grammar] Declaration and definition of variables for a DSL [message #899563 is a reply to message #555644] Wed, 01 August 2012 13:02 Go to previous message
Laigle jérôme is currently offline Laigle jérômeFriend
Messages: 26
Registered: August 2012
Junior Member
hi

i have exactly the same problem
what was your problem with your datatype?

what is the solution?
Previous Topic:weird encoding problem with properties-files
Next Topic:How to extend Xtext DSL to use a validation class packaged with a library model ?
Goto Forum:
  


Current Time: Tue Apr 16 17:16:58 GMT 2024

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

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

Back to the top