Pregunta

Tengo la siguiente gramática para verificar la validez de un archivo XML, el archivo comienza con un elemento y luego el nodo raíz.

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

Estoy obteniendo 1 Reducir / reducir el conflicto, y no sé cómo encontrarlo.Cualquier ayuda sería apreciada.

¿Fue útil?

Solución

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 */
    ; 
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top