* Argot: A System For Grammar-Driven Macros The ~argot~ system provides a macro-defining-macro called ~deflanguage~. The ~deflanguage~ macro accepts a context-free grammar, augmented with parse handlers, and defines a macro whose body is parsed and expanded according to that augmented grammar. ** A brief tour In ~/examples/calc.lisp~ you see the following ~deflanguage~: #+begin_src lisp (deflanguage calc (:documentation "A calculator language") ( :match (:or (:seq (:eof)) (:seq (:eof)) (:seq (:eof)) (:seq (:eof))) :then car) ( :match (:or )) ( :match (:{} calc)) ( :match (:item) :if numberp) ( :match (:seq (:@ lhs ) (:@ rhs (:+ (:seq (:or= + - / * ^ %) )))) :then (expand-binop lhs rhs)) ( :match (:seq (:or= sin cos tan -) ))) #+end_src This defines a cacluator language that you can use like so: #+begin_src lisp > (calc 1) 1 > (calc 1 + 2 + 3) 6 > (calc 1 + 2 * 3) 7 > (calc (1 + 2) * 3) 9 > (calc (1 + 2) * 3 + 1) 10 > (calc (1 + 2) * (3 + 1)) 12 > (calc 2 ^ (2 * (1 + 1))) 16 #+end_src The symbol ~calc~ also has a function docstring. If you are in slime, you can evoke ~M-x slime-documentation~ with your cursor over the ~calc~ symbol and see this: #+begin_src Documentation for the symbol CALC: Function: Arglist: (&BODY TOKENS) A calculator language ::= ( ::EOF:: | ::EOF:: | ::EOF:: | ::EOF::) ::= ( | | | ) ::= {CALC} ::= ::TOKEN:: ::= ('+' | '-' | '/' | '*' | '^' | '%') ⁤+ ::= ('SIN' | 'COS' | 'TAN' | '-') KEY: ::TOKEN:: Any ole token ::EOF:: Explicitly match the end of the input {GRAMMAR} Parse a sublist of tokens with GRAMMAR (a|b|..) One of the alternavites a b ... PATTERN+ One or more PATTERN PATTERN* Zero or more PATTERN A nonterminal symbol - naming a parse rule [OPT] Zero or one of OPT #+end_src ** User Guide