Advanced Functional Prog.

back - up - cont


Parsing expressions

Answers (1)

EXP = NUM ('+' EXP | '*' EXP | epslion)
let rec exp = 
  num'       && fun n1 -> 
  ((sym '+') && fun _  -> 
   exp       && fun n2 -> 
   ret (n1+n2)) 
  || 
  ((sym '*') && fun _  -> 
   exp       && fun n2 -> 
   ret (n1*n2)) 
  || (ret n1);;

exp "12+34*56";;

15 - 18