Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Variable declaration(create dsl with xtext)
Variable declaration [message #899570] Wed, 01 August 2012 13:25 Go to next message
Laigle jérôme is currently offline Laigle jérôme
Messages: 26
Registered: August 2012
Junior Member
Hi,

I'm working on a DSL where it should be possible to differ between a declaration of a element and the definition of a element. For example:

dcl a%=10
dcl b% = 42
a = 12
b=30
b=a

So, I've started with the following construct

VariableName:
name=ID type=Type
;

VariableDeclaration :
'dcl' variableName=VariableName

;
VariableReference:
variableName=[VariableName|ID]
;

VariableAssignment:
variable=[VariableReference] '=' value=VariableValue
;

VariableValue:
{VariableValue}
(variableReference =VariableReference)?
//(value=Value)?
(value=NUMBER)?
;

whereas Type refers to my defined types. I've thought it might be an idea to use cross references like in the following fragment

VariableDef:
name=[VariableDeclaration] '=' INT;

But that's not working and I doubt that this is the right way. I'm new to Xtext and so this question might be quite stupid. Maybe somebody has an idea or can point me into the right direction? Thanks in advance!

Best regards,
Jérôme
Re: Variable declaration [message #899573 is a reply to message #899570] Wed, 01 August 2012 13:36 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik Lindberg
Messages: 2500
Registered: July 2009
Senior Member
Use:

VariableDeclaration :
'dcl' name=VariableName ;

since references use the feature "name" by default.

Regards
- henrik

On 2012-01-08 15:25, Laigle jérôme wrote:
> Hi,
>
> I'm working on a DSL where it should be possible to differ between a
> declaration of a element and the definition of a element. For example:
>
> dcl a%=10 dcl b% = 42 a = 12 b=30
> b=a
>
> So, I've started with the following construct
>
> VariableName:
> name=ID type=Type
> ;
>
> VariableDeclaration :
> 'dcl' variableName=VariableName
>
> ;
> VariableReference:
> variableName=[VariableName|ID]
> ;
>
> VariableAssignment:
> variable=[VariableReference] '=' value=VariableValue ;
>
> VariableValue:
> {VariableValue}
> (variableReference =VariableReference)? //(value=Value)?
> (value=NUMBER)?
> ;
>
> whereas Type refers to my defined types. I've thought it might be an
> idea to use cross references like in the following fragment
>
> VariableDef:
> name=[VariableDeclaration] '=' INT;
>
> But that's not working and I doubt that this is the right way. I'm new
> to Xtext and so this question might be quite stupid. Maybe somebody has
> an idea or can point me into the right direction? Thanks in advance!
>
> Best regards,
> Jérôme
Re: Variable declaration [message #899604 is a reply to message #899573] Wed, 01 August 2012 14:46 Go to previous messageGo to next message
Laigle jérôme is currently offline Laigle jérôme
Messages: 26
Registered: August 2012
Junior Member
thanks for the quick reply.

VariableDeclaration :
'dcl' name=VariableName ;

this is better because it fixed my problem with generate xtext artifact

but i do test with xtend in parallel and test no working

My test:
@Test
def void testSegmentNumVariableDeclaration()
{
val compilationUnit =
'''
program MyProgramme
segment 0
dcl maVariable%
maVariable=3

eseg 0
end
'''.parse
val segment = getProgrammeSegment(compilationUnit,0)
val variableName1=getProgrammeSegmentVariableDeclaration(compilationUnit,0,0)
Assert::assertNotNull(variableName1.type)
val num= variableName1.type
Assert::assertNotNull(num)
Assert::assertTrue(num instanceof NumericType)
val numericType= num as NumericType
Assert::assertEquals("maVariable", variableName1.name)
Assert::assertNotNull(numericType)


val instruction= segment.instructions.get(1)
Assert::assertNotNull(instruction)
Assert::assertTrue(instruction instanceof VariableAssignment)
val variableAssignment=instruction as VariableAssignment
Assert::assertEquals(3, variableAssignment.value)

}
the value of variableAssignment is null i don't understand why?

eror in the test :


junit.framework.AssertionFailedError: expected:<3> but was:<abal.language.impl.VariableValueImpl@4feaf536 (value: null)>


Re: Variable declaration [message #899606 is a reply to message #899573] Wed, 01 August 2012 14:47 Go to previous message
Charalampos Alexopoulos is currently offline Charalampos Alexopoulos
Messages: 9
Registered: July 2012
Junior Member
Hi Henrik
Thank you for the advice. I am out of home right now, i will try it as soon as i return tomorrow.
Previous Topic:How to extend Xtext DSL to use a validation class packaged with a library model ?
Next Topic:Save event XtextEditor
Goto Forum:
  


Current Time: Sat Oct 25 16:06:39 GMT 2014

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

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