I’m following the example in the book 
(http://pharobooks.gforge.inria.fr/PharoByExampleTwo-Eng/latest/PetitParser.pdf 
<http://pharobooks.gforge.inria.fr/PharoByExampleTwo-Eng/latest/PetitParser.pdf>,
 pp. 9-10) with a slight modification. I believe that the example evaluates 
things that have the same precedence from right-to-left (is that correct?). 
I’ve tried to adjust things so that it evaluates from left to right, but get an 
error. Any advice?

James

| number term prod prim start |
number := #digit asParser plus flatten ==> [ :str | str asNumber ].
term := PPDelegateParser new.
prod := PPDelegateParser new.
prim := PPDelegateParser new.
term setParser: (term memoized , $+ asParser trim , prod ==> [ :nodes | nodes 
first + nodes last ]) / prod.
prod setParser: (prim , $* asParser trim , prod ==> [ :nodes | nodes first * 
nodes last ]) / prim.
prim setParser: ($( asParser trim , term , $) asParser trim ==> [ :nodes | 
nodes second ]) / number.
start := term end.
start parse: '1 + 2'

Reply via email to