A more logical excuse for fpl is that at some point jest needs to be rewritten in jest, and if I use existing parser generator languages, I'm going to be tied to c or whatever language those parser generators generate. So I need something which will generate jest (unless I want to code the parser by hand, which is possible).
Valid directives are:
@comment_style
@default_action
@default_main
@post_parse
@produces
(required) - tells the parser
generator what type is to be returned from code generation
rules and from the generated parser itself. For c++, the
type must be to_string compatible - if it's not already
(and I'm really sorry about this), you must specify a
to_string()
function in a
code block prior to any rules.
For example:
+{
std::string to_string(const &my_type x) {
return x.convert_to_string_or_whatever();
}
}+
@separator
Production rules are of the form:
<exprs to match> -> <production name> { <code> } or <exprs to match> -> <production name> ;
"xxx"
or 'yyy'
)
The first 2 effectively specify scan tokens. Single or double quotes are equivalent, and specify an exact match to look for. Regular expressions can be used to specify The third case specifies
Expressions may be followed directly by (no space) one of *, +, or ? to mean 0-or-more, 1-or-more, or 0-or-1 respectively.
# a very basic calculator @produces int aexpr '+' mexpr -> aexpr +{ return arg_0 + arg_2; }+ aexpr '-' mexpr -> aexpr +{ return arg_0 - arg_2; }+ mexpr -> aexpr ; mexpr '*' term -> mexpr +{ return arg_0 * arg_2; }+ mexpr '/' term -> mexpr +{ return arg_0 / arg_2; }+ mexpr '%' term -> mexpr +{ return arg_0 % arg_2; }+ term -> mexpr ; '-' term -> term +{ return -arg_1; }+ '(' aexpr ')' -> term +{ return arg_1; }+ /[0-9]+/ -> term +{ return std::stoi(arg_0); }+
/[1-3]/
and
/[123]/
are equivalent or that
/[a-z]+/
and /[a-f]+/ can both
match some of the same strings.
In practice this mostly does not matter, but I recommend you
keep your regexes tidy and minimal to avoid any surprises.