title: PLY/YACC parsing conflicts on PDF
body: <p>I'm trying to parse PDFs with PLY lex/yacc, and Ive hit a snag regarding yacc parsing rule that govern <code>NUMBER</code> tokens, arrays, and indirect_references. </p>
  
  <p>The relevant source:</p>
  
  <pre><code>def p_value_list(t):
     r'''value_list : value_list value
                   | value'''
     if t.slice[0] == 'item_list':
         t[0] = {'type':'value_list', 'children' : t[0]['children'] + [t[1]] }
     else:
         t[0] = {'type':'value_list', 'children' : [t[1]] }
     pass
  def p_value(t):
     r'''value : dictionary
              | array
              | indirect_reference
              | NUMBER
              | HEX
              | STREAM
              | TEXT
              | BOOL
              | empty'''
     t[0] = t[1]
     pass
  def p_indirect_reference(t):
     r'''indirect_reference : NUMBER NUMBER KEY_R'''
     t[0] = {'type':'indirect_reference', 'children' : [t[1], t[2]] }
     pass
  def p_array(t):
     r'''array : LBRACKET value_list RBRACKET'''
     t[0] = {'type':'array', 'children' : t[2] }
     pass
  </code></pre>
  
  <p>Which results in ambiguous rules regarding <code>NUMBERS</code> (do you have a list <code>NUMBER NUMBER</code> or do you have an indirect reference <code>NUMBER NUMBER KEY_R</code>) -- The errors I get range from unexpected <code>NUMBER</code> tokens when parsing the simple array <code>[0 0 0]</code></p>
  
  <pre><code>ERROR: Error  : obj_list NUMBER NUMBER OBJ LTLT key_value_list ID LBRACKET NUMBER NUMBER . LexToken(NUMBER,'0',1,166273)
  </code></pre>
  
  <p>to errors like this</p>
  
  <pre><code>ERROR: Error  : obj_list NUMBER NUMBER OBJ LTLT key_value_list ID LBRACKET NUMBER NUMBER . LexToken(RBRACKET,']',1,88)
  </code></pre>
  
  <p>Which I assume is expecting a <code>KEY_R</code> token when really its an array of two <code>NUMBER</code> tokens: <code>[ 486 173]</code></p>
  
  <p>For the brave, PDF Spec and full source linked.</p>
  
  <p>[1]  <a href="https://github.com/opticaliqlusion/pypdf/blob/master/pypdf.py" rel="nofollow">https://github.com/opticaliqlusion/pypdf/blob/master/pypdf.py</a></p>
  
  <p>[2] <a href="http://wwwimages.adobe.com/content/dam/Adobe/en/devnet/pdf/pdfs/pdf_reference_1-7.pdf" rel="nofollow">http://wwwimages.adobe.com/content/dam/Adobe/en/devnet/pdf/pdfs/pdf_reference_1-7.pdf</a></p>