I have a dangling-else problem in Coco/R. I try to understand the Coco/R User Manual and I ask Google, but I can't solve the problem on my own.
I simplified my problem to the following Coco/R grammar (saved in new4.atg):
COMPILER Expr
CHARACTERS
digit = '0'..'9'.
letter = 'A'..'Z'.
TOKENS
number = digit { digit }.
name = letter { digit | letter }.
PRODUCTIONS
Expr = Test | Id Test.
Test = Test2.
Test2=Id | "(" Test ")".
Id=IdName|IdNumber.
IdName = name.
IdNumber = number.
END Expr.
When I want to build the compiler with coco.bat, I get this answer:
Coco/R (Dec 22, 2014)
checking
new 4.atg(15,1): LL1 warning in Expr: number is start of several alternatives
new 4.atg(15,1): LL1 warning in Expr: name is start of several alternatives
parser + scanner generated
0 errors detected
In the best result in Google, I have read that I can declare IF(isXXXFollowYYY()) statement, but I don't how and if it's the best solution.
(In my example: Expr = Test | If(isTestFollowID)Id Test. But where is isTestFollowID declared?)
I want to get no warnings, when I start coco.bat.
Your grammar is ambiguous.
From
Expr, upon seeing anIdtoken, the parser can go eitheror
An LL(1) parser will not know which path to take.
The immediate problem can be fixed by pulling
Idout into a lead-in optional component in yourExprproduction:Instead of
you can do
However the
Testproduction can also match anIdat its beginning, so it appears that further refactorings will be needed to make the grammar LL(1).