Skip to main content



      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 18:07 Go to next message
Eclipse UserFriend
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 08:41 Go to previous message
Eclipse UserFriend
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
Previous Topic:No operations in Xexpressionorvardeclaration
Next Topic:Automatically Load generated Xtext
Goto Forum:
  


Current Time: Tue Sep 02 12:28:20 EDT 2025

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

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

Back to the top