1

I have the following grammar for checking the validity of an XML file, the file starts with an element and then the root node.

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

I am getting 1 reduce/reduce conflict, and I don't know how to find it. Any help would be appreciated.

mihajlv
  • 2,275
  • 4
  • 36
  • 59

1 Answers1

1

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 */
    ; 
n. m. could be an AI
  • 112,515
  • 14
  • 128
  • 243
  • it is a fist version just to make sure it works, yes I figured it out it should be `node_list node` thanks for the answer though. – mihajlv Mar 10 '12 at 20:22