Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xbase - Differ between Statements and Expressions
Xbase - Differ between Statements and Expressions [message #745083] Sat, 22 October 2011 15:20 Go to next message
Daniel Missing name is currently offline Daniel Missing nameFriend
Messages: 101
Registered: July 2011
Senior Member
Hi everybody.

Currently Xbase does not differ between Statements and Expressions. Is there a way to add this behaviour to Xbase?

The problem is Xbase allows this code pieces:
..
var myVar = 2 + ( switch(foo) {
    case 'a': 1
    case 'b': 2
    case 'c': 3
    default:  0
});

while(  if(flag) condition1() else condition2() ) {

}


But in my language I want to create this would be invalid code. Is there an easy way to modify Xbase that the following XPrimaryExpressions are detected as Statements:

XBlockExpression, XSwitchExpression, XIfExpression, XForLoopExpression, XWhileExpression, XDoWhileExpression, XTryCatchFinallyExpression

Why would I do that? Most programming languages like C# and Java clearly differ between normal expressions and statements and therefore such code pieces as the mentioned example are not possible. This would make the code generation a lot more complicated.

Cheers Daniel
Re: Xbase - Differ between Statements and Expressions [message #745131 is a reply to message #745083] Sat, 22 October 2011 16:03 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14670
Registered: July 2009
Senior Member
Hi,

isnt that something for the typeprovider

	@Override
	protected JvmTypeReference _type(XIfExpression object, boolean rawType) {
		return getPrimitiveVoid(object);
	}


~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xbase - Differ between Statements and Expressions [message #745152 is a reply to message #745131] Sat, 22 October 2011 16:21 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14670
Registered: July 2009
Senior Member
or you change the grammar like

	XPrimaryExpression returns xbase::XExpression:
	XConstructorCall |
	XBlockExpression |
	XSwitchExpression |
	XFeatureCall |
	XLiteral |
	XThrowExpression |
	XReturnExpression |
	XTryCatchFinallyExpression |
	XParenthesizedExpression;
	
	XExpressionInsideBlock returns xbase::XExpression:
	XVariableDeclaration | XExpression | XIfExpression | ...;


~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Xbase - Differ between Statements and Expressions [message #745410 is a reply to message #745152] Sat, 22 October 2011 20:15 Go to previous message
Daniel Missing name is currently offline Daniel Missing nameFriend
Messages: 101
Registered: July 2011
Senior Member
Thanks, I'll have a look at it. But I think the grammar overriding should make my needs possible.
I can't say If everything works because my language is not yet usable (a lot of xtend like stuff needs to be implemented).
Previous Topic:Lookahead in Xtext?
Next Topic:Generated parser problem
Goto Forum:
  


Current Time: Sat Apr 27 04:30:23 GMT 2024

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

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

Back to the top