Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Error in referencing
Error in referencing [message #1082632] Thu, 08 August 2013 21:19 Go to next message
Roza Ghamari is currently offline Roza GhamariFriend
Messages: 82
Registered: January 2013
Member
I am implementing a grammar in xtext in which the same grammatical structure is used for two different classes in the data model. Basically what I have is a Class A which has two lists of switchType1 and swithcType2 . The grammar for both switches are almost identical other than the references. So the grammar I have is:

A :
'OBJ' name = ID
(
(list1 += switchType1)* |
(list2 += switchType2)*
) ';'
;

switchType1:
'SWITCH' '(' expression = Folrmula ') '{'
//cases
'}'
;

Formula:
param1 = [Parameter] '==' value = INT
;

switchType2:
'SWITCH' '(' objRef = [A|QualifiedName] ')' '{'
//cases
'}'
;

The problem I get is that in content assistant I see the correct suggestions. I also implemented the scope provider for both switches. However, I see an error on this line saying
Couldn't resolve reference to Parameter 'x'.

When my input is:

OBJ a1 ;
OBJ a2 SWITCH (a1) { } ;

What do you think I should do to solve this issue?
Re: Error in referencing [message #1082639 is a reply to message #1082632] Thu, 08 August 2013 21:34 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

your grammar is ambigous

warning(200): ../org.xtext.example.mydsl1/src-gen/org/xtext/example/mydsl1/parser/antlr/internal/InternalMyDsl.g:203:2: Decision can match input such as "'SWITCH' '(' RULE_ID '=='" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
warning(200): ../org.xtext.example.mydsl1.ui/src-gen/org/xtext/example/mydsl1/ui/contentassist/antlr/internal/InternalMyDsl.g:282:1: Decision can match input such as "'SWITCH' '(' RULE_ID '=='" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input



Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Error in referencing [message #1082679 is a reply to message #1082639] Thu, 08 August 2013 22:53 Go to previous messageGo to next message
Roza Ghamari is currently offline Roza GhamariFriend
Messages: 82
Registered: January 2013
Member
Thanks for pointing to the error Christian. I don't get these warnings tho in my actual grammar and I build the xtext successfully. It might be because my grammar is huge there's a bug there. Since I cannot send the grammar, I just wrote a simple version. I have been trying out different versions and none of the work. However, this they don't compile as well. These are my different alternatives:

1

Model:
	params += Parameter*
	greetings+=Greeting*
;
	
	
Greeting:
'OBJ' name = ID
(
list1 += (switchType1 )*
) ';'
;

switchType1:
'SWITCH' '(' ((expression = Formula ) ) ')' '{'
 cases += CaseType1 *
'}'
;

CaseType1:
	'CASE' val = INT ':' '{' objList += Greeting* '}'
;

Formula:
 (param1 = [Parameter] ) | (objRef = [Greeting] )
;


Parameter:
	'PARAM' name = ID ';'
;


2

Model:
	params += Parameter*
	greetings+=Greeting*
;
	
	
Greeting:
'OBJ' name = ID
(
list1 += (switchType1 )*
) ';'
;

switchType1:
'SWITCH' '(' ((expression = Formula )  | (objRef = [Greeting] ) ) ')' '{'
 cases += CaseType1 *
'}'
;

CaseType1:
	'CASE' val = INT ':' '{' objList += Greeting* '}'
;

Formula:
 (param1 = [Parameter] ) ('+' val = INT)?
;

Parameter:
	'PARAM' name = ID ';'
;



alternative 3:

Model:
	params += Parameter*
	greetings+=Greeting*
;
	
	
Greeting:
'OBJ' name = ID
(
(list1 += (switchType1 )*) 
|
(list2 += (switchType2)*)

) ';'
;

switchType1:
'SWITCH' '(' ((expression = Formula ) ) ')' '{'
 cases += CaseType1 *
'}'
;

CaseType1:
	'CASE' val = INT ':' '{' objList += Greeting* '}'
;

Formula:
 (param1 = [Parameter] ) ('+' val = INT)?
;

switchType2:
'SWITCH' '(' objRef = [Greeting] ')' '{'
cases += CaseType1*
'}'
;


Parameter:
	'PARAM' name = ID ';'
;


Th ideal implementation for me is number 3 because my model will be cleaner but I have tried the other two as well. All of these I get this error:

error(211): ../org.xtext.example.mydsl.ui/src-gen/org/xtext/example/mydsl/ui/contentassist/antlr/internal/InternalMyDsl.g:260:1: [fatal] rule rule__Greeting__Alternatives_2 has non-LL(*) decision due to recursive rule invocations reachable from alts 1,2. Resolve by left-factoring or using syntactic predicates or using backtrack=true option.
warning(200): ../org.xtext.example.mydsl.ui/src-gen/org/xtext/example/mydsl/ui/contentassist/antlr/internal/InternalMyDsl.g:260:1: Decision can match input such as "'SWITCH' '(' RULE_ID '+'" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
warning(200): ../org.xtext.example.mydsl.ui/src-gen/org/xtext/example/mydsl/ui/contentassist/antlr/internal/InternalMyDsl.g:260:1: Decision can match input such as "'SWITCH' '(' RULE_ID ')' '{' '}'" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input


I have set backtrack true in MWE2, but still I get the same error.

Only when I remove the ? from Formula val definition, I get the grammar built and running, but this is not possible for my real grammar.

Do you have any idea how I can fix it? How should I implement this grammar?


[Updated on: Thu, 08 August 2013 22:54]

Report message to a moderator

Re: Error in referencing [message #1082860 is a reply to message #1082679] Fri, 09 August 2013 05:53 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

you cannot have 2 references in an ambigous way.
what i dont understand is:

why dont you build an expression that can handle both, param refs and object refs?

e.g.

Referable: Parameter | Greeting


....


ref=[Referable]

and handle other stuff like not beeing able to do a x+2 for greetings via check/typesystem



Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Error in referencing [message #1083238 is a reply to message #1082860] Fri, 09 August 2013 17:34 Go to previous messageGo to next message
Roza Ghamari is currently offline Roza GhamariFriend
Messages: 82
Registered: January 2013
Member

The issue is that i have Formula and Parameter imported from another grammar and datamodel, and I define Greetings in my own model and grammar. So I cannot change the Formula rule and use [referable] instead of [Parameter] there. Do you think there is any other way? In approach 3 the 2 references are not in the same rule, why is that one not working?
Re: Error in referencing [message #1083239 is a reply to message #1082860] Fri, 09 August 2013 17:34 Go to previous messageGo to next message
Roza Ghamari is currently offline Roza GhamariFriend
Messages: 82
Registered: January 2013
Member
The issue is that i have Formula and Parameter imported from another grammar and datamodel, and I define Greetings in my own model and grammar. So I cannot change the Formula rule and use [referable] instead of [Parameter] there. Do you think there is any other way? In approach 3 the 2 references are not in the same rule, why is that one not working?
Re: Error in referencing [message #1083275 is a reply to message #1083239] Fri, 09 August 2013 18:39 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
hi,

not unless you introduce special syntax (r.g. a prefix sign like %$....)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:the TypeComputer in Xbase 2.4
Next Topic:Xcore -> Xtext
Goto Forum:
  


Current Time: Wed Apr 24 19:35:08 GMT 2024

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

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

Back to the top