From 69d5b76e1a56a0e2f537b06b133921b45f490371 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 11 Apr 2015 01:47:28 +0200 Subject: Add support for square-bracketed actions --- src/parse.cpp | 222 +++++++++++++++++++++++++++++++--------------------------- 1 file changed, 120 insertions(+), 102 deletions(-) (limited to 'src/parse.cpp') diff --git a/src/parse.cpp b/src/parse.cpp index afeafda..faf9618 100644 --- a/src/parse.cpp +++ b/src/parse.cpp @@ -126,35 +126,40 @@ static inline std::string * parse_reduce_15(std::string * v, __attribute__((unus return v; } -static inline solar::symbol_t * parse_reduce_16(solar::symbol_t * v, __attribute__((unused)) solar::grammar_t * grammar) { +static inline std::string * parse_reduce_16(std::string * v, __attribute__((unused)) solar::grammar_t * grammar) { + *v = "\n\treturn " + *v + ";\n"; return v; } -static inline solar::symbol_t * parse_reduce_17(std::string * v, __attribute__((unused)) solar::grammar_t * grammar) { +static inline solar::symbol_t * parse_reduce_17(solar::symbol_t * v, __attribute__((unused)) solar::grammar_t * grammar) { + return v; +} + +static inline solar::symbol_t * parse_reduce_18(std::string * v, __attribute__((unused)) solar::grammar_t * grammar) { solar::symbol_t *ret = new solar::symbol_t(solar::symbol_t::make_nonterm(*v)); delete v; return ret; } -static inline solar::symbol_t * parse_reduce_18(std::string * v, __attribute__((unused)) solar::grammar_t * grammar) { +static inline solar::symbol_t * parse_reduce_19(std::string * v, __attribute__((unused)) solar::grammar_t * grammar) { solar::symbol_t *ret = new solar::symbol_t(solar::symbol_t::make_term(*v)); delete v; return ret; } -static inline solar::symbol_t * parse_reduce_19(char v, __attribute__((unused)) solar::grammar_t * grammar) { +static inline solar::symbol_t * parse_reduce_20(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_20(std::string * v, __attribute__((unused)) solar::grammar_t * grammar) { +static inline std::string * parse_reduce_21(std::string * v, __attribute__((unused)) solar::grammar_t * grammar) { return v; } -static inline std::string * parse_reduce_21(std::string * v, __attribute__((unused)) solar::grammar_t * grammar) { +static inline std::string * parse_reduce_22(std::string * v, __attribute__((unused)) solar::grammar_t * grammar) { return v; } -static inline std::string * parse_reduce_22(std::string * v, __attribute__((unused)) solar::grammar_t * grammar) { +static inline std::string * parse_reduce_23(std::string * v, __attribute__((unused)) solar::grammar_t * grammar) { return v; } @@ -354,22 +359,26 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus parser->stack[++parser->top].state = 25; return 1; - case TOK_STRING: + case TOK_SQBLOCK: parser->stack[++parser->top].state = 26; return 1; - case TOK_SYMBOL_LC: + case TOK_STRING: parser->stack[++parser->top].state = 27; return 1; - case TOK_SYMBOL_UC: + case TOK_SYMBOL_LC: parser->stack[++parser->top].state = 28; return 1; - case ';': + case TOK_SYMBOL_UC: parser->stack[++parser->top].state = 29; return 1; + case ';': + parser->stack[++parser->top].state = 30; + return 1; + default: return -1; } @@ -378,7 +387,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus case 17: switch (token) { case 'r': - parser->stack[++parser->top].state = 30; + parser->stack[++parser->top].state = 31; return 1; default: @@ -389,7 +398,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus case 18: switch (token) { case 'd': - parser->stack[++parser->top].state = 31; + parser->stack[++parser->top].state = 32; return 1; default: @@ -400,7 +409,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus case 19: switch (token) { case 'r': - parser->stack[++parser->top].state = 32; + parser->stack[++parser->top].state = 33; return 1; default: @@ -411,7 +420,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus case 20: switch (token) { case 'e': - parser->stack[++parser->top].state = 33; + parser->stack[++parser->top].state = 34; return 1; default: @@ -431,7 +440,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus case 22: switch (token) { case '(': - parser->stack[++parser->top].state = 34; + parser->stack[++parser->top].state = 35; return 1; default: @@ -445,7 +454,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus switch (token) { default: parser->top -= 1; - parser->stack[parser->top].value.symbol_symbol = parse_reduce_16(parser->stack[parser->top + 0].value.symbol_term, grammar); + parser->stack[parser->top].value.symbol_symbol = parse_reduce_17(parser->stack[parser->top + 0].value.symbol_term, grammar); parser->stack[++parser->top].state = 22; } break; @@ -463,14 +472,14 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus switch (token) { default: parser->top -= 1; - parser->stack[parser->top].value.symbol_term = parse_reduce_19(parser->stack[parser->top + 0].value.token.c, grammar); + parser->stack[parser->top].value.symbol_term = parse_reduce_20(parser->stack[parser->top + 0].value.token.c, grammar); switch (parser->stack[parser->top].state) { case 16: parser->stack[++parser->top].state = 23; break; - case 33: - parser->stack[++parser->top].state = 38; + case 34: + parser->stack[++parser->top].state = 39; break; } @@ -478,6 +487,15 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus break; case 26: + switch (token) { + default: + parser->top -= 1; + parser->stack[parser->top].value.symbol_action = parse_reduce_16(parser->stack[parser->top + 0].value.token.str, grammar); + parser->stack[++parser->top].state = 21; + } + break; + + case 27: switch (token) { default: parser->top -= 2; @@ -486,34 +504,34 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 27: + case 28: switch (token) { default: parser->top -= 1; - parser->stack[parser->top].value.symbol_symbol = parse_reduce_17(parser->stack[parser->top + 0].value.token.str, grammar); + parser->stack[parser->top].value.symbol_symbol = parse_reduce_18(parser->stack[parser->top + 0].value.token.str, grammar); parser->stack[++parser->top].state = 22; } break; - case 28: + case 29: switch (token) { default: parser->top -= 1; - parser->stack[parser->top].value.symbol_term = parse_reduce_18(parser->stack[parser->top + 0].value.token.str, grammar); + parser->stack[parser->top].value.symbol_term = parse_reduce_19(parser->stack[parser->top + 0].value.token.str, grammar); switch (parser->stack[parser->top].state) { case 16: parser->stack[++parser->top].state = 23; break; - case 33: - parser->stack[++parser->top].state = 38; + case 34: + parser->stack[++parser->top].state = 39; break; } } break; - case 29: + case 30: switch (token) { default: parser->top -= 1; @@ -522,10 +540,10 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 30: + case 31: switch (token) { case 'a': - parser->stack[++parser->top].state = 35; + parser->stack[++parser->top].state = 36; return 1; default: @@ -533,10 +551,10 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 31: + case 32: switch (token) { case 'e': - parser->stack[++parser->top].state = 36; + parser->stack[++parser->top].state = 37; return 1; default: @@ -544,10 +562,10 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 32: + case 33: switch (token) { case 'c': - parser->stack[++parser->top].state = 37; + parser->stack[++parser->top].state = 38; return 1; default: @@ -555,18 +573,18 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 33: + case 34: switch (token) { case TOK_CHAR: parser->stack[++parser->top].state = 25; return 1; case TOK_SYMBOL_UC: - parser->stack[++parser->top].state = 28; + parser->stack[++parser->top].state = 29; return 1; case TOK_SYMBOL_LC: - parser->stack[++parser->top].state = 39; + parser->stack[++parser->top].state = 40; return 1; default: @@ -574,18 +592,18 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 34: + case 35: switch (token) { case TOK_SYMBOL: - parser->stack[++parser->top].state = 41; + parser->stack[++parser->top].state = 42; return 1; case TOK_SYMBOL_LC: - parser->stack[++parser->top].state = 42; + parser->stack[++parser->top].state = 43; return 1; case TOK_SYMBOL_UC: - parser->stack[++parser->top].state = 43; + parser->stack[++parser->top].state = 44; return 1; default: @@ -593,10 +611,10 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 35: + case 36: switch (token) { case '_': - parser->stack[++parser->top].state = 44; + parser->stack[++parser->top].state = 45; return 1; default: @@ -604,10 +622,10 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 36: + case 37: switch (token) { case 'r': - parser->stack[++parser->top].state = 45; + parser->stack[++parser->top].state = 46; return 1; default: @@ -615,10 +633,10 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 37: + case 38: switch (token) { case 'e': - parser->stack[++parser->top].state = 46; + parser->stack[++parser->top].state = 47; return 1; default: @@ -626,10 +644,10 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 38: + case 39: switch (token) { case TOK_BLOCK: - parser->stack[++parser->top].state = 47; + parser->stack[++parser->top].state = 48; return 1; default: @@ -637,10 +655,10 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 39: + case 40: switch (token) { case TOK_BLOCK: - parser->stack[++parser->top].state = 48; + parser->stack[++parser->top].state = 49; return 1; default: @@ -648,10 +666,10 @@ 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 = 49; + parser->stack[++parser->top].state = 50; return 1; default: @@ -659,76 +677,76 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 41: + case 42: switch (token) { default: parser->top -= 1; - parser->stack[parser->top].value.symbol_varname = parse_reduce_22(parser->stack[parser->top + 0].value.token.str, grammar); + parser->stack[parser->top].value.symbol_varname = parse_reduce_23(parser->stack[parser->top + 0].value.token.str, grammar); switch (parser->stack[parser->top].state) { - case 34: - parser->stack[++parser->top].state = 40; + case 35: + parser->stack[++parser->top].state = 41; break; - case 47: - parser->stack[++parser->top].state = 53; + case 48: + parser->stack[++parser->top].state = 54; break; - case 56: - parser->stack[++parser->top].state = 57; + case 57: + parser->stack[++parser->top].state = 58; break; } } break; - case 42: + case 43: switch (token) { default: parser->top -= 1; - parser->stack[parser->top].value.symbol_varname = parse_reduce_20(parser->stack[parser->top + 0].value.token.str, grammar); + parser->stack[parser->top].value.symbol_varname = parse_reduce_21(parser->stack[parser->top + 0].value.token.str, grammar); switch (parser->stack[parser->top].state) { - case 34: - parser->stack[++parser->top].state = 40; + case 35: + parser->stack[++parser->top].state = 41; break; - case 47: - parser->stack[++parser->top].state = 53; + case 48: + parser->stack[++parser->top].state = 54; break; - case 56: - parser->stack[++parser->top].state = 57; + case 57: + parser->stack[++parser->top].state = 58; break; } } break; - case 43: + case 44: switch (token) { default: parser->top -= 1; - parser->stack[parser->top].value.symbol_varname = parse_reduce_21(parser->stack[parser->top + 0].value.token.str, grammar); + parser->stack[parser->top].value.symbol_varname = parse_reduce_22(parser->stack[parser->top + 0].value.token.str, grammar); switch (parser->stack[parser->top].state) { - case 34: - parser->stack[++parser->top].state = 40; + case 35: + parser->stack[++parser->top].state = 41; break; - case 47: - parser->stack[++parser->top].state = 53; + case 48: + parser->stack[++parser->top].state = 54; break; - case 56: - parser->stack[++parser->top].state = 57; + case 57: + parser->stack[++parser->top].state = 58; break; } } break; - case 44: + case 45: switch (token) { case 'a': - parser->stack[++parser->top].state = 50; + parser->stack[++parser->top].state = 51; return 1; default: @@ -736,10 +754,10 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 45: + case 46: switch (token) { case TOK_BLOCK: - parser->stack[++parser->top].state = 51; + parser->stack[++parser->top].state = 52; return 1; default: @@ -747,10 +765,10 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 46: + case 47: switch (token) { case TOK_BLOCK: - parser->stack[++parser->top].state = 52; + parser->stack[++parser->top].state = 53; return 1; default: @@ -758,18 +776,18 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 47: + case 48: switch (token) { case TOK_SYMBOL: - parser->stack[++parser->top].state = 41; + parser->stack[++parser->top].state = 42; return 1; case TOK_SYMBOL_LC: - parser->stack[++parser->top].state = 42; + parser->stack[++parser->top].state = 43; return 1; case TOK_SYMBOL_UC: - parser->stack[++parser->top].state = 43; + parser->stack[++parser->top].state = 44; return 1; default: @@ -777,7 +795,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 48: + case 49: switch (token) { default: parser->top -= 7; @@ -786,7 +804,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 49: + case 50: switch (token) { default: parser->top -= 5; @@ -795,10 +813,10 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 50: + case 51: switch (token) { case 'r': - parser->stack[++parser->top].state = 54; + parser->stack[++parser->top].state = 55; return 1; default: @@ -806,7 +824,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 51: + case 52: switch (token) { default: parser->top -= 8; @@ -815,7 +833,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 52: + case 53: switch (token) { default: parser->top -= 8; @@ -824,7 +842,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 53: + case 54: switch (token) { default: parser->top -= 8; @@ -833,10 +851,10 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 54: + case 55: switch (token) { case 'g': - parser->stack[++parser->top].state = 55; + parser->stack[++parser->top].state = 56; return 1; default: @@ -844,10 +862,10 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 55: + case 56: switch (token) { case TOK_BLOCK: - parser->stack[++parser->top].state = 56; + parser->stack[++parser->top].state = 57; return 1; default: @@ -855,18 +873,18 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 56: + case 57: switch (token) { case TOK_SYMBOL: - parser->stack[++parser->top].state = 41; + parser->stack[++parser->top].state = 42; return 1; case TOK_SYMBOL_LC: - parser->stack[++parser->top].state = 42; + parser->stack[++parser->top].state = 43; return 1; case TOK_SYMBOL_UC: - parser->stack[++parser->top].state = 43; + parser->stack[++parser->top].state = 44; return 1; default: @@ -874,7 +892,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 57: + case 58: switch (token) { default: parser->top -= 12; -- cgit v1.2.3