开发者

Why are there 3 parsing conflicts in my tiny grammar?

//complete
start ::= template.

//template
template ::= template_elements.
template ::= template template_elements.
template ::= .

//template elements
template_elements(res) ::= COMMENT. 
template_elements(res) ::= tag(t). 

//tag
tag(res) ::= LDEL exp(e) RDEL. 

//exp
exp(res) ::= value(v). 
exp(res) ::= exp(e1) OP(o) exp(e2).

//value
value(res) ::= variable(v). 

//variable
variable(res) ::= DOLLAR ID(i).
开发者_如何转开发

Anyone knows where the conflicts locate?

UPDATE

If I delete exp(res) ::= exp(e1) OP(o) exp(e2).,there'll be only two conflicts,but I don't know why this is causing conflict...

UPDATE2

Why it's OK here:

template ::= template_elements.
template ::= template template_elements.
template ::= .


To fix your exp ambiguity, set the precedence and associativity -- see the documentation under Precedence Rules.

Lemon can handle left recursion, but your template rule should be

template ::= template template_elements.
template ::= .

Because template can be empty, you don't need the template ::= template_elements case.

What errors do you get after making those changes?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜