Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Empty rule
Empty rule [message #1010122] Sat, 16 February 2013 11:03 Go to next message
Pooyan Behnamghader is currently offline Pooyan Behnamghader
Messages: 7
Registered: July 2012
Junior Member
Hi.

How can I define grammars with empty rules in Xtext?
For example:



grammar ir.ut.ece.MathExpComp_1 with org.eclipse.xtext.common.Terminals

generate mathExpComp_1 "http://www.ut.ir/ece/MathExpComp_1"
/*

 */
E:
	T Ep
;


E1P:
	'+' T Ep
;

Ep:
	''
;
T:
	F Tp
;
T1p:
	'*' F Tp
;
Tp: // Empty rule
	''
;
F:
	value=INT
;


Bests,
Pooyan
Re: Empty rule [message #1010126 is a reply to message #1010122] Sat, 16 February 2013 11:12 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6230
Registered: July 2009
Senior Member
HI,

you/have to assign things in xtext.and you can use cardinalities.
You may have a look at
http://blog.efftinge.de/2010/08/parsing-expressions-with-xtext.html
Re: Empty rule [message #1010131 is a reply to message #1010126] Sat, 16 February 2013 11:32 Go to previous messageGo to next message
Pooyan Behnamghader is currently offline Pooyan Behnamghader
Messages: 7
Registered: July 2012
Junior Member
Dear Christian,
Hi.

I appreciate your time and your kind answer.
The mathematical expression was just to show the problem that I have been faced. I have some problem with inherited attributes in xtext grammar.
I am developing a DSL which it's grammar contains some empty parsing elements (epsilon rules).

Is it possible to write such grammars in Xtext?

Bests,
Pooyan
Re: Empty rule [message #1010133 is a reply to message #1010131] Sat, 16 February 2013 11:36 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6230
Registered: July 2009
Senior Member
hi

can you post the real example?

~Christian
Re: Empty rule [message #1010233 is a reply to message #1010131] Sat, 16 February 2013 19:01 Go to previous message
Henrik Lindberg is currently offline Henrik Lindberg
Messages: 2499
Registered: July 2009
Senior Member
On 2013-16-02 17:32, Pooyan Behnamghader wrote:
> Dear Christian,
> Hi.
>
> I appreciate your time and your kind answer.
> The mathematical expression was just to show the problem that I have
> been faced. I have some problem with inherited attributes in xtext grammar.
> I am developing a DSL which it's grammar contains some empty parsing
> elements (epsilon rules).
>
> Is it possible to write such grammars in Xtext?
>

In some grammar languages you write something like

R : // empty
| something

In Xtext, this is done with cardinality - i.e:

R : something ?

Which means R contains an optional something (since it is optional,
"empty"/"nothing" is also valid at this position.

Does that answer your question?

Regards
- henrik
Previous Topic:Xtend2: extended type-based collection filters
Next Topic:Skipping validations of features from EMF Model
Goto Forum:
  


Current Time: Fri Aug 29 01:43:48 EDT 2014

Powered by FUDForum. Page generated in 0.03188 seconds