Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » rule ruleIfstatement has non-LL(*) decision due to recursive rule invocations
rule ruleIfstatement has non-LL(*) decision due to recursive rule invocations [message #901519] Mon, 13 August 2012 08:41
Laigle jérôme is currently offline Laigle jérômeFriend
Messages: 26
Registered: August 2012
Junior Member
Hi,
I'm working on a DSL and i have problem with my grammar for define if
I need to support this type of instruction for example:

if a<0 : b++
if b<5
c++
d++
endif
So, I've started with the following construct


Ifstatement:
IfSimpleInstruction|IfSeveralInstruction


;
IfSimpleInstruction:
{IfSimpleInstruction}'if'(expressions=Expression) ':'instruction=Instruction
;
IfSeveralInstruction:
{IfSeveralInstruction}
'if'(expressions=Expression)
then+=Instruction*
(=>'else' else+=Instruction*)?
'endif'
;
Instruction:
ControleStructure|VariableDeclaration|VariableAssignment
;
VariableAssignment:
dcl=[VariableDeclaration]'='expr=Expression
;

ControleStructure:
Ifstatement
;
Expression :
CompareOperator;

CompareOperator returns Expression:
ConditionalOR(( /* {Inclusion.left=current} '='|*/{Equality.left=current}'=='|{NoInclusion.left=current}'!='|{Different.left=current}'<>'|{Inferrior.left=current}'<'|{Superior.left=current}'>'|{SuperiorOrEqual.left=current}'>='|{InferriorOrEqual.left=current}'<=') right=ConditionalOR)*;

ConditionalOR returns Expression:
Addition (({ConditionalOR.left=current} 'or'|{ConditionalOX.left=current} 'ox'|{ConditionalAND.left=current} 'and'|{ConditionalNOT.left=current} 'not') right=Addition)*;
Addition returns Expression:
Multiplication (({Plus.left=current} '+' | {Minus.left=current} '-') right=Multiplication)*;

Multiplication returns Expression:
PrimaryExpression (({Multi.left=current} '*' | {Div.left=current} '/') right=PrimaryExpression)*;

PrimaryExpression returns Expression:
NumericInt|NumericReal|StringLiteral //|Call
| VariableOperande
| '(' Expression ')'
;
StringLiteral:
stringValue=STRING
;
NumericInt:
value=INT;

NumericReal:
value=REAL;

VariableOperande:
variable=[VariableDeclaration]
;


VariableDeclaration:
'dcl' name = ID type=Type //| ('like' variable=[VariableDeclaration]))
('endloc')?('[,S]')?
;
Type:
ShortNumericType | NumericType | StringType | BCDType
;

ShortNumericType:
{ShortNumericType}'#';

NumericType:
{NumericType}'%';


StringType:
{StringType}'$'('='size=INT)?
;
BCDType:
{BCDType}('='size=INT)?;



terminal ID : ('a'..'z'|'A'..'Z') ('a'..'z'|'A'..'Z'|'0'..'9')*;
terminal INT returns ecore::EInt: ('0'..'9')+;
terminal REAL returns ecore::EDouble : INT '.' INT;
terminal STRING :
'"' ( '\\' ('b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\') | !('\\'|'"') )* '"' |
"'" ( '\\' ('b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\') | !('\\'|"'") )* "'"
;

terminal SL_COMMENT : (';') !('\n'|'\r')* ('\r'? '\n')?;

terminal WS : (' '|'\t'|'\r'|'\n')+;



I have one eror: InternalLanguage.g:80:1: [fatal] rule ruleIfstatement 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.

I don't understand why this grammar it's not good because IfSimpleInstruction and IfSeveralInstruction haven't the same define


Maybe somebody has an idea or can point me into the right direction? Thanks in advance!
Best regards,
Jérôme
Previous Topic:Transitive / recursive import
Next Topic:Creating typrefs for bounded wildcards
Goto Forum:
  


Current Time: Sun Nov 29 00:27:35 GMT 2020

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

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

Back to the top