Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Multiple Entities within an Entity(Defining multiple entitities within an Entity)
Multiple Entities within an Entity [message #1805957] Mon, 29 April 2019 11:24 Go to next message
J Bouwhuis is currently offline J BouwhuisFriend
Messages: 17
Registered: April 2019
Junior Member
* DISCLAIMER: I am new to xText so this question might seem trivial *

I am trying to develop a DSL within xText for creating Functional Models of software programs. I tried setting up in initial version of this DSL which describes basic functional flows within a program (describing the functional flows using if/else statements and basic operations which I have enumerated in my DSL). The thing that I am stuck at is with defining the IfElseStatements entity. This entity should be able to model multiple if statements first, after which it is ended with an else statement (so just describing a basic if/else statement). However, when I compile the DSL and try to use it in xText, the editor tells me that I have to define an else statement directly after I have created an if statement (so it doesn't allow to create multiple if statements first). I am curious to your thoughts on why this doesn't work as aspected. If you need any more information, I will of course provide this.


grammar org.xtext.example.mydsl.TestProgramDSL with org.eclipse.xtext.common.Terminals


Model:
'functionName' name = STRING
functions = NestedFunctions
;

NestedFunctions:
nestedFunctions += Functions+
;

Functions:
libraryFunctions += libraryFunctionsEnum
ifElseStatements += IfElseStatements+
;



IfElseStatements:
'if'
IfStatements += IfStatements+
'else'
elseFunctions += libraryFunctionsEnum+
;


IfStatements:
conditions += Conditions+
ifFunctions += libraryFunctionsEnum+
;

//*Eventually filled with details from class diagram, but for now we manually fill it for the sake of testing.
enum libraryFunctionsEnum:
createAccount='createInstance'|
login='login'|
hasCode= 'encrypt'|
display='display'
;
Re: Multiple Entities within an Entity [message #1806351 is a reply to message #1805957] Wed, 08 May 2019 04:24 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Am not sure if I can follow you
The grammar allow the if keyword only once in a ifelse
a complete grammar and unit test would be helpful



Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Multiple Entities within an Entity [message #1806395 is a reply to message #1806351] Wed, 08 May 2019 12:23 Go to previous message
J Bouwhuis is currently offline J BouwhuisFriend
Messages: 17
Registered: April 2019
Junior Member
@Christian thanks a lot for your answer. I already figured it out myself by now, but I still much appreciate your answer. You are right indeed (the 'if' keyword was set to be only specified once). I rewrote the DSL and added comments to it (see below). It now works as it should. Thanks!

grammar org.xtext.example.mydsl.FinalDsl with org.eclipse.xtext.common.Terminals

generate finalDsl "http://www.xtext.org/example/mydsl/FinalDsl"

Model:
'functionName' name = STRING
functions += FunctionElements*
;

// Function elements of which the model exists. The model can contain
// library functions, for loops, and if/else statements.
FunctionElements:
(
functions += libraryFunctionsEnum |
forLoops += ForLoops |
ifElseStatements += IfElseStatements
)
;

// IfElse Statements requiring if statements and optionally followed by
// one else statement.
IfElseStatements:
ifStatements += IfStatements
(elseStatement = ElseStatement)?
;

// If statements requiring conditions and optionally followed by
// library functions or for loops.
IfStatements:
'if'
conditions = Conditions
(ifFunctions += libraryFunctionsEnum | forLoops += ForLoops)
;

// Else statement requiring one or multiple library functions.
ElseStatement:
'else' elseFunctions += libraryFunctionsEnum
;

// For loops requiring one condition and followed by zero or more
// library functions
ForLoops:
'for'
conditions = Conditions
libraryFunctions += libraryFunctionsEnum*

;

//*Eventually filled with details from class diagram, but for now we manually fill it for the sake of testing.
enum libraryFunctionsEnum:
createAccount='createInstance'|
login='login'|
hasCode= 'encrypt'|
display='display'
;



Conditions:
STRING
operator=logicalOperators
STRING
;

enum logicalOperators:
greaterThan='>'|
smallerThan='<'|
greaterOrEqualThan='=>'|
smallerOrEqualThan='<='|
equalTo='=='
;

[Updated on: Wed, 08 May 2019 12:24]

Report message to a moderator

Previous Topic:Xtext example project(domainmodel(Xbase))
Next Topic:Referring to source code of Java project in xText
Goto Forum:
  


Current Time: Thu Mar 28 09:25:24 GMT 2024

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

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

Back to the top