Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Xtext newbie - ID with array declaration
Xtext newbie - ID with array declaration [message #1764364] Mon, 29 May 2017 04:43 Go to next message
Eclipse UserFriend
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 04:46 Go to previous messageGo to next message
Eclipse UserFriend
hmmm am not sure if i can follow you

Decl: type=Type name=ID ('[' dim=INT']')?;
enum Type: char | int32| ...;
Re: Xtext newbie - ID with array declaration [message #1764367 is a reply to message #1764365] Mon, 29 May 2017 04:56 Go to previous messageGo to next message
Eclipse UserFriend
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 04:57] by Moderator

Re: Xtext newbie - ID with array declaration [message #1764368 is a reply to message #1764367] Mon, 29 May 2017 05:08 Go to previous messageGo to next message
Eclipse UserFriend
yes but you put the array to the type, not the name (in the grammar)

[Updated on: Mon, 29 May 2017 05:09] by Moderator

Re: Xtext newbie - ID with array declaration [message #1764372 is a reply to message #1764368] Mon, 29 May 2017 05:35 Go to previous messageGo to next message
Eclipse UserFriend
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 05:41 Go to previous messageGo to next message
Eclipse UserFriend
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';
Re: Xtext newbie - ID with array declaration [message #1764384 is a reply to message #1764375] Mon, 29 May 2017 06:03 Go to previous message
Eclipse UserFriend
Perfect!

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


Current Time: Sat Aug 30 23:10:55 EDT 2025

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

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

Back to the top