First, I'd agree with @Arthur concerning the use of Instaparse for generating your grammer.
The next step is to write a function which transform your grammar into Clojure data structures which represent code.
For example, if the grammar parses to
[:S [:EXPR [:WSK "ROC"] [:OpA ">"] [:NUM "100"]] :>> [:FCT "BUY"]] ; "ROC > 100 << BUY"
your function needs to take the appropriate parts and translate them into the corresponding code. The expression would probably be parsed into a (> (ROC) 100)
for example, though it's hard to tell without example inputs and expected outputs.
Generating the functions is just like normal Clojure data manipulation. Take the result of the parser, turn it into code. Then use that generated code in a macro. Here's a simplified example for working with just what this example needs to handle.
(defn parse-expr [expr]
(let [[_ [part1-type part1-val] [part2-type part2-val] [part3-type part3-val]] expr]
(if (and (= :WSK part1-type) (= :OpA part2-type) (= :NUM part3-type))
(let [wsk (variable part1-val)
opa (variable part2-val)
num (Integer/valueOf part3-val)]
(list opa (list wsk) num)))))
(defmacro generate-funcs [parse-tree]
(let [[_ expr _ [_ fact]] parse-tree
expr (parse-expr expr)
fact (symbol fact)]
`(fn [] (if ~expr (str ~fact) ()))))
Try running
(parse-expr [:EXPR [:WSK "B"] [:OpA "<"] [:NUM "1"]])
and
(macroexpand-1 '(generate-funcs [:S [:EXPR [:WSK "B"] [:OpA "<"] [:NUM "1"]] :>> [:FCT "b"]]))
to get a better grasp of what I'm referring to for translating the data into code.