2012-03-10 131 views
1

我有以下语法用于检查XML文件的有效性,该文件从元素开始,然后是根节点。YACC语法减少/减少冲突

program 
    : terminal_node 
     root 
    ; 
root 
    : '<' ID attribute_list '>' node_list '<' ID '/''>' 
    ; 
node_list 
    : node 
    | node node_list 
    ; 
node 
    : terminal_node 
    : nonterminal_node 
    ; 

terminal_node 
    : '<' ID attribute_list '/''>' 
    ; 

nonterminal_node 
    : '<' ID attribute_list '>' node_list '<' ID '/''>' 
    ; 
attribute_list 
    : attribute 
    | attribute attribute_list 
    ; 

attribute 
    : ID ASSIGNOP '"' ID '"' 
    | ID ASSIGNOP '"' NUM '"' 
    ; 

我得到1减少/减少冲突,我不知道如何找到它。任何帮助,将不胜感激。

+0

“根” 和 “nonterminal_node” 是完全一样的。 – wildplasser 2012-03-10 20:12:27

回答

1

这对XML语法看起来有点奇怪。你确定你不想要空的node_listattribute_list吗?

不管怎样,试试这个:

node_list 
    : node 
    | node_list node /* list first, element second, this is the LALR way */ 
    ; 
node 
    : terminal_node 
    | nonterminal_node /* note a typo in your code here */ 
    ; 
+0

这是一个拳头的版本,以确保它的工作,是的,我想出了它应该是'node_list节点'谢谢你的答案。 – mihajlv 2012-03-10 20:22:21