diff options
author | colin <colin@cicadas.surf> | 2023-07-29 09:19:39 -0700 |
---|---|---|
committer | colin <colin@cicadas.surf> | 2023-07-29 09:19:39 -0700 |
commit | e8dfcee463d771c21c513dea4af30c5c51a2525e (patch) | |
tree | 32b67d39f58783bb5f827344c53c0e33a00ae357 | |
parent | fbfa64ec69870d424d3f94bd87380efe565b64b5 (diff) |
more of the same
-rw-r--r-- | argot.lisp | 10 | ||||
-rw-r--r-- | examples/calc.lisp | 38 |
2 files changed, 28 insertions, 20 deletions
@@ -72,23 +72,23 @@ and it returns VAR in that case." (defun parse-rule-def (ruledef) (handler-case (ematch ruledef - ((guard (list lhs :-> pattern) + ((guard (list lhs :match pattern) (and (nonterminal? lhs) (pattern? pattern))) (list lhs pattern (collect-vars pattern) nil nil)) - ((guard (list lhs :-> pattern :if check) + ((guard (list lhs :match pattern :if check) (and (nonterminal? lhs) (pattern? pattern))) (list lhs pattern (collect-vars pattern) check nil)) - ((guard (list lhs :-> pattern :then action) + ((guard (list lhs :match pattern :then action) (and (nonterminal? lhs) (pattern? pattern))) (list lhs pattern (collect-vars pattern) nil action)) - ((guard (list lhs :-> pattern :then action :if check) + ((guard (list lhs :match pattern :then action :if check) (and (nonterminal? lhs) (pattern? pattern))) (list lhs pattern (collect-vars pattern) check action)) - ((guard (list lhs :-> pattern :if check :then action) + ((guard (list lhs :match pattern :if check :then action) (and (nonterminal? lhs) (pattern? pattern))) (list lhs pattern (collect-vars pattern) check action))) (trivia::match-error () 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) |