2012-03-10 4 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

답변

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 */ 
    ; 
+0

그것이 작동하는지 확인하기 위해 주먹 버전입니다. 예, 대답을 위해 node_list 노드를 사용해 주셔야합니다. – mihajlv