title: parsing a postscript file
body: <p>I’m translating PDFMiner (an open source PDF to text program written in python) into objective-c.
  Some fonts have a postscript file in them with character names and their encoded values. 
  For example: </p>
  
  <pre><code>/Encoding 256 array
  0 1 255 {1 index exch /.notdef put} for
  dup 65 /A put
  dup 67 /C put
  dup 70 /F put
  dup 45 /hyphen put
  </code></pre>
  
  <p>I don’t actually know what the above code does. I’m guessing it puts those pairs into a dictionary. I’m not sure what dup does at all. 
  What the above code means to me is that if I see a 45 in the PDF then I’ll look it up and convert it to a hyphen, or if I see a 70 then I convert it to an F etc. </p>
  
  <p>The code I’m copying uses a full blown Postscript tokenizer to parse all put commands in a postscript file. For each put command it creates a dictionary with the key value pair corresponding the the put operands. </p>
  
  <p>My question is, do I really need to build an entire Postscript tokenizer to parse these things?</p>
  
  <p>A far simpler alternative would be to scan for every occurrence of the string “put” then look at the two preceding words. If the two preceding words are a number followed by a /x then I assume this is what I want otherwise ignore it. </p>
  
  <p>I don’t know postscript at all, but I figure anyone who does can tell me if my simpler alternative has any corner cases that will screw things up. </p>
  
  <p>Thanks!</p>