diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/calc.lisp | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/examples/calc.lisp b/examples/calc.lisp index 7b2f9ef..4d8766a 100644 --- a/examples/calc.lisp +++ b/examples/calc.lisp @@ -6,21 +6,29 @@ (in-package #:argot.examples.calc) (deflanguage calc (:documentation "A calculator language") - (<calc> :-> (:or - (:seq <subexpr> (:eof)) - (:seq <value> (:eof)) - (:seq <unop> (:eof)) - (:seq <binop> (:eof))) - :then car) - (<expr> :-> (:or <subexpr> <value> <unop> <binop>)) - (<subexpr> :-> (:item) - :if listp - :then (argot:parse calc <subexpr>)) - (<value> :-> (:item) :if numberp) - (<binop> :-> (:seq (:@ lhs <expr>) - (:@ rhs (:+ (:seq (:or= + - / * ^ %) <expr>)))) - :then (expand-binop lhs rhs)) - (<unop> :-> (:seq (:or= sin cos tan -) <expr>))) + (<calc> + :match (:or + (:seq <subexpr> (:eof)) + (:seq <value> (:eof)) + (:seq <unop> (:eof)) + (:seq <binop> (:eof))) + :then car) + (<expr> + :match (:or <subexpr> <value> <unop> <binop>)) + (<subexpr> + :match (:item) + :if listp + :then (argot:parse calc <subexpr>)) + (<value> + :match (:item) + :if numberp) + (<binop> + :match (:seq + (:@ lhs <expr>) + (:@ rhs (:+ (:seq (:or= + - / * ^ %) <expr>)))) + :then (expand-binop lhs rhs)) + (<unop> + :match (:seq (:or= sin cos tan -) <expr>))) (defun lassoc? (op) |