Decision and expression [message #1506064] |
Wed, 10 December 2014 14:53 |
Grégoire Avot Messages: 7 Registered: December 2014 |
Junior Member |
|
|
Hello forum,
I want to parse following input: a=[1+2+3] or a=[1+2+3:4+5.6]
-----------------------------------
Model: id=ID '=' add=Element;
Element: '[' (range1d=Addition | range2d=Range ) ']';
Range: left=Addition ':' right=Addition;
Addition returns Expression:
Multiplication ({Addition.left=current} '+' right=Addition)?;
Multiplication returns Expression:
Primary ({Multiplication.left=current} '*' right=Multiplication)?;
Primary returns Expression:
litteral = NumberLiteral |
'(' Addition ')';
NumberLiteral: value=INT;
-----------------------------------
When I compile this grammar, I get an error:
[fatal] rule ruleElement 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.
If I remove one of the two decisions in Element rule, I do not have compilation error. I do not understand why. Solution I used to solve this problem is to merge Element and Rule into a single rule using two actions:
-----------------------------------
Element: '[' Addition ( {Scalar.size=current} | ( {Range.left=current} ':' right=Addition)) ']';
-----------------------------------
Now everything works fine. But I still do not understand what I did wrong in my first implementation. Can someone explain this ?
Best regards,
Grégoire.
[Updated on: Wed, 10 December 2014 14:55] Report message to a moderator
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04287 seconds