I'm trying to implement a small description language for user scripting in an application. Basically users describe how objects are created from other objects. (Not really a programming language). I could use JSON as well (but it would be more verbose).
I use leex and yecc and i have a decent parse tree. Say it is something like this :
{def,double, %% function name double
[{x}], %% list of input names
%% return expression, in this case {Operator, Operand1, Operand2}
{'*',{var,x},{number,2}}
}.
With this tree, i would like to build something like this:
double(State) ->
_Var1 = some_app:get_input(State,x),
_Var1 * 2.
But i don't know where to start. I can read the tree at runtime and build funs but i really want to learn how to compile (and hope better performance).
Should i transform my parse tree to Erlang AST and then compile erlang module ?
Thanks.
So, the classic workflow is this :
leex
yecc
cerl
compile
module. It can yield beam binaries to load as a module or create a.beam
fileAs an alternative to
leex/yecc
(LALR parser) we can use neotoma which works with PEG grammars. It depends on what you have to parse. There i needed left recursion and didn't want to handle whitespace.As a target, the EVM (BEAM) seems quite easy. Compiling ends up to simply translate from one language to another and Core Erlang is a very simple language but still expressive.