문제

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 '"'
    ;
.

나는 분쟁을 줄이거 나 줄이고, 나는 그것을 찾는 방법을 모른다.어떤 도움이 감사 할 것입니다.

도움이 되었습니까?

해결책

This looks a bit strange for an XML grammar. Are you sure you don't want empty node_lists or attribute_lists?

Anyway, try this:

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 ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top