A rex version of parsing (2)
// parse function for auxiliary V, rules V -> a | b | c

V([]) => [FAILURE, []];                                   // no input

V([c | chars]) => isVar(c) ? [mkTree(c), chars];          // variable

V([c | chars]) => [FAILURE, [c | chars]];                 // not a variable


// auxiliary functions

FAILURE = "failure";
VARS = ['a', 'b', 'c'];

isVar(char) = member(char, VARS);

failed(result) = result == FAILURE;

mkTree(Var) = Var;
mkTree(Op, Tree1, Tree2) = [Op, Tree1, Tree2];

parse(string) = A(explode(string));