From: Michael D. Lowis Date: Tue, 19 Aug 2014 03:37:10 +0000 (-0400) Subject: reworked grammar for nicer tags, broke it instead :( X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=a5e87af4d57aba6f7bece6c49e22ea0a6e34f7f5;p=proto%2Fsclpl.git reworked grammar for nicer tags, broke it instead :( --- diff --git a/source/sclpl/grammar.c b/source/sclpl/grammar.c index e5f5506..3b1f391 100644 --- a/source/sclpl/grammar.c +++ b/source/sclpl/grammar.c @@ -2,25 +2,23 @@ const char Grammar[] = "" "replexpr : /[^\\n]*\\n/ ;" "" -"expr : '(' \"quote\" ')'" -" | '(' \"quasiquote\" ')'" -" | '(' \"unquote\" ')'" -" | '(' \"if\" ( )?')'" -" | '(' \"fn\" '(' ( )* ')' ( )+ ')'" -" | '(' \"def\" ')'" -" | '(' ( )* ')'" -" | /['`,]/ " -" | " -" ;" -"" -"atom : | | | | ;" -"" -"num : \"0b\" /[0-1]+/" -" | \"0o\" /[0-7]+/" -" | \"0d\" /[0-9]+/" -" | \"0x\" /[0-9a-fA-F]+/" -" | /[-+]?[0-9]+(\\.[0-9]+)?/" -" ;" +"expr : | | ;" +"" +"sexpr : '(' ( )* ')' ;" +"" +"qexpr : ('\\'' | '`' | ',') ;" +"" +"atom : | | | | | | ;" +"" +"int : /[-+]?[0-9]+/ ;" +"" +"float : /[-+]?[0-9]+\\.[0-9]+/ ;" +"" +"radixnum : \"0b\" /[0-1]+/" +" | \"0o\" /[0-7]+/" +" | \"0d\" /[0-9]+/" +" | \"0x\" /[0-9a-fA-F]+/" +" ;" "" "ch : '\\\\' (\"space\"|\"newline\"|\"return\"|\"tab\"|\"vtab\")" " | '\\\\' /./" diff --git a/source/sclpl/grammar.y b/source/sclpl/grammar.y index 3358a2a..2d1bc6e 100644 --- a/source/sclpl/grammar.y +++ b/source/sclpl/grammar.y @@ -1,25 +1,23 @@ replexpr : /[^\n]*\n/ ; -expr : '(' "quote" ')' - | '(' "quasiquote" ')' - | '(' "unquote" ')' - | '(' "if" ( )?')' - | '(' "fn" '(' ( )* ')' ( )+ ')' - | '(' "def" ')' - | '(' ( )* ')' - | /['`,]/ - | - ; - -atom : | | | | ; - -num : "0b" /[0-1]+/ - | "0o" /[0-7]+/ - | "0d" /[0-9]+/ - | "0x" /[0-9a-fA-F]+/ - | /[-+]?[0-9]+(\.[0-9]+)?/ - ; +expr : | | ; + +sexpr : '(' ( )* ')' ; + +qexpr : ('\'' | '`' | ',') ; + +atom : | | | | | | ; + +int : /[-+]?[0-9]+/ ; + +float : /[-+]?[0-9]+\.[0-9]+/ ; + +radixnum : "0b" /[0-1]+/ + | "0o" /[0-7]+/ + | "0d" /[0-9]+/ + | "0x" /[0-9a-fA-F]+/ + ; ch : '\\' ("space"|"newline"|"return"|"tab"|"vtab") | '\\' /./ diff --git a/source/sclpl/main.c b/source/sclpl/main.c index 520001d..71535b8 100644 --- a/source/sclpl/main.c +++ b/source/sclpl/main.c @@ -47,6 +47,8 @@ ast_t* format_expr_ast(mpc_ast_t* expr) { int main(int argc, char **argv) { mpc_parser_t* ReplExpr = mpc_new("replexpr"); mpc_parser_t* Expr = mpc_new("expr"); + mpc_parser_t* SExpr = mpc_new("sexpr"); + mpc_parser_t* QExpr = mpc_new("qexpr"); mpc_parser_t* Atom = mpc_new("atom"); mpc_parser_t* Num = mpc_new("num"); mpc_parser_t* Char = mpc_new("ch"); @@ -55,7 +57,7 @@ int main(int argc, char **argv) { mpc_parser_t* Var = mpc_new("var"); mpc_parser_t* WS = mpc_new("ws"); mpca_lang(MPCA_LANG_WHITESPACE_SENSITIVE, Grammar, - ReplExpr, Expr, Atom, Num, Char, String, Bool, Var, WS, NULL); + ReplExpr, Expr, SExpr, QExpr, Atom, Num, Char, String, Bool, Var, WS, NULL); while(!feof(stdin)) { mpc_result_t r; printf(":> "); @@ -70,6 +72,6 @@ int main(int argc, char **argv) { while('\n' != fgetc(stdin)){} } } - mpc_cleanup(9, ReplExpr, Expr, Atom, Num, Char, String, Bool, Var, WS); + mpc_cleanup(11, ReplExpr, Expr, SExpr, QExpr, Atom, Num, Char, String, Bool, Var, WS); return 0; }