Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Variable reference error(XText says me that I haven't of an existing variable)
Variable reference error [message #1796323] Wed, 10 October 2018 15:09 Go to next message
kozhaev Vladimir is currently offline kozhaev VladimirFriend
Messages: 108
Registered: July 2009
Senior Member
Please, see my grammar below. I have the following error for the mentioned text
Quote:

operation test(){
i:integer=1;
j:integer=i;
}


Quote:

Couldn't resolve reference to Variable 'i'.


Line 3

Where is the problem and how to fix it?

Regards,
Vladimir

grammar org.blockchain.rell.Rell with org.eclipse.xtext.common.Terminals

generate rell "http://www.blockchain.org/rell/Rell"

Model:
	entities+=TheClass*
	operations+=Operation*;

TheClass:
	'class' name=ID ('extends' superType=[TheClass])? '{'
	attributes+=Attribute*
	'}';

Operation:
	"operation" name=ID "(" parameters=RelAttrubutesList? ")" "{" statements+=Statement* "}";

Statement:
	(Relational | Variable) ';';

Variable:
	declaration=VariableDeclaration '=' expression=Expression;

Relational:
	Update | Delete | Create;

Update:
	'update' entity=ID '(' expressions=ExpressionsModel? ')' '{' variableList+=VariableInit
	(',' variableList+=VariableInit*)? '}';

Delete:
	'delete' entity=ID '(' expressions=ExpressionsModel? ')';

Create:
	'create' entity=ID '(' expressions=ExpressionsModel? ')';

ExpressionsModel:
	elements+=ConditionElements (',' elements+=ConditionElements*)?;

ConditionElements:
	compareName=ID ('==' | '!=' | '>' | '<' | '>=' | '<=') expr=Expression;


VariableInit:
	name=ID '=' expression=Expression;

Expression:
	Or;

Or returns Expression:
	And ({Or.left=current} "or" right=And)*;

And returns Expression:
	Equality ({And.left=current} "and" right=Equality)*;

Equality returns Expression:
	Comparison ({Equality.left=current} op=("==" | "!=")
	right=Comparison)*;

Comparison returns Expression:
	PlusOrMinus ({Comparison.left=current} op=(">=" | "<=" | ">" | "<")
	right=PlusOrMinus)*;

PlusOrMinus returns Expression:
	MulOrDiv (({Plus.left=current} '+' | {Minus.left=current} '-')
	right=MulOrDiv)*;

Atomic returns Expression:
	{IntConstant} value=INT |
	{StringConstant} value=STRING |
	{BoolConstant} value=('true' | 'false') |
	{VariableRef} variable=[Variable];

MulOrDiv returns Expression:
	Primary ({MulOrDiv.left=current} op=('*' | '/')
	right=Primary)*;

Primary returns Expression:
	'(' Expression ')' |
	{Not} "not" expression=Primary |
	Atomic;

RelAttrubutesList:
	value+=RelAttribute (',' value+=RelAttribute)*;

RelAttribute:
	name=ID ':' reference=TypeReference;

Attribute:
	modificator=Prefix? variable=VariableDeclaration ';';

VariableDeclaration:
	name=ID ':' type=TypeReference;

TypeReference:
	primitive=PrimitiveType | entity=EntityType;

PrimitiveType:
	Text | Integer | Json | ByteArray;

EntityType:
	entity=[TheClass];

Json:
	'json';

Integer:
	'integer' | 'timestamp';

Text:
	'text' | 'tuid' | 'name';

ByteArray:
	'byte_array' | 'signer' | 'guid' | 'pubkey';

Prefix:
	'key' | 'index';

Re: Variable reference error [message #1796324 is a reply to message #1796323] Wed, 10 October 2018 15:11 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Variable:
declaration=VariableDeclaration '=' expression=Expression;

variable has no name (you could adapt IQualifiedNameProvider for that)

but you refer

{VariableRef} variable=[Variable];

could change this to

{VariableRef} variable=[VariableDeclaration];

too


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Variable reference error [message #1796347 is a reply to message #1796324] Thu, 11 October 2018 12:39 Go to previous message
kozhaev Vladimir is currently offline kozhaev VladimirFriend
Messages: 108
Registered: July 2009
Senior Member
Look like using of the IQualifiedNameProvider is what I need because I can't use Variable declarations in the expressions, but variables only
Previous Topic:IXTextBuilderParticipant for VS Code
Next Topic:Xtext 2.15.0 released!
Goto Forum:
  


Current Time: Thu Mar 28 19:46:41 GMT 2024

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

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

Back to the top