Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » problem with if expression
problem with if expression [message #901211] Fri, 10 August 2012 11:02
Laigle jérôme is currently offline Laigle jérômeFriend
Messages: 26
Registered: August 2012
Junior Member
Hi,

I'm working on a DSL but i have a problem with if and endif
Because in my dsl endif was defines obligatory
But i realise test with xtend and my test pass without endif i don't understand why
My dsl:

CompilationUnit:
instructions+=Instruction*;

Instruction:
ControleStructure|VariableDeclaration|VariableAssignment;

Ifstatement:

'if'(expressions=Expression)
then+=Instruction*
(=>'else' else+=Instruction*)?
'endif' ;

VariableAssignment:
dcl=[VariableDeclaration]'='expr=Expression;

ControleStructure:
Ifstatement;
Expression :
CompareOperator;

CompareOperator returns Expression:
ConditionalOR(( /* {Inclusion.left=current} '='|*/{Equality.left=current}'=='|{NoInclusion.left=current}'!='|{Different.left=current}'<>'|{Inferrior.left=current}'<'|{Superior.left=current}'>'|{SuperiorOrEqual.left=current}'>='|{InferriorOrEqual.left=current}'<=') right=ConditionalOR)*;

ConditionalOR returns Expression:
Addition (({ConditionalOR.left=current} 'or'|{ConditionalOX.left=current} 'ox'|{ConditionalAND.left=current} 'and'|{ConditionalNOT.left=current} 'not') right=Addition)*;
Addition returns Expression:
Multiplication (({Plus.left=current} '+' | {Minus.left=current} '-') right=Multiplication)*;

Multiplication returns Expression:
PrimaryExpression (({Multi.left=current} '*' | {Div.left=current} '/') right=PrimaryExpression)*;

PrimaryExpression returns Expression:
NumericInt|NumericReal|StringLiteral //|Call
| VariableOperande
| '(' Expression ')' ;
StringLiteral:
stringValue=STRING;
NumericInt:
value=INT;

NumericReal:
value=REAL;

VariableOperande:
variable=[VariableDeclaration];


VariableDeclaration:
'dcl' name = ID type=Type //| ('like' variable=[VariableDeclaration]))
('endloc')?('[,S]')?
;
Type:
ShortNumericType | NumericType | StringType | BCDType
;

ShortNumericType:
{ShortNumericType}'#';

NumericType:
{NumericType}'%';


StringType:
{StringType}'$'('='size=INT)?;
BCDType:
{BCDType}('='size=INT)?;



terminal ID : ('a'..'z'|'A'..'Z') ('a'..'z'|'A'..'Z'|'0'..'9')*;
terminal INT returns ecore::EInt: ('0'..'9')+;
terminal REAL returns ecore::EDouble : INT '.' INT;
terminal STRING :
'"' ( '\\' ('b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\') | !('\\'|'"') )* '"' |
"'" ( '\\' ('b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\') | !('\\'|"'") )* "'"
;

terminal SL_COMMENT : (';') !('\n'|'\r')* ('\r'? '\n')?;

terminal WS : (' '|'\t'|'\r'|'\n')+;


test with xtend:

class test{
@Inject extension ParseHelper<CompilationUnit>


@Test def void testBadProgramDeclaration() {
val compilationUnit=
'''


if(a and b)

dcl a%
dcl b%

'''.parse

Assert::assertNotNull(compilationUnit)

val compilalionUnit= compilationUnit.instructions.get(0)
val ifstatement= compilalionUnit as Ifstatement
val expression2= ifstatement.expressions

Assert::assertTrue(expression2 instanceof ConditionalAND)
val conditionalAND=expression2 as ConditionalAND
Assert::assertNotNull(conditionalAND)
Assert::assertNotNull(conditionalAND.left)
Assert::assertTrue(conditionalAND.left instanceof VariableOperande)
val variableOperande = conditionalAND.left as VariableOperande
Assert::assertNotNull(variableOperande.variable)
Assert::assertEquals('a',variableOperande.variable.name)

Assert::assertNotNull(conditionalAND.right)
Assert::assertTrue(conditionalAND.right instanceof VariableOperande)
val rightVariableOperande = conditionalAND.right as VariableOperande
Assert::assertNotNull(rightVariableOperande.variable)
Assert::assertEquals('b',rightVariableOperande.variable.name)
}

}
this test is correct but it shouldn't be
because they don't have endif

Maybe somebody has an idea or can point me into the right direction? Thanks in advance!

Best regards,
Jérôme
Previous Topic:Make my model nodes implement an interface?
Next Topic:Register variables in xtext block of code
Goto Forum:
  


Current Time: Wed Feb 26 23:57:10 GMT 2020

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

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

Back to the top