Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtext newbie - ID with array declaration
Xtext newbie - ID with array declaration [message #1764364] Mon, 29 May 2017 08:43 Go to next message
Anton Hughes is currently offline Anton HughesFriend
Messages: 66
Registered: January 2013
Member
Hello

Im trying to create a dsl that is essentially identical to a simple c++ header file.

I am unsure how to make the following, within the xtext dsl:

   char              myChar[32];


Thanks

Re: Xtext newbie - ID with array declaration [message #1764365 is a reply to message #1764364] Mon, 29 May 2017 08:46 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14735
Registered: July 2009
Senior Member
hmmm am not sure if i can follow you

Decl: type=Type name=ID ('[' dim=INT']')?;
enum Type: char | int32| ...;


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Xtext newbie - ID with array declaration [message #1764367 is a reply to message #1764365] Mon, 29 May 2017 08:56 Go to previous messageGo to next message
Anton Hughes is currently offline Anton HughesFriend
Messages: 66
Registered: January 2013
Member
Hi Christian

Apologies for the lack of details.


Dsl
My dsl, currently, looks like this:
struct MyStruct{
	
	int myInt; 
	unsigned int myUnsiggnedInt;
   __time32_t        timestamp;                  
   char              myChar[32];             
	
};



Xtext
And my xtext file is:
grammar mydomain.Mydsl with org.eclipse.xtext.common.Terminals

generate Mydsl "http://mydomain/mydsl"

Model:
	structs+=struct*;

struct:
	'struct' name=ID  '{'
		attributes+=Attribute*
	'};';

Attribute:
	type=AttributeType name=ID ';';

AttributeType:
	elementType=ElementType (array?='[' (length=INT)? ']')?;

ElementType:
	BasicType | StructType;
	


BasicType:
	typeName=('string' | 'int' | 'boolean'  | 'char' | '__time32_t' |  'unsigned int');

StructType:
	struct=[struct];



Problem
The dsl is currently unable to parse the following line:

   char              myChar[32];             

[Updated on: Mon, 29 May 2017 08:57]

Report message to a moderator

Re: Xtext newbie - ID with array declaration [message #1764368 is a reply to message #1764367] Mon, 29 May 2017 09:08 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14735
Registered: July 2009
Senior Member
yes but you put the array to the type, not the name (in the grammar)

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com

[Updated on: Mon, 29 May 2017 09:09]

Report message to a moderator

Re: Xtext newbie - ID with array declaration [message #1764372 is a reply to message #1764368] Mon, 29 May 2017 09:35 Go to previous messageGo to next message
Anton Hughes is currently offline Anton HughesFriend
Messages: 66
Registered: January 2013
Member
I have tried your suggestion of:

BasicType:
	typeName=('string' | 'int' | 'boolean' | 'double' | 'char' | '__time32_t' |  'unsigned int');
	
Decl: type=Type name=ID ('[' dim=INT']')?;
enum Type: char | int32;


But I am still getting an error when I try having the following in the dsl:

char              myChar[32];


Re: Xtext newbie - ID with array declaration [message #1764375 is a reply to message #1764372] Mon, 29 May 2017 09:41 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14735
Registered: July 2009
Senior Member
thats not what i meant

Attribute:
	type=AttributeType name=ID  (array?='[' (length=INT)? ']')? ';';

AttributeType:
	elementType=ElementType (array?='[' (length=INT)? ']')?;

ElementType:
	BasicType | StructType;
	


BasicType:
	typeName=('string' | 'int' | 'boolean'  | 'char' | '__time32_t' | UINT);
	
UINT: 'unsigned' 'int';


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: Xtext newbie - ID with array declaration [message #1764384 is a reply to message #1764375] Mon, 29 May 2017 10:03 Go to previous message
Anton Hughes is currently offline Anton HughesFriend
Messages: 66
Registered: January 2013
Member
Perfect!

Thanks Christian!
Previous Topic:IFeatureScopeTracker.Provider lsp 2.12
Next Topic:Xtext : shouldgenerate
Goto Forum:
  


Current Time: Mon Dec 02 22:51:03 GMT 2024

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

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

Back to the top