Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [xText] Pulling up features into common super class
[xText] Pulling up features into common super class [message #58352] Tue, 14 July 2009 11:47
Eclipse UserFriend
Originally posted by: c.krause.cwi.nl

Hi all,

I want xText to generate a common superclass for two types and to pull
up a feature into this superclass. More specifically, I have my grammar
for arithmetical expressions:


/* ----- N-ary Operations ----- */

Addition returns Expression:
Subtraction ( {Addition.operands += current} ('+' operands +=
Subtraction)+)?;

Multiplication returns Expression:
Division ( {Multiplication.operands += current} ('*' operands +=
Division)+)?;


/* ----- Binary Operations ----- */

Subtraction returns Expression:
Multiplication ( {Subtraction.left = current} '-' right =
Multiplication)?;

Division returns Expression:
Operation ( {Division.left = current} '/' right = Operation)?;


Operation returns Expression:
Literal | '(' Addition ')';



....and I would like to have the following type hierarchy generated:

* Operation, Literal -> Expression
* BinaryOperation, NaryOperation -> Operation
* Addition, Multiplication -> NaryOperation
* Subtraction, Division -> BinaryOperation


In all my attempts I ended up with a cyclic hierarchy. What I basically
tried to do is to add a dummy rule:

Operation:
BinaryOperation | NaryOperation;

I believe the problem is that in my current model Operation is not a type.

If anybody has a hint, I'd appreciate any help. Anyway, I will try to
get it working somehow..

Cheers,
Christian
Previous Topic:Left recursion: from binary to n-ary operations
Next Topic:[Xtext] ANTLR options
Goto Forum:
  


Current Time: Fri Jul 19 05:17:10 GMT 2024

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

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

Back to the top