Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Logical expressions within XExpressionOrVarDeclaration
Logical expressions within XExpressionOrVarDeclaration [message #1690364] Thu, 26 March 2015 21:58 Go to next message
Som 2015 is currently offline Som 2015Friend
Messages: 16
Registered: March 2015
Junior Member
Hello all,

Can someone tell me how to include logical and arithmetic expressions within XExpressionOrVarDeclaration and generate code for them?

I get the following kind of error: The method ==(int) is undefined

Thanks a lot
Re: Logical expressions within XExpressionOrVarDeclaration [message #1690396 is a reply to message #1690364] Fri, 27 March 2015 06:38 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

can you elaborate what you are actually doing? the operators == >= <= > < are already defined in xbase and are implemented by the xbase libary. so simply add this one to the classpath of the project that contains your model file (org.eclipse.xtext.xbase.lib)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Logical expressions within XExpressionOrVarDeclaration [message #1690423 is a reply to message #1690396] Fri, 27 March 2015 09:27 Go to previous messageGo to next message
Som 2015 is currently offline Som 2015Friend
Messages: 16
Registered: March 2015
Junior Member
Hello,

I want to write simple Boolean expressions such as : x == y && y > 10

In my grammar, I have tried the followings:

Condition returns XBlockExpression:
{Condition}
(expressions += XAndExpression)*

But this does not compile. we get the error "The method &&(boolean) is not defined".

We used normal XExpression and XExpressionOrVarDeclaration but get the same error.

How can we get a logical expression to parse, and generate Java code from it?

Thanks
Re: Logical expressions within XExpressionOrVarDeclaration [message #1690424 is a reply to message #1690423] Fri, 27 March 2015 09:31 Go to previous messageGo to next message
Som 2015 is currently offline Som 2015Friend
Messages: 16
Registered: March 2015
Junior Member
Just to mention that if I use XExpressionOrVarDeclaration, and I try to write an "If" statement in my language, I cannot write a boolean expression as "if" condition. So, something is not working....
Re: Logical expressions within XExpressionOrVarDeclaration [message #1690425 is a reply to message #1690424] Fri, 27 March 2015 09:34 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
did you add the lib to the deps?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Logical expressions within XExpressionOrVarDeclaration [message #1690431 is a reply to message #1690425] Fri, 27 March 2015 10:04 Go to previous messageGo to next message
Som 2015 is currently offline Som 2015Friend
Messages: 16
Registered: March 2015
Junior Member
Hello,

Thanks, I added the libraries, so by having XExpressionOrVarDeclaration, I can write Boolean expressions.

However, what I actually want is when *defining* a method to have a boolean expression in its signature. Something like

op method(x>10&&y<10) {...}

How can we get this? In my grammar, I get the error that such expression is not allowed because it does not have side effects.

Thanks
Re: Logical expressions within XExpressionOrVarDeclaration [message #1690432 is a reply to message #1690431] Fri, 27 March 2015 10:09 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
what is the semantics of such an expression? maybe the same as here? https://www.eclipse.org/forums/index.php/t/1065012/

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Logical expressions within XExpressionOrVarDeclaration [message #1690433 is a reply to message #1690432] Fri, 27 March 2015 10:11 Go to previous messageGo to next message
Som 2015 is currently offline Som 2015Friend
Messages: 16
Registered: March 2015
Junior Member
The semantics is that the method can only be executed if the Boolean expression evaluates to the true.
Re: Logical expressions within XExpressionOrVarDeclaration [message #1690437 is a reply to message #1690433] Fri, 27 March 2015 10:23 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
So it is the same semantics

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Code generator for Smalljava example
Next Topic:Leading whitespaces in template
Goto Forum:
  


Current Time: Thu Apr 25 01:05:06 GMT 2024

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

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

Back to the top