PetitParser Question

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

PetitParser Question

jgfoster
I’m following the example in the book (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'