Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Entities extend other entities
icon5.gif  Entities extend other entities [message #756597] Mon, 14 November 2011 13:27 Go to next message
Mikka Missing name is currently offline Mikka Missing nameFriend
Messages: 2
Registered: November 2011
Junior Member
Hi,

I have a problem with the classes generated by xtext using my grammar definition. Some classes extend other classes and 'steal' their properties and I have absolutely no idea why.

This is an extract of the used grammar definition:

Probassigns:
	probassign+=Probassign ('+' probassign+=Probassign)*;

Probassign:
	(Probability ':')? nextstateassign+=Nextstateassign ('&'nextstateassign+=Nextstateassign)*;

Probability:
	mult+=Mult (('+'|'-') mult+=Mult)*;
	
Mult:
	sign+=Sign (('*'|'/') sign+=Sign)*;

Sign:
	('+'|'-')* Prob;

Prob:
	name+=Name | Val | '('probability+=Probability')';

Nextstateassign:
	('(' newstate+=Newstate '=' stateexpr+=Stateexpr ')')+;


As you can see the 'Probassigns' rule contains the 'Probassign' rule, which contains the 'Nextstateassign' rule. So I expect the generated 'Probassign' class to contain a 'getNextstateassigns()' method, that returns a list of 'NextStateAssigns' objects.
But instead of this the 'Probassign' class is empty, the 'Probability' class extends the 'Probassign' class and contains the 'getNextstateassigns()' method, as you can see in the attached screenshot.

Why is the the 'Probability' class extending the 'Probassign' class? Could it be caused by the circle in the grammar (Probassign -> Probability -> Mult -> Sign -> Prob -> Probability)?

In the manual i found this:
"Manual - 7.3.2."
Furthermore, each type that is added to the currently possible return types automatically extends the current return type of the parser rule.

I first thought that this is the reason, but i guess I just misunderstood it, because other classes are not extended by classes that are contained in the rules.

It would be great if somebody can tell me why the inheritance is happening. Let me know if further information is required.
Re: Entities extend other entities [message #756626 is a reply to message #756597] Mon, 14 November 2011 14:29 Go to previous message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
The feature must be part of Probability, since the the result of Probassign will be an instance of Probability if the first optional group matches.
If that was not your intention you might want to assign Probability to a feature :

Probassign:
(probability=Probability ':')? nextstateassign+=Nextstateassign ('&'nextstateassign+=Nextstateassign)*;

Probability:
mult+=Mult (('+'|'-') mult+=Mult)*;

[Updated on: Mon, 14 November 2011 14:30]

Report message to a moderator

Previous Topic:Newbie: grammar, identifying STRING vs ID
Next Topic:Mapping to JVM Concepts
Goto Forum:
  


Current Time: Sun Mar 07 21:52:22 GMT 2021

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

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

Back to the top