From 007741dad0cb9db0e34c77f2b3c964e568ec0eda Mon Sep 17 00:00:00 2001 From: NunoSempere Date: Sun, 30 Apr 2023 23:58:31 -0400 Subject: [PATCH] step: generalize grammar --- src/mumble.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/mumble.c b/src/mumble.c index 6fb8eeb..102d010 100644 --- a/src/mumble.c +++ b/src/mumble.c @@ -179,19 +179,21 @@ int main(int argc, char** argv) /* Create Some Parsers */ 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* Mumble = mpc_new("mumble"); /* Define them with the following Language */ mpca_lang(MPCA_LANG_DEFAULT, - " \ - number : /-?[0-9]+/ ; \ - operator : '+' | '-' | '*' | '/' ; \ - expr : | '(' + ')' ; \ - mumble : /^/ + | /$/ ; \ + " \ + number : /-?[0-9]+/ ; \ + symbol : '+' | '-' | '*' | '/' ; \ + sexpr : '(' * ')' ; \ + expr : | | ; \ + mumble : /^/ * /$/ ; \ ", - Number, Operator, Expr, Mumble); + Number, Symbol, Sexpr, Expr, Mumble); // Initialize a repl @@ -230,7 +232,7 @@ int main(int argc, char** argv) } /* Undefine and Delete our Parsers */ - mpc_cleanup(4, Number, Operator, Expr, Mumble); + mpc_cleanup(4, Number, Symbol, Sexpr, Expr, Mumble); return 0; }