我有以下语法来检查XML文件的有效性,文件以元素开头,然后是根节点。
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 '"'
;我得到了一个reduce/reduce冲突,但我不知道如何找到它。任何帮助都将不胜感激。
发布于 2012-03-11 04:16:21
对于XML语法来说,这看起来有点奇怪。确实不需要空的node_list%s或attribute_list%s吗?
不管怎样,试试这个:
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 */
; https://stackoverflow.com/questions/9649642
复制相似问题