title: Parser for user defined infix operators
body: <p>I am writing an interpreter for a language where functions can be used as operators. However, the functions content will only be known at runtime.</p>
  
  <p>For that I considered two solutions:</p>
  
  <ul>
  <li>Parsing is done at runtime, using the runtime information on the function</li>
  <li>All user-defined operators use default values for precedence and associativity.</li>
  </ul>
  
  <p>I chose the latter as I see a number of advantages in parsing separately to execution.</p>
  
  <p>Now it comes to implementation and I am interested to see what options there are. My initial thoughts are a shift reduce parser, but I have little experience in constructing parsers.</p>
  
  <p>Example:</p>
  
  <pre><code>LHS op RHS : LHS * RHS     /* define a binary operator 'op' */
  var : 3                    /* define a variable */
  print 5 op var             /* should print 15 */
  
  LHS op RHS : LHS / RHS     /* Re-define op */
  print var op var           /* Should print 1 */
  </code></pre>
  
  <p>in the last case, the parser will get from the lexer: " <code>id</code> <code>id</code> <code>id</code> <code>id</code> ". Only at runtime do I know that the 'op' id is an operator.</p>