Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Grammar support(Grammar support)
Grammar support [message #1823784] Thu, 02 April 2020 06:03 Go to next message
Virag Purnam is currently offline Virag PurnamFriend
Messages: 142
Registered: June 2014
Senior Member
Hi,

VarDecl:
	{VarDecl} 'int' newVar=NewVar ';'
;

NewVar:
	{NewVar} ('.' | '.EX')? IDENT
;

terminal IDENT:
			(('a'..'z'|'A'..'Z'|'_') ('^'|'a'..'z'|'A'..'Z'|'-'|'0'..'9')*)
 ;


With the above grammar, I am not able to declare variable.
int .Each;
, This throws error, as it expects 'X' after 'E'.
How to address this issue?
Re: Grammar support [message #1823790 is a reply to message #1823784] Thu, 02 April 2020 07:19 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

NewVar:
	{NewVar} ('.' 'EX'?)? IDENT
;


might fix it with an LL parser such as Xtext, but you'll be in bigger trouble with an LALR parser.

I strongly recommend that you review your grammar since you seem to have something confusing to tools which usually means something confusing to users. The tools provide a really good warning that your grammar is crazy.

What is

int .EXIT;


supposed to be? EX+IT or EXIT?

Regards

Ed Willink
Re: Grammar support [message #1823793 is a reply to message #1823790] Thu, 02 April 2020 07:34 Go to previous messageGo to next message
Virag Purnam is currently offline Virag PurnamFriend
Messages: 142
Registered: June 2014
Senior Member
Hi Mr. Ed Willink,

Thanks for the suggestion.
If the variable name starts with '.', then '.EXIT' will be treated as .EX - IT.
Is the grammar change proposed by you will satisfy the mentioned usecase.

Regards,
Virag
Re: Grammar support [message #1823798 is a reply to message #1823793] Thu, 02 April 2020 08:38 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
I think the point is that to "us" it seems like a confusing use case at best. Even if a variable name that happens to start with .EX has some semantic significance, I'd not try to build that significance into the grammar. If you want something in the grammar, better to use "." to mean whatever that is supposed to mean and to use "$' (or some other character not allowed at the start of an IDENT) to mean whatever you're planning to make ".EX" mean. It's just plan weird and confusing what you're trying to do where ".EX" looks just like a variable.

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Grammar support [message #1823815 is a reply to message #1823798] Thu, 02 April 2020 13:53 Go to previous message
Virag Purnam is currently offline Virag PurnamFriend
Messages: 142
Registered: June 2014
Senior Member
I will try if I can simplify the grammar. I will post back here after my experiment.
Thanks.
Previous Topic:Xtext grammar to Java Code Generation
Next Topic:location not found for modeling/tmf/xtext/updates/releases/xpand/
Goto Forum:
  


Current Time: Thu Mar 28 23:04:04 GMT 2024

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

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

Back to the top