Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » problem for define dsl
problem for define dsl [message #902737] Mon, 20 August 2012 08:21 Go to next message
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 my grammar
I defined for DoLoop the keyword 'do' and 'loop'
i realised test with xtend but i see that keyword 'loop' it's not obligatory (test is ok without keyword 'loop')
I don't understand why
Maybe is not a good define

My dsl:

CompilationUnit:
instructions+=Instruction*;
Instruction:
ControleStructure|VariableDeclaration
|VariableAssignment|SymbolRef
;
ControleStructure:
DoLoop
;
DoLoop:
{DoLoop}
'do'
instructions+=Instruction*
'loop'
;
VariableDeclaration returns Symbol:
'dcl' name = ID type=Type/*( | ('like' variable=[VariableDeclaration |Type]))*/
('endloc')?('[,S]')?
;
Type:
ShortNumericType | NumericType | StringType | BCDType
;

ShortNumericType:
{ShortNumericType}'#';

NumericType:
{NumericType}'%';


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

VariableAssignment:
dcl=[Symbol]'='expr=Expression
;
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
|SymbolRef
| '(' Expression ')'
;

SymbolRef:
CallOrVariableSymbolRef
;

CallOrVariableSymbolRef:
('call')? symbol=[Symbol|ID] ("(" (arguments+=Expression)? ("," arguments+=Expression)* ")")?
;


StringLiteral:
stringValue=STRING
;
NumericInt:
value=INT;

NumericReal:
value=REAL;


test with xtend:

@RunWith(typeof(XtextRunner))
@InjectWith(typeof(LanguageInjectorProvider))
class test {
@Inject extension ParseHelper<CompilationUnit>

@Test
def void testSegmentLoopDeclaration()
{
val compilationUnit =
'''
program "MyProgramme"

segment 0
dcl a%
do
a=a+1


eseg 0
end
'''.parse

val instruction= compilationUnit.instructions.get(0)
val variable= instruction as Symbol
Assert::assertEquals("a", variable.name)
val num= variable.type
Assert::assertNotNull(num)
Assert::assertTrue(num instanceof NumericType)
val numericType= num as NumericType
Assert::assertNotNull(numericType)
val controleStructure=compilationUnit.instructions.get(1) as ControleStructure
val doLoop= controleStructure as DoLoop
Assert::assertNotNull(doLoop)//test should be false
val variableAssignement=doLoop.instructions.get(0) as VariableAssignment
val plus=variableAssignement.expr as Plus
Assert::assertNotNull(plus)
val variableOperande = plus.left as SymbolRef
val variable2 = variableOperande as CallOrVariableSymbolRef
Assert::assertEquals('a',variable2.symbol.name)
val numeric= plus.right as NumericInt
Assert::assertEquals(1,numeric.value)
}
}
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: problem for define dsl [message #902780 is a reply to message #902737] Mon, 20 August 2012 12:03 Go to previous messageGo to next message
Laigle jérôme is currently offline Laigle jérômeFriend
Messages: 26
Registered: August 2012
Junior Member
when i defined dsl like this:


DoLoop:
{DoLoop}
'do'
instructions+=Instruction*
'loop'
;


And i realised test like this :
do
a=a+1



the test should be wrong because it doesn't have keyword 'loop'
but the test passed...
i don't understand why...
Re: problem for define dsl [message #903083 is a reply to message #902780] Tue, 21 August 2012 20:49 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3108
Registered: July 2009
Senior Member
Hi,

you should assert something like compilationUnit.eResource.errors.isEmpty

The parser may recover from simple errors like missing keywords, but it
will notify users about them in the errors list of the resource.

Regards,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 20.08.12 14:04, schrieb Laigle jérôme:
> when i defined dsl like this:
>
> DoLoop:
> {DoLoop}
> 'do'
> instructions+=Instruction*
> 'loop'
> ;
>
>
> And i realised test like this :
> do
> a=a+1
>
>
>
> the test should be wrong because it doesn't have keyword 'loop'
> but the test passed...
> i don't understand why...
Re: problem for define dsl [message #903241 is a reply to message #903083] Wed, 22 August 2012 16:18 Go to previous message
Laigle jérôme is currently offline Laigle jérômeFriend
Messages: 26
Registered: August 2012
Junior Member
thank you

best regard
jérome
Previous Topic:Using the index with an hierarchically directory tree
Next Topic:Boolean literal serialization from GMF adding parens
Goto Forum:
  


Current Time: Fri Nov 27 00:29:31 GMT 2020

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

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

Back to the top