|
Re: Error in referencing [message #1082639 is a reply to message #1082632] |
Thu, 08 August 2013 21:34 |
|
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 |
Roza Ghamari 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 |
|
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
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04743 seconds