[英]YACC grammar reduce/reduce conflict
我有以下語法來檢查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 '"'
;
我得到1個減少/減少沖突,但我不知道如何找到它。 任何幫助,將不勝感激。
對於XML語法,這看起來有點奇怪。 您確定不想要空的node_list
或attribute_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 */
;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.