4 Examples

Here is an example of a simple calculator.

Examples:

  (define calc
    (parse expr
           (expr ((a := mulexp '+ b := mulexp)
                  (+ a b))
                 ((a := mulexp) a))
           (mulexp ((a := simple '* b := simple)
                    (* a b))
                   ((a := simple '* b := simple)
                    (* a b))
                   ((a := simple) a))
           (simple ((a := 'num) a)
                   (('oparen a := expr 'cparen) a))))
  (define g
    (packrat-list-results '((num . 1) (+) (num . 2) (*) (num . 3))))
  > (parse-result-semantic-value (calc g))

  7

See the tests source file for an example of a parser for a simplified Scheme grammar.