Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Grammar support(Grammar support)
Grammar support [message #1823784] Thu, 02 April 2020 02:03 Go to next message
Eclipse UserFriend
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 03:19 Go to previous messageGo to next message
Eclipse UserFriend
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 03:34 Go to previous messageGo to next message
Eclipse UserFriend
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 04:38 Go to previous messageGo to next message
Eclipse UserFriend
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.
Re: Grammar support [message #1823815 is a reply to message #1823798] Thu, 02 April 2020 09:53 Go to previous message
Eclipse UserFriend
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: Sun Jul 06 16:26:46 EDT 2025

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

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

Back to the top