[英]Left recursion mutally in antlr 3
我尝试在antlr 3中解析语法,但是左递归存在问题,并且我是解析语法的初学者。
The problem is that the roules b, e, t, f are referencing each other without consuming any input - eg a number could be accepted by multiple sequences: 问题在于规则b,e,t,f在不消耗任何输入的情况下相互引用-例如,一个数字可以被多个序列接受:
b -> NUM
b -> e -> t -> f -> b -> NUM
...
the cycle you have there probably is meant to express a sub-expression - what's missing there then are parentheses: 您在那里的循环可能意味着表达一个子表达式-那里缺少的是括号:
start : e;
e : t (a t)*;
t : f (m f)*;
f : ID | NUM | '-'NUM | '(' e ')';
a : '+' | '-';
m : '*' | '/';
(I also changed e : t | tat
to e : t | eat
to allow 1 + 2 + 3
) (我也将
e : t | tat
更改为e : t | eat
以允许1 + 2 + 3
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.