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: @@ -176,20 +177,37 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus case 3: switch (token) { + case '|': + parser->stack[++parser->top].state = 5; + return 1; + 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; + return -1; } break; case 4: switch (token) { - case '|': + case 'd': parser->stack[++parser->top].state = 6; return 1; + case 'e': + parser->stack[++parser->top].state = 7; + return 1; + + case 'h': + parser->stack[++parser->top].state = 8; + return 1; + + case 's': + parser->stack[++parser->top].state = 9; + return 1; + + case 't': + parser->stack[++parser->top].state = 10; + return 1; + default: return -1; } @@ -197,23 +215,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus case 5: switch (token) { - case 'd': - parser->stack[++parser->top].state = 7; - return 1; - - case 'e': - parser->stack[++parser->top].state = 8; - return 1; - - case 'h': - parser->stack[++parser->top].state = 9; - return 1; - - case 's': - parser->stack[++parser->top].state = 10; - return 1; - - case 't': + case '=': parser->stack[++parser->top].state = 11; return 1; @@ -224,7 +226,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus case 6: switch (token) { - case '=': + case 'e': parser->stack[++parser->top].state = 12; return 1; @@ -235,7 +237,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus case 7: switch (token) { - case 'e': + case 'x': parser->stack[++parser->top].state = 13; return 1; @@ -246,7 +248,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus case 8: switch (token) { - case 'x': + case 'e': parser->stack[++parser->top].state = 14; return 1; @@ -257,7 +259,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus case 9: switch (token) { - case 'e': + case 'o': parser->stack[++parser->top].state = 15; return 1; @@ -268,7 +270,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus case 10: switch (token) { - case 'o': + case 'y': parser->stack[++parser->top].state = 16; return 1; @@ -279,25 +281,18 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus case 11: switch (token) { - case 'y': - parser->stack[++parser->top].state = 17; + case '(': + parser->stack[++parser->top].state = 18; return 1; default: - return -1; + result.symbol_rhs = parse_reduce_11(grammar); + parser->stack[parser->top].value.symbol_rhs = result.symbol_rhs; + parser->stack[++parser->top].state = 17; } break; case 12: - switch (token) { - default: - result.symbol_rhs = parse_reduce_11(grammar); - parser->stack[parser->top].value.symbol_rhs = result.symbol_rhs; - parser->stack[++parser->top].state = 18; - } - break; - - case 13: 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: @@ -638,15 +643,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus case 38: switch (token) { - case TOK_CHAR: - parser->stack[++parser->top].state = 28; - return 1; - - case TOK_SYMBOL_UC: - parser->stack[++parser->top].state = 32; - return 1; - - case TOK_SYMBOL: + case 'c': parser->stack[++parser->top].state = 45; return 1; @@ -657,16 +654,16 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus case 39: switch (token) { - case TOK_SYMBOL: - parser->stack[++parser->top].state = 47; + case TOK_CHAR: + parser->stack[++parser->top].state = 28; return 1; case TOK_SYMBOL_UC: - parser->stack[++parser->top].state = 48; + parser->stack[++parser->top].state = 32; return 1; - case '=': - parser->stack[++parser->top].state = 49; + case TOK_SYMBOL: + parser->stack[++parser->top].state = 47; return 1; default: @@ -676,10 +673,18 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus case 40: switch (token) { - case 'u': + case TOK_SYMBOL: + parser->stack[++parser->top].state = 49; + return 1; + + case TOK_SYMBOL_UC: parser->stack[++parser->top].state = 50; return 1; + case '=': + parser->stack[++parser->top].state = 51; + return 1; + default: return -1; } @@ -687,8 +692,8 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus case 41: switch (token) { - case '_': - parser->stack[++parser->top].state = 51; + case '.': + parser->stack[++parser->top].state = 52; return 1; default: @@ -698,8 +703,8 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus case 42: switch (token) { - case 'r': - parser->stack[++parser->top].state = 52; + case 'u': + parser->stack[++parser->top].state = 53; return 1; default: @@ -709,8 +714,8 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus case 43: switch (token) { - case 'e': - parser->stack[++parser->top].state = 53; + case '_': + parser->stack[++parser->top].state = 54; return 1; default: @@ -720,8 +725,8 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus case 44: switch (token) { - case TOK_BLOCK: - parser->stack[++parser->top].state = 54; + case 'r': + parser->stack[++parser->top].state = 55; return 1; default: @@ -731,8 +736,8 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus case 45: switch (token) { - case TOK_BLOCK: - parser->stack[++parser->top].state = 55; + case 'e': + parser->stack[++parser->top].state = 56; return 1; default: @@ -742,8 +747,8 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus case 46: switch (token) { - case ')': - parser->stack[++parser->top].state = 56; + case TOK_BLOCK: + parser->stack[++parser->top].state = 57; return 1; default: @@ -753,84 +758,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus case 47: 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; - break; - - case 49: - parser->stack[++parser->top].state = 57; - break; - - case 54: - parser->stack[++parser->top].state = 62; - break; - - case 69: - parser->stack[++parser->top].state = 71; - break; - - case 70: - parser->stack[++parser->top].state = 72; - break; - - } - } - break; - - case 48: - 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; - break; - - case 49: - parser->stack[++parser->top].state = 57; - break; - - case 54: - parser->stack[++parser->top].state = 62; - break; - - case 69: - parser->stack[++parser->top].state = 71; - break; - - case 70: - parser->stack[++parser->top].state = 72; - break; - - } - } - break; - - case 49: - switch (token) { - case TOK_SYMBOL: - parser->stack[++parser->top].state = 47; - return 1; - - case TOK_SYMBOL_UC: - parser->stack[++parser->top].state = 48; - return 1; - - default: - return -1; - } - break; - - case 50: - switch (token) { - case 'c': + case TOK_BLOCK: parser->stack[++parser->top].state = 58; return 1; @@ -839,10 +767,87 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; + case 48: + switch (token) { + case ')': + parser->stack[++parser->top].state = 59; + return 1; + + default: + return -1; + } + break; + + 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 40: + parser->stack[++parser->top].state = 48; + break; + + case 51: + parser->stack[++parser->top].state = 60; + break; + + case 57: + parser->stack[++parser->top].state = 66; + break; + + case 76: + parser->stack[++parser->top].state = 78; + break; + + case 77: + parser->stack[++parser->top].state = 79; + break; + + } + } + break; + + 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 40: + parser->stack[++parser->top].state = 48; + break; + + case 51: + parser->stack[++parser->top].state = 60; + break; + + case 57: + parser->stack[++parser->top].state = 66; + break; + + case 76: + parser->stack[++parser->top].state = 78; + break; + + case 77: + parser->stack[++parser->top].state = 79; + break; + + } + } + break; + case 51: switch (token) { - case 'a': - parser->stack[++parser->top].state = 59; + case TOK_SYMBOL: + parser->stack[++parser->top].state = 49; + return 1; + + case TOK_SYMBOL_UC: + parser->stack[++parser->top].state = 50; return 1; default: @@ -852,8 +857,8 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus case 52: switch (token) { - case TOK_BLOCK: - parser->stack[++parser->top].state = 60; + case '.': + parser->stack[++parser->top].state = 61; return 1; default: @@ -863,8 +868,8 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus case 53: switch (token) { - case TOK_BLOCK: - parser->stack[++parser->top].state = 61; + case 'c': + parser->stack[++parser->top].state = 62; return 1; default: @@ -874,12 +879,8 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus case 54: switch (token) { - case TOK_SYMBOL: - parser->stack[++parser->top].state = 47; - return 1; - - case TOK_SYMBOL_UC: - parser->stack[++parser->top].state = 48; + case 'a': + parser->stack[++parser->top].state = 63; return 1; default: @@ -888,6 +889,43 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus break; case 55: + switch (token) { + case TOK_BLOCK: + parser->stack[++parser->top].state = 64; + return 1; + + default: + return -1; + } + break; + + case 56: + switch (token) { + case TOK_BLOCK: + parser->stack[++parser->top].state = 65; + return 1; + + default: + return -1; + } + break; + + case 57: + switch (token) { + case TOK_SYMBOL: + parser->stack[++parser->top].state = 49; + return 1; + + case TOK_SYMBOL_UC: + parser->stack[++parser->top].state = 50; + return 1; + + default: + return -1; + } + break; + + 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,44 +944,55 @@ 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; - } - break; - - case 57: - switch (token) { - case ')': - parser->stack[++parser->top].state = 63; - return 1; - - default: - return -1; - } - break; - - case 58: - switch (token) { - case 't': - parser->stack[++parser->top].state = 64; - return 1; - - default: - return -1; - } - break; - - case 59: - switch (token) { - case 'r': - parser->stack[++parser->top].state = 65; - return 1; - - default: - return -1; + parser->stack[++parser->top].state = 17; } break; case 60: + switch (token) { + case ')': + parser->stack[++parser->top].state = 67; + return 1; + + default: + return -1; + } + break; + + 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 = 69; + return 1; + + default: + return -1; + } + break; + + case 63: + switch (token) { + case 'r': + parser->stack[++parser->top].state = 70; + return 1; + + default: + return -1; + } + break; + + 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,55 +1032,87 @@ 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; - } - break; - - case 64: - switch (token) { - case 'o': - parser->stack[++parser->top].state = 66; - return 1; - - default: - return -1; - } - break; - - case 65: - switch (token) { - case 'g': - parser->stack[++parser->top].state = 67; - return 1; - - default: - return -1; - } - break; - - case 66: - switch (token) { - case 'r': - parser->stack[++parser->top].state = 68; - return 1; - - default: - return -1; - } - break; - - case 67: - switch (token) { - case TOK_BLOCK: - parser->stack[++parser->top].state = 69; - return 1; - - default: - return -1; + parser->stack[++parser->top].state = 17; } break; 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 = 72; + return 1; + + default: + return -1; + } + break; + + case 70: + switch (token) { + case 'g': + parser->stack[++parser->top].state = 73; + return 1; + + default: + return -1; + } + break; + + 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 = 75; + return 1; + + default: + return -1; + } + break; + + case 73: + switch (token) { + case TOK_BLOCK: + parser->stack[++parser->top].state = 76; + return 1; + + default: + return -1; + } + break; + + 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()]