Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Question about Xtext Grammar
Question about Xtext Grammar [message #556840] Thu, 02 September 2010 18:59 Go to next message
No real name is currently offline No real nameFriend
Messages: 101
Registered: August 2010
Senior Member
Hi,

Can someone quickly tell me how I can model this scenario in Xtext grammar?

state {
action = ...
condition = ...
condition = ...
}

I have three possibilites: either action or conditions or both should be specified. however it is illegal if neither is specified. Also there can be only ONE action but multiple conditions per state block.

I was thinking of something like this:

(action+=Action)?
((conditions+=Condition)*)?

But this will allow neither to be specified. Otherwise, maybe something like this:

Statements : Type1 | Type2

Type 1:
(actions+=Action)?
(conditions+=Condition)+

Type 2:
(actions+=Action)

Is there a better way to do the above? Thank you for any ideas.
Re: Question about Xtext Grammar [message #556842 is a reply to message #556840] Thu, 02 September 2010 19:16 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

i would take this grammar

State:
	{State} "state" "{"
		action=Action? 
		conditions+=Condition*
	"}"
;



and 'd leave the check to a validator.

or that grammar

State:
	 "state" "{"
		(action=Action | conditions+=Condition) conditions+=Condition*
	"}"
;


~Christian


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

[Updated on: Thu, 02 September 2010 19:26]

Report message to a moderator

Re: Question about Xtext Grammar [message #556843 is a reply to message #556840] Thu, 02 September 2010 19:12 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi pg

It's not always a good idea to be pedantically accurate in the grammar.

Your user may not fully understand the rules, so allow the user to type
what the user thinks is sensible and use validation to warn about rule
violation. You may also be able to offer quick fixers/refactoring to
realize what the user has specvified 'illegally'.

Regards

Ed Willink

On 02/09/2010 19:59, pgbackup@yahoo.com wrote:
> Hi,
>
> Can someone quickly tell me how I can model this scenario in Xtext grammar?
>
> state {
> action = ...
> condition = ...
> condition = ...
> }
>
> I have three possibilites: either action or conditions or both should be
> specified. however it is illegal if neither is specified. Also there can
> be only ONE action but multiple conditions per state block.
>
> I was thinking of something like this:
>
> (action+=Action)?
> ((conditions+=Condition)*)?
>
> But this will allow neither to be specified. Otherwise, maybe something
> like this:
>
> Statements : Type1 | Type2
>
> Type 1:
> (actions+=Action)?
> (conditions+=Condition)+
>
> Type 2:
> (actions+=Action)
>
> Is there a better way to do the above? Thank you for any ideas.
Re: Question about Xtext Grammar [message #556849 is a reply to message #556843] Thu, 02 September 2010 19:32 Go to previous message
No real name is currently offline No real nameFriend
Messages: 101
Registered: August 2010
Senior Member
Hi,

Thank you very much for the responses. I now understand about checking the validitity using the validator. I will try it out there.

Kind regards,
pallav
Previous Topic:how to define grammar for: create package ... end; create package body ... end;
Next Topic:Refererncing to existing items in Xtext
Goto Forum:
  


Current Time: Fri Apr 19 23:13:40 GMT 2024

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

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

Back to the top