From 9cbf364a463acf6fe8a7e69d19f1df864a80c851 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Fri, 17 Apr 2015 23:10:47 +0200 Subject: Add support for character terminal group rules --- src/lex.cpp | 1 + src/parse.cpp | 415 +++++++++++++++++++++++++++++++++++----------------------- src/parse.hpp | 2 +- src/parse.y | 21 ++- 4 files changed, 259 insertions(+), 180 deletions(-) diff --git a/src/lex.cpp b/src/lex.cpp index 29bdd4e..16b3eb9 100644 --- a/src/lex.cpp +++ b/src/lex.cpp @@ -309,6 +309,7 @@ int lex_t::lex(parse_token_value_t *value) { case '=': case '(': case ')': + case '.': token = current(); next(true); consume(false); diff --git a/src/parse.cpp b/src/parse.cpp index bad9e24..a0ce970 100644 --- a/src/parse.cpp +++ b/src/parse.cpp @@ -13,10 +13,6 @@ static inline void free_symbol(solar::symbol_t *v) { delete v; } -static inline void free_rule(solar::rule_t *v) { - delete v; -} - static inline void free_rhs(rhs_t *v) { delete v; } @@ -26,7 +22,6 @@ typedef union parse_symbol_value { parse_token_value_t token; std::string *symbol_action; rhs_t *symbol_rhs; - solar::rule_t *symbol_rule; solar::symbol_t *symbol_symbol; solar::symbol_t *symbol_term; std::string *symbol_varname; @@ -79,11 +74,17 @@ static inline void parse_reduce_8(std::string *type, std::string *name, __attrib grammar->extra_args.push_back(std::make_pair(*type, *name)); } -static inline void parse_reduce_9(solar::rule_t *rule, __attribute__((unused)) solar::grammar_t *grammar) { - grammar->add_rule(*rule); +static inline void parse_reduce_9(std::string *lhs, rhs_t *rhs, std::string *action, __attribute__((unused)) solar::grammar_t *grammar) { + grammar->add_rule({solar::item_t(*lhs, rhs->first), rhs->second, *action}); } -static inline solar::rule_t * parse_reduce_10(std::string *lhs, rhs_t *rhs, std::string *action, __attribute__((unused)) solar::grammar_t *grammar) {return new solar::rule_t {solar::item_t(*lhs, rhs->first), rhs->second, *action};} +static inline void parse_reduce_10(std::string *lhs, unsigned char c1, unsigned char c2, __attribute__((unused)) solar::grammar_t *grammar) { + vars_t vars; + vars.emplace_back(); + + for (unsigned int c = c1; c <= c2; c++) + grammar->add_rule({solar::item_t(*lhs, {solar::symbol_t::make_char(c)}), vars, std::string()}); +} static inline rhs_t * parse_reduce_11(__attribute__((unused)) solar::grammar_t *grammar) {return new rhs_t();} @@ -129,7 +130,7 @@ static inline solar::symbol_t * parse_reduce_20(solar::symbol_t *v, __attribute_ static inline solar::symbol_t * parse_reduce_21(std::string *v, __attribute__((unused)) solar::grammar_t *grammar) {return new solar::symbol_t(solar::symbol_t::make_term(*v));} -static inline solar::symbol_t * parse_reduce_22(char v, __attribute__((unused)) solar::grammar_t *grammar) {return new solar::symbol_t(solar::symbol_t::make_char(v));} +static inline solar::symbol_t * parse_reduce_22(unsigned char v, __attribute__((unused)) solar::grammar_t *grammar) {return new solar::symbol_t(solar::symbol_t::make_char(v));} static inline std::string * parse_reduce_23(std::string *v, __attribute__((unused)) solar::grammar_t *grammar) {return v;} @@ -154,11 +155,11 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus return 0; case TOK_SYMBOL: - parser->stack[++parser->top].state = 4; + parser->stack[++parser->top].state = 3; return 1; case '%': - parser->stack[++parser->top].state = 5; + parser->stack[++parser->top].state = 4; return 1; default: @@ -175,19 +176,9 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus break; case 3: - switch (token) { - default: - parser->top -= 1; - parse_reduce_9(parser->stack[parser->top + 0].value.symbol_rule, grammar); - free_rule(parser->stack[parser->top + 0].value.symbol_rule); - parser->stack[++parser->top].state = 2; - } - break; - - case 4: switch (token) { case '|': - parser->stack[++parser->top].state = 6; + parser->stack[++parser->top].state = 5; return 1; default: @@ -195,26 +186,26 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 5: + case 4: switch (token) { case 'd': - parser->stack[++parser->top].state = 7; + parser->stack[++parser->top].state = 6; return 1; case 'e': - parser->stack[++parser->top].state = 8; + parser->stack[++parser->top].state = 7; return 1; case 'h': - parser->stack[++parser->top].state = 9; + parser->stack[++parser->top].state = 8; return 1; case 's': - parser->stack[++parser->top].state = 10; + parser->stack[++parser->top].state = 9; return 1; case 't': - parser->stack[++parser->top].state = 11; + parser->stack[++parser->top].state = 10; return 1; default: @@ -222,10 +213,10 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 6: + case 5: switch (token) { case '=': - parser->stack[++parser->top].state = 12; + parser->stack[++parser->top].state = 11; return 1; default: @@ -233,10 +224,10 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 7: + case 6: switch (token) { case 'e': - parser->stack[++parser->top].state = 13; + parser->stack[++parser->top].state = 12; return 1; default: @@ -244,10 +235,10 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 8: + case 7: switch (token) { case 'x': - parser->stack[++parser->top].state = 14; + parser->stack[++parser->top].state = 13; return 1; default: @@ -255,10 +246,10 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 9: + case 8: switch (token) { case 'e': - parser->stack[++parser->top].state = 15; + parser->stack[++parser->top].state = 14; return 1; default: @@ -266,10 +257,10 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 10: + case 9: switch (token) { case 'o': - parser->stack[++parser->top].state = 16; + parser->stack[++parser->top].state = 15; return 1; default: @@ -277,10 +268,10 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 11: + case 10: switch (token) { case 'y': - parser->stack[++parser->top].state = 17; + parser->stack[++parser->top].state = 16; return 1; default: @@ -288,16 +279,20 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 12: + case 11: switch (token) { + case '(': + parser->stack[++parser->top].state = 18; + return 1; + default: result.symbol_rhs = parse_reduce_11(grammar); parser->stack[parser->top].value.symbol_rhs = result.symbol_rhs; - parser->stack[++parser->top].state = 18; + parser->stack[++parser->top].state = 17; } break; - case 13: + case 12: switch (token) { case 's': parser->stack[++parser->top].state = 19; @@ -308,7 +303,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 14: + case 13: switch (token) { case 't': parser->stack[++parser->top].state = 20; @@ -319,7 +314,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 15: + case 14: switch (token) { case 'a': parser->stack[++parser->top].state = 21; @@ -330,7 +325,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 16: + case 15: switch (token) { case 'u': parser->stack[++parser->top].state = 22; @@ -341,7 +336,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 17: + case 16: switch (token) { case 'p': parser->stack[++parser->top].state = 23; @@ -352,7 +347,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 18: + case 17: switch (token) { case TOK_BLOCK: parser->stack[++parser->top].state = 27; @@ -387,10 +382,21 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; + case 18: + switch (token) { + case TOK_CHAR: + parser->stack[++parser->top].state = 34; + return 1; + + default: + return -1; + } + break; + case 19: switch (token) { case 't': - parser->stack[++parser->top].state = 34; + parser->stack[++parser->top].state = 35; return 1; default: @@ -401,7 +407,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus case 20: switch (token) { case 'r': - parser->stack[++parser->top].state = 35; + parser->stack[++parser->top].state = 36; return 1; default: @@ -412,7 +418,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus case 21: switch (token) { case 'd': - parser->stack[++parser->top].state = 36; + parser->stack[++parser->top].state = 37; return 1; default: @@ -423,7 +429,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus case 22: switch (token) { case 'r': - parser->stack[++parser->top].state = 37; + parser->stack[++parser->top].state = 38; return 1; default: @@ -434,7 +440,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus case 23: switch (token) { case 'e': - parser->stack[++parser->top].state = 38; + parser->stack[++parser->top].state = 39; return 1; default: @@ -446,19 +452,18 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus switch (token) { default: parser->top -= 5; - result.symbol_rule = parse_reduce_10(parser->stack[parser->top + 0].value.token.str, parser->stack[parser->top + 3].value.symbol_rhs, parser->stack[parser->top + 4].value.symbol_action, grammar); + parse_reduce_9(parser->stack[parser->top + 0].value.token.str, parser->stack[parser->top + 3].value.symbol_rhs, parser->stack[parser->top + 4].value.symbol_action, grammar); free_string(parser->stack[parser->top + 0].value.token.str); free_rhs(parser->stack[parser->top + 3].value.symbol_rhs); free_string(parser->stack[parser->top + 4].value.symbol_action); - parser->stack[parser->top].value.symbol_rule = result.symbol_rule; - parser->stack[++parser->top].state = 3; + parser->stack[++parser->top].state = 2; } break; case 25: switch (token) { case '(': - parser->stack[++parser->top].state = 39; + parser->stack[++parser->top].state = 40; return 1; default: @@ -466,7 +471,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus result.symbol_rhs = parse_reduce_12(parser->stack[parser->top + 0].value.symbol_rhs, parser->stack[parser->top + 1].value.symbol_symbol, grammar); free_symbol(parser->stack[parser->top + 1].value.symbol_symbol); parser->stack[parser->top].value.symbol_rhs = result.symbol_rhs; - parser->stack[++parser->top].state = 18; + parser->stack[++parser->top].state = 17; } break; @@ -477,12 +482,12 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus result.symbol_symbol = parse_reduce_20(parser->stack[parser->top + 0].value.symbol_term, grammar); parser->stack[parser->top].value.symbol_symbol = result.symbol_symbol; switch (parser->stack[parser->top].state) { - case 18: + case 17: parser->stack[++parser->top].state = 25; break; - case 68: - parser->stack[++parser->top].state = 70; + case 75: + parser->stack[++parser->top].state = 77; break; } @@ -506,13 +511,13 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus result.symbol_term = parse_reduce_22(parser->stack[parser->top + 0].value.token.c, grammar); parser->stack[parser->top].value.symbol_term = result.symbol_term; switch (parser->stack[parser->top].state) { - case 18: - case 68: + case 17: + case 75: parser->stack[++parser->top].state = 26; break; - case 38: - parser->stack[++parser->top].state = 44; + case 39: + parser->stack[++parser->top].state = 46; break; } @@ -537,7 +542,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus result.symbol_rhs = parse_reduce_15(parser->stack[parser->top + 0].value.symbol_rhs, parser->stack[parser->top + 1].value.token.str, grammar); free_string(parser->stack[parser->top + 1].value.token.str); parser->stack[parser->top].value.symbol_rhs = result.symbol_rhs; - parser->stack[++parser->top].state = 18; + parser->stack[++parser->top].state = 17; } break; @@ -549,12 +554,12 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus free_string(parser->stack[parser->top + 0].value.token.str); parser->stack[parser->top].value.symbol_symbol = result.symbol_symbol; switch (parser->stack[parser->top].state) { - case 18: + case 17: parser->stack[++parser->top].state = 25; break; - case 68: - parser->stack[++parser->top].state = 70; + case 75: + parser->stack[++parser->top].state = 77; break; } @@ -569,13 +574,13 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus free_string(parser->stack[parser->top + 0].value.token.str); parser->stack[parser->top].value.symbol_term = result.symbol_term; switch (parser->stack[parser->top].state) { - case 18: - case 68: + case 17: + case 75: parser->stack[++parser->top].state = 26; break; - case 38: - parser->stack[++parser->top].state = 44; + case 39: + parser->stack[++parser->top].state = 46; break; } @@ -594,8 +599,8 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus case 34: switch (token) { - case 'r': - parser->stack[++parser->top].state = 40; + case '.': + parser->stack[++parser->top].state = 41; return 1; default: @@ -605,8 +610,8 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus case 35: switch (token) { - case 'a': - parser->stack[++parser->top].state = 41; + case 'r': + parser->stack[++parser->top].state = 42; return 1; default: @@ -616,8 +621,8 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus case 36: switch (token) { - case 'e': - parser->stack[++parser->top].state = 42; + case 'a': + parser->stack[++parser->top].state = 43; return 1; default: @@ -627,8 +632,8 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus case 37: switch (token) { - case 'c': - parser->stack[++parser->top].state = 43; + case 'e': + parser->stack[++parser->top].state = 44; return 1; default: @@ -637,6 +642,17 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus break; case 38: + switch (token) { + case 'c': + parser->stack[++parser->top].state = 45; + return 1; + + default: + return -1; + } + break; + + case 39: switch (token) { case TOK_CHAR: parser->stack[++parser->top].state = 28; @@ -647,7 +663,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus return 1; case TOK_SYMBOL: - parser->stack[++parser->top].state = 45; + parser->stack[++parser->top].state = 47; return 1; default: @@ -655,18 +671,18 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 39: + case 40: switch (token) { case TOK_SYMBOL: - parser->stack[++parser->top].state = 47; + parser->stack[++parser->top].state = 49; return 1; case TOK_SYMBOL_UC: - parser->stack[++parser->top].state = 48; + parser->stack[++parser->top].state = 50; return 1; case '=': - parser->stack[++parser->top].state = 49; + parser->stack[++parser->top].state = 51; return 1; default: @@ -674,10 +690,21 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 40: + case 41: + switch (token) { + case '.': + parser->stack[++parser->top].state = 52; + return 1; + + default: + return -1; + } + break; + + case 42: switch (token) { case 'u': - parser->stack[++parser->top].state = 50; + parser->stack[++parser->top].state = 53; return 1; default: @@ -685,10 +712,10 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 41: + case 43: switch (token) { case '_': - parser->stack[++parser->top].state = 51; + parser->stack[++parser->top].state = 54; return 1; default: @@ -696,10 +723,10 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 42: + case 44: switch (token) { case 'r': - parser->stack[++parser->top].state = 52; + parser->stack[++parser->top].state = 55; return 1; default: @@ -707,10 +734,10 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 43: + case 45: switch (token) { case 'e': - parser->stack[++parser->top].state = 53; + parser->stack[++parser->top].state = 56; return 1; default: @@ -718,10 +745,10 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 44: + case 46: switch (token) { case TOK_BLOCK: - parser->stack[++parser->top].state = 54; + parser->stack[++parser->top].state = 57; return 1; default: @@ -729,10 +756,10 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 45: + case 47: switch (token) { case TOK_BLOCK: - parser->stack[++parser->top].state = 55; + parser->stack[++parser->top].state = 58; return 1; default: @@ -740,10 +767,10 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 46: + case 48: switch (token) { case ')': - parser->stack[++parser->top].state = 56; + parser->stack[++parser->top].state = 59; return 1; default: @@ -751,76 +778,76 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 47: + case 49: switch (token) { default: parser->top -= 1; result.symbol_varname = parse_reduce_24(parser->stack[parser->top + 0].value.token.str, grammar); parser->stack[parser->top].value.symbol_varname = result.symbol_varname; switch (parser->stack[parser->top].state) { - case 39: - parser->stack[++parser->top].state = 46; + case 40: + parser->stack[++parser->top].state = 48; break; - case 49: - parser->stack[++parser->top].state = 57; + case 51: + parser->stack[++parser->top].state = 60; break; - case 54: - parser->stack[++parser->top].state = 62; + case 57: + parser->stack[++parser->top].state = 66; break; - case 69: - parser->stack[++parser->top].state = 71; + case 76: + parser->stack[++parser->top].state = 78; break; - case 70: - parser->stack[++parser->top].state = 72; + case 77: + parser->stack[++parser->top].state = 79; break; } } break; - case 48: + case 50: switch (token) { default: parser->top -= 1; result.symbol_varname = parse_reduce_23(parser->stack[parser->top + 0].value.token.str, grammar); parser->stack[parser->top].value.symbol_varname = result.symbol_varname; switch (parser->stack[parser->top].state) { - case 39: - parser->stack[++parser->top].state = 46; + case 40: + parser->stack[++parser->top].state = 48; break; - case 49: - parser->stack[++parser->top].state = 57; + case 51: + parser->stack[++parser->top].state = 60; break; - case 54: - parser->stack[++parser->top].state = 62; + case 57: + parser->stack[++parser->top].state = 66; break; - case 69: - parser->stack[++parser->top].state = 71; + case 76: + parser->stack[++parser->top].state = 78; break; - case 70: - parser->stack[++parser->top].state = 72; + case 77: + parser->stack[++parser->top].state = 79; break; } } break; - case 49: + case 51: switch (token) { case TOK_SYMBOL: - parser->stack[++parser->top].state = 47; + parser->stack[++parser->top].state = 49; return 1; case TOK_SYMBOL_UC: - parser->stack[++parser->top].state = 48; + parser->stack[++parser->top].state = 50; return 1; default: @@ -828,10 +855,21 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 50: + case 52: + switch (token) { + case '.': + parser->stack[++parser->top].state = 61; + return 1; + + default: + return -1; + } + break; + + case 53: switch (token) { case 'c': - parser->stack[++parser->top].state = 58; + parser->stack[++parser->top].state = 62; return 1; default: @@ -839,10 +877,10 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 51: + case 54: switch (token) { case 'a': - parser->stack[++parser->top].state = 59; + parser->stack[++parser->top].state = 63; return 1; default: @@ -850,10 +888,10 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 52: + case 55: switch (token) { case TOK_BLOCK: - parser->stack[++parser->top].state = 60; + parser->stack[++parser->top].state = 64; return 1; default: @@ -861,10 +899,10 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 53: + case 56: switch (token) { case TOK_BLOCK: - parser->stack[++parser->top].state = 61; + parser->stack[++parser->top].state = 65; return 1; default: @@ -872,14 +910,14 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 54: + case 57: switch (token) { case TOK_SYMBOL: - parser->stack[++parser->top].state = 47; + parser->stack[++parser->top].state = 49; return 1; case TOK_SYMBOL_UC: - parser->stack[++parser->top].state = 48; + parser->stack[++parser->top].state = 50; return 1; default: @@ -887,7 +925,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 55: + case 58: switch (token) { default: parser->top -= 7; @@ -898,7 +936,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 56: + case 59: switch (token) { default: parser->top -= 5; @@ -906,14 +944,14 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus free_symbol(parser->stack[parser->top + 1].value.symbol_symbol); free_string(parser->stack[parser->top + 3].value.symbol_varname); parser->stack[parser->top].value.symbol_rhs = result.symbol_rhs; - parser->stack[++parser->top].state = 18; + parser->stack[++parser->top].state = 17; } break; - case 57: + case 60: switch (token) { case ')': - parser->stack[++parser->top].state = 63; + parser->stack[++parser->top].state = 67; return 1; default: @@ -921,10 +959,21 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 58: + case 61: + switch (token) { + case TOK_CHAR: + parser->stack[++parser->top].state = 68; + return 1; + + default: + return -1; + } + break; + + case 62: switch (token) { case 't': - parser->stack[++parser->top].state = 64; + parser->stack[++parser->top].state = 69; return 1; default: @@ -932,10 +981,10 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 59: + case 63: switch (token) { case 'r': - parser->stack[++parser->top].state = 65; + parser->stack[++parser->top].state = 70; return 1; default: @@ -943,7 +992,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 60: + case 64: switch (token) { default: parser->top -= 8; @@ -953,7 +1002,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 61: + case 65: switch (token) { default: parser->top -= 8; @@ -963,7 +1012,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 62: + case 66: switch (token) { default: parser->top -= 8; @@ -975,7 +1024,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 63: + case 67: switch (token) { default: parser->top -= 6; @@ -983,14 +1032,25 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus free_symbol(parser->stack[parser->top + 1].value.symbol_symbol); free_string(parser->stack[parser->top + 4].value.symbol_varname); parser->stack[parser->top].value.symbol_rhs = result.symbol_rhs; - parser->stack[++parser->top].state = 18; + parser->stack[++parser->top].state = 17; } break; - case 64: + case 68: + switch (token) { + case ')': + parser->stack[++parser->top].state = 71; + return 1; + + default: + return -1; + } + break; + + case 69: switch (token) { case 'o': - parser->stack[++parser->top].state = 66; + parser->stack[++parser->top].state = 72; return 1; default: @@ -998,10 +1058,10 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 65: + case 70: switch (token) { case 'g': - parser->stack[++parser->top].state = 67; + parser->stack[++parser->top].state = 73; return 1; default: @@ -1009,10 +1069,21 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 66: + case 71: + switch (token) { + case ';': + parser->stack[++parser->top].state = 74; + return 1; + + default: + return -1; + } + break; + + case 72: switch (token) { case 'r': - parser->stack[++parser->top].state = 68; + parser->stack[++parser->top].state = 75; return 1; default: @@ -1020,10 +1091,10 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 67: + case 73: switch (token) { case TOK_BLOCK: - parser->stack[++parser->top].state = 69; + parser->stack[++parser->top].state = 76; return 1; default: @@ -1031,7 +1102,17 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 68: + case 74: + switch (token) { + default: + parser->top -= 11; + parse_reduce_10(parser->stack[parser->top + 0].value.token.str, parser->stack[parser->top + 4].value.token.c, parser->stack[parser->top + 8].value.token.c, grammar); + free_string(parser->stack[parser->top + 0].value.token.str); + parser->stack[++parser->top].state = 2; + } + break; + + case 75: switch (token) { case TOK_CHAR: parser->stack[++parser->top].state = 28; @@ -1050,14 +1131,14 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 69: + case 76: switch (token) { case TOK_SYMBOL: - parser->stack[++parser->top].state = 47; + parser->stack[++parser->top].state = 49; return 1; case TOK_SYMBOL_UC: - parser->stack[++parser->top].state = 48; + parser->stack[++parser->top].state = 50; return 1; default: @@ -1065,14 +1146,14 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 70: + case 77: switch (token) { case TOK_SYMBOL: - parser->stack[++parser->top].state = 47; + parser->stack[++parser->top].state = 49; return 1; case TOK_SYMBOL_UC: - parser->stack[++parser->top].state = 48; + parser->stack[++parser->top].state = 50; return 1; default: @@ -1080,7 +1161,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 71: + case 78: switch (token) { default: parser->top -= 12; @@ -1091,7 +1172,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 72: + case 79: switch (token) { default: parser->top -= 13; diff --git a/src/parse.hpp b/src/parse.hpp index e080ceb..c9fa9ce 100644 --- a/src/parse.hpp +++ b/src/parse.hpp @@ -14,7 +14,7 @@ typedef enum parse_token { } parse_token_t; typedef struct parse_token_value { - char c; + unsigned char c; std::string *str; } parse_token_value_t; diff --git a/src/parse.y b/src/parse.y index 8d8a081..4fcba12 100644 --- a/src/parse.y +++ b/src/parse.y @@ -15,10 +15,6 @@ static inline void free_symbol(solar::symbol_t *v) { delete v; } -static inline void free_rule(solar::rule_t *v) { - delete v; -} - static inline void free_rhs(rhs_t *v) { delete v; } @@ -40,12 +36,9 @@ static inline void free_rhs(rhs_t *v) { %type STRING {std::string *} str %destructor STRING free_string -%type CHAR {char} c +%type CHAR {unsigned char} c -%type rule {solar::rule_t *} -%destructor rule free_rule - %type rhs {rhs_t *} %destructor rhs free_rhs @@ -93,13 +86,17 @@ directive |= "%extra_arg" BLOCK(type) varname(name) { grammar->extra_args.push_back(std::make_pair(*type, *name)); } -directive |= rule(rule) { - grammar->add_rule(*rule); +directive |= SYMBOL(lhs) "|=" rhs(rhs) action(action) { + grammar->add_rule({solar::item_t(*lhs, rhs->first), rhs->second, *action}); } +directive |= SYMBOL(lhs) "|=" '(' CHAR(c1) "..." CHAR(c2) ')' ';' { + vars_t vars; + vars.emplace_back(); -rule |= SYMBOL(lhs) "|=" rhs(rhs) action(action) - [new solar::rule_t {solar::item_t(*lhs, rhs->first), rhs->second, *action}] + for (unsigned int c = c1; c <= c2; c++) + grammar->add_rule({solar::item_t(*lhs, {solar::symbol_t::make_char(c)}), vars, std::string()}); +} rhs |= [new rhs_t()] -- cgit v1.2.3