Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » No JVM Operators XExpressionOrVarDeclaration (Can't use var x = 1 +2 regradless of grammer edits or infer)
No JVM Operators XExpressionOrVarDeclaration [message #1736367] Tue, 28 June 2016 22:07 Go to next message
Mostafa Kamel is currently offline Mostafa KamelFriend
Messages: 2
Registered: June 2016
Junior Member
i'm a beginner at Xtext and i have the following grammer nearly identical to Tortoise language(one of 7 Languages )

grammar xjad.Opponent with org.eclipse.xtext.xbase.Xbase

generate opponent "http://www.Opponent.xjad"

import "http://www.eclipse.org/xtext/xbase/Xbase"

Program :
  subPrograms+=SubProgram*
  body=Body
;  
  
SubProgram:
	'Node'  type=JvmTypeReference name=ID MAC=STRING  IP=STRING
;

Body returns XBlockExpression:
  {XBlockExpression}
  'begin'
  (expressions+= XExpressionOrVarDeclaration ';'?)*
  'end';
 


	
var alpha = 1 + 2; //Fails with + cannot be resolved.


The following is the inferance engine

public static val INFERRED_CLASS_NAME = 'OpponentProgram'


	final String ImplicitSocketName = "ImplicitSocket";
	def dispatch void infer(Program program, IJvmDeclaredTypeAcceptor acceptor, boolean isPreIndexingPhase) {

		acceptor.accept(program.toClass(INFERRED_CLASS_NAME)) [

			members += toField(ImplicitSocketName,typeRef(UsbSocket))[
					static = true
					final =true
					initializer = '''new UsbSocket()'''
			]
			
			for (subp : program.subPrograms) {
				members += subp.toField(subp.name, subp.type) [
					static = true
					final =true
					initializer = '''new «subp.type.qualifiedName»(«ImplicitSocketName»,"«subp.MAC»","«subp.IP»")'''
					

				]
			}

			if (program.body != null) {

				members += program.toMethod("main", typeRef(Void.TYPE)) [
					parameters += program.toParameter("args", typeRef(String).addArrayTypeDimension)
					static = true
					varArgs = true
					body = program.body
				]

			}

		]
	}


if(y == "ASD") .....
i see the following error in the editor
== cannot be resolved.
and same for any == =< => ++ 1+2 and any similar operation
Re: No JVM Operators XExpressionOrVarDeclaration [message #1736448 is a reply to message #1736367] Wed, 29 June 2016 12:41 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13724
Registered: July 2009
Senior Member
make sure xbase.lib is on the classpath of the model project (the one containing xxxx.yourdsl)
e.g. by adding the libary "xtend" to the java build path of the (java) project
or adding it as required plugin to the (plugin) project


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:No operations in Xexpressionorvardeclaration
Next Topic:Automatically Load generated Xtext
Goto Forum:
  


Current Time: Wed Jan 27 08:21:27 GMT 2021

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

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

Back to the top