step: generalize grammar
This commit is contained in:
parent
e5913ce78f
commit
007741dad0
18
src/mumble.c
18
src/mumble.c
|
@ -179,19 +179,21 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
/* Create Some Parsers */
|
/* Create Some Parsers */
|
||||||
mpc_parser_t* Number = mpc_new("number");
|
mpc_parser_t* Number = mpc_new("number");
|
||||||
mpc_parser_t* Operator = mpc_new("operator");
|
mpc_parser_t* Symbol = mpc_new("symbol");
|
||||||
|
mpc_parser_t* Sexpr = mpc_new("sexpr");
|
||||||
mpc_parser_t* Expr = mpc_new("expr");
|
mpc_parser_t* Expr = mpc_new("expr");
|
||||||
mpc_parser_t* Mumble = mpc_new("mumble");
|
mpc_parser_t* Mumble = mpc_new("mumble");
|
||||||
|
|
||||||
/* Define them with the following Language */
|
/* Define them with the following Language */
|
||||||
mpca_lang(MPCA_LANG_DEFAULT,
|
mpca_lang(MPCA_LANG_DEFAULT,
|
||||||
" \
|
" \
|
||||||
number : /-?[0-9]+/ ; \
|
number : /-?[0-9]+/ ; \
|
||||||
operator : '+' | '-' | '*' | '/' ; \
|
symbol : '+' | '-' | '*' | '/' ; \
|
||||||
expr : <number> | '(' <operator> <expr>+ ')' ; \
|
sexpr : '(' <expr>* ')' ; \
|
||||||
mumble : /^/ <operator> <expr>+ | <expr>/$/ ; \
|
expr : <number> | <symbol> | <sexpr> ; \
|
||||||
|
mumble : /^/ <expr>* /$/ ; \
|
||||||
",
|
",
|
||||||
Number, Operator, Expr, Mumble);
|
Number, Symbol, Sexpr, Expr, Mumble);
|
||||||
|
|
||||||
|
|
||||||
// Initialize a repl
|
// Initialize a repl
|
||||||
|
@ -230,7 +232,7 @@ int main(int argc, char** argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Undefine and Delete our Parsers */
|
/* Undefine and Delete our Parsers */
|
||||||
mpc_cleanup(4, Number, Operator, Expr, Mumble);
|
mpc_cleanup(4, Number, Symbol, Sexpr, Expr, Mumble);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user