diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lex.cpp | 24 | ||||
-rw-r--r-- | src/lex.hpp | 4 | ||||
-rw-r--r-- | src/parse.cpp | 346 | ||||
-rw-r--r-- | src/parse.hpp | 9 | ||||
-rw-r--r-- | src/parse.y | 14 |
5 files changed, 257 insertions, 140 deletions
diff --git a/src/lex.cpp b/src/lex.cpp index c5ae330..3746c91 100644 --- a/src/lex.cpp +++ b/src/lex.cpp @@ -135,7 +135,6 @@ int lex_t::consume_comment(parse_token_value_t *value) { return -1; } -/* int lex_t::unterminated_string(parse_token_value_t *value) { if (ferror(file)) return io_error(value); @@ -145,18 +144,14 @@ int lex_t::unterminated_string(parse_token_value_t *value) { } int lex_t::lex_string(parse_token_value_t *value) { - char *buf = NULL; - size_t len = 1024; - size_t pos = 0; - if (needspace) return syntax_error(value); - buf = static_cast<char*>(std::malloc(len)); + std::string *buf = new std::string; while (true) { if (!next(true)) { - std::free(buf); + delete buf; return unterminated_string(value); } @@ -177,16 +172,10 @@ int lex_t::lex_string(parse_token_value_t *value) { continue; } - if (pos >= len) { - len *= 2; - buf = static_cast<char*>(std::realloc(buf, len)); - } - - buf[pos++] = cur; + *buf += cur; } - value->str = strndup(buf, pos); - std::free(buf); + value->str = buf; next(true); consume(true); @@ -194,6 +183,7 @@ int lex_t::lex_string(parse_token_value_t *value) { return TOK_STRING; } +/* int lex_t::lex_number(parse_token_value_t *value) { if (needspace) return syntax_error(value); @@ -431,8 +421,8 @@ int lex_t::lex(parse_token_value_t *value) { case '{': return lex_block(value); - //case '"': - //return lex_string(value); + case '"': + return lex_string(value); //case '0' ... '9': //return lex_number(value); diff --git a/src/lex.hpp b/src/lex.hpp index e240e12..bbf1de2 100644 --- a/src/lex.hpp +++ b/src/lex.hpp @@ -66,9 +66,9 @@ private: int syntax_error(parse_token_value_t *value); int consume_comment(parse_token_value_t *value); int unterminated_block(parse_token_value_t *value); - //int unterminated_string(parse_token_value_t *value); + int unterminated_string(parse_token_value_t *value); - //int lex_string(parse_token_value_t *value); + int lex_string(parse_token_value_t *value); //int lex_number(parse_token_value_t *value); int lex_keyword(parse_token_value_t *value); int lex_block(parse_token_value_t *value); diff --git a/src/parse.cpp b/src/parse.cpp index fba7e79..b68943d 100644 --- a/src/parse.cpp +++ b/src/parse.cpp @@ -107,43 +107,54 @@ static inline std::pair<std::vector<solar::symbol_t>, std::vector<std::string>> return rhs; } -static inline std::string * parse_reduce_12(__attribute__((unused)) solar::grammar_t * grammar) { +static inline std::pair<std::vector<solar::symbol_t>, std::vector<std::string>> * parse_reduce_12(std::pair<std::vector<solar::symbol_t>, std::vector<std::string>> * rhs, std::string * str, __attribute__((unused)) solar::grammar_t * grammar) { + for (char c : *str) { + rhs->first.push_back(solar::symbol_t::make_char(c)); + rhs->second.emplace_back(); + } + + delete str; + + return rhs; +} + +static inline std::string * parse_reduce_13(__attribute__((unused)) solar::grammar_t * grammar) { return new std::string; } -static inline std::string * parse_reduce_13(std::string * v, __attribute__((unused)) solar::grammar_t * grammar) { +static inline std::string * parse_reduce_14(std::string * v, __attribute__((unused)) solar::grammar_t * grammar) { return v; } -static inline solar::symbol_t * parse_reduce_14(solar::symbol_t * v, __attribute__((unused)) solar::grammar_t * grammar) { +static inline solar::symbol_t * parse_reduce_15(solar::symbol_t * v, __attribute__((unused)) solar::grammar_t * grammar) { return v; } -static inline solar::symbol_t * parse_reduce_15(std::string * v, __attribute__((unused)) solar::grammar_t * grammar) { +static inline solar::symbol_t * parse_reduce_16(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_16(std::string * v, __attribute__((unused)) solar::grammar_t * grammar) { +static inline solar::symbol_t * parse_reduce_17(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_17(char v, __attribute__((unused)) solar::grammar_t * grammar) { +static inline solar::symbol_t * parse_reduce_18(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_18(std::string * v, __attribute__((unused)) solar::grammar_t * grammar) { +static inline std::string * parse_reduce_19(std::string * v, __attribute__((unused)) solar::grammar_t * grammar) { return v; } -static inline std::string * parse_reduce_19(std::string * v, __attribute__((unused)) solar::grammar_t * grammar) { +static inline std::string * parse_reduce_20(std::string * v, __attribute__((unused)) solar::grammar_t * grammar) { return 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; } @@ -465,7 +476,7 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va switch (token) { case TOK_BLOCK: parser->top -= 1; - parser->stack[parser->top].value.symbol_term = parse_reduce_17(parser->stack[parser->top + 0].value.token.c, grammar); + parser->stack[parser->top].value.symbol_term = parse_reduce_18(parser->stack[parser->top + 0].value.token.c, grammar); switch (parser->stack[parser->top].state) { case 7: parser->stack[++parser->top].state = 12; @@ -478,7 +489,20 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va case TOK_CHAR: parser->top -= 1; - parser->stack[parser->top].value.symbol_term = parse_reduce_17(parser->stack[parser->top + 0].value.token.c, grammar); + parser->stack[parser->top].value.symbol_term = parse_reduce_18(parser->stack[parser->top + 0].value.token.c, grammar); + switch (parser->stack[parser->top].state) { + case 7: + parser->stack[++parser->top].state = 12; + break; + case 23: + parser->stack[++parser->top].state = 27; + break; + } + break; + + case TOK_STRING: + parser->top -= 1; + parser->stack[parser->top].value.symbol_term = parse_reduce_18(parser->stack[parser->top + 0].value.token.c, grammar); switch (parser->stack[parser->top].state) { case 7: parser->stack[++parser->top].state = 12; @@ -491,7 +515,7 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va case TOK_SYMBOL_LC: parser->top -= 1; - parser->stack[parser->top].value.symbol_term = parse_reduce_17(parser->stack[parser->top + 0].value.token.c, grammar); + parser->stack[parser->top].value.symbol_term = parse_reduce_18(parser->stack[parser->top + 0].value.token.c, grammar); switch (parser->stack[parser->top].state) { case 7: parser->stack[++parser->top].state = 12; @@ -504,7 +528,7 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va case TOK_SYMBOL_UC: parser->top -= 1; - parser->stack[parser->top].value.symbol_term = parse_reduce_17(parser->stack[parser->top + 0].value.token.c, grammar); + parser->stack[parser->top].value.symbol_term = parse_reduce_18(parser->stack[parser->top + 0].value.token.c, grammar); switch (parser->stack[parser->top].state) { case 7: parser->stack[++parser->top].state = 12; @@ -517,7 +541,7 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va case '(': parser->top -= 1; - parser->stack[parser->top].value.symbol_term = parse_reduce_17(parser->stack[parser->top + 0].value.token.c, grammar); + parser->stack[parser->top].value.symbol_term = parse_reduce_18(parser->stack[parser->top + 0].value.token.c, grammar); switch (parser->stack[parser->top].state) { case 7: parser->stack[++parser->top].state = 12; @@ -530,7 +554,7 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va case ';': parser->top -= 1; - parser->stack[parser->top].value.symbol_term = parse_reduce_17(parser->stack[parser->top + 0].value.token.c, grammar); + parser->stack[parser->top].value.symbol_term = parse_reduce_18(parser->stack[parser->top + 0].value.token.c, grammar); switch (parser->stack[parser->top].state) { case 7: parser->stack[++parser->top].state = 12; @@ -562,7 +586,7 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va switch (token) { case TOK_BLOCK: parser->top -= 1; - parser->stack[parser->top].value.symbol_term = parse_reduce_16(parser->stack[parser->top + 0].value.token.str, grammar); + parser->stack[parser->top].value.symbol_term = parse_reduce_17(parser->stack[parser->top + 0].value.token.str, grammar); switch (parser->stack[parser->top].state) { case 7: parser->stack[++parser->top].state = 12; @@ -575,7 +599,20 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va case TOK_CHAR: parser->top -= 1; - parser->stack[parser->top].value.symbol_term = parse_reduce_16(parser->stack[parser->top + 0].value.token.str, grammar); + parser->stack[parser->top].value.symbol_term = parse_reduce_17(parser->stack[parser->top + 0].value.token.str, grammar); + switch (parser->stack[parser->top].state) { + case 7: + parser->stack[++parser->top].state = 12; + break; + case 23: + parser->stack[++parser->top].state = 27; + break; + } + break; + + case TOK_STRING: + parser->top -= 1; + parser->stack[parser->top].value.symbol_term = parse_reduce_17(parser->stack[parser->top + 0].value.token.str, grammar); switch (parser->stack[parser->top].state) { case 7: parser->stack[++parser->top].state = 12; @@ -588,7 +625,7 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va case TOK_SYMBOL_LC: parser->top -= 1; - parser->stack[parser->top].value.symbol_term = parse_reduce_16(parser->stack[parser->top + 0].value.token.str, grammar); + parser->stack[parser->top].value.symbol_term = parse_reduce_17(parser->stack[parser->top + 0].value.token.str, grammar); switch (parser->stack[parser->top].state) { case 7: parser->stack[++parser->top].state = 12; @@ -601,7 +638,7 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va case TOK_SYMBOL_UC: parser->top -= 1; - parser->stack[parser->top].value.symbol_term = parse_reduce_16(parser->stack[parser->top + 0].value.token.str, grammar); + parser->stack[parser->top].value.symbol_term = parse_reduce_17(parser->stack[parser->top + 0].value.token.str, grammar); switch (parser->stack[parser->top].state) { case 7: parser->stack[++parser->top].state = 12; @@ -614,7 +651,7 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va case '(': parser->top -= 1; - parser->stack[parser->top].value.symbol_term = parse_reduce_16(parser->stack[parser->top + 0].value.token.str, grammar); + parser->stack[parser->top].value.symbol_term = parse_reduce_17(parser->stack[parser->top + 0].value.token.str, grammar); switch (parser->stack[parser->top].state) { case 7: parser->stack[++parser->top].state = 12; @@ -627,7 +664,7 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va case ';': parser->top -= 1; - parser->stack[parser->top].value.symbol_term = parse_reduce_16(parser->stack[parser->top + 0].value.token.str, grammar); + parser->stack[parser->top].value.symbol_term = parse_reduce_17(parser->stack[parser->top + 0].value.token.str, grammar); switch (parser->stack[parser->top].state) { case 7: parser->stack[++parser->top].state = 12; @@ -690,7 +727,7 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va switch (token) { case 0: 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 8: parser->stack[++parser->top].state = 16; @@ -698,15 +735,15 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va case 21: parser->stack[++parser->top].state = 24; break; - case 31: - parser->stack[++parser->top].state = 32; + case 32: + parser->stack[++parser->top].state = 33; break; } break; case TOK_EXTRA_ARG: 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 8: parser->stack[++parser->top].state = 16; @@ -714,15 +751,15 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va case 21: parser->stack[++parser->top].state = 24; break; - case 31: - parser->stack[++parser->top].state = 32; + case 32: + parser->stack[++parser->top].state = 33; break; } break; case TOK_HEADER: 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 8: parser->stack[++parser->top].state = 16; @@ -730,15 +767,15 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va case 21: parser->stack[++parser->top].state = 24; break; - case 31: - parser->stack[++parser->top].state = 32; + case 32: + parser->stack[++parser->top].state = 33; break; } break; case TOK_SOURCE: 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 8: parser->stack[++parser->top].state = 16; @@ -746,15 +783,15 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va case 21: parser->stack[++parser->top].state = 24; break; - case 31: - parser->stack[++parser->top].state = 32; + case 32: + parser->stack[++parser->top].state = 33; break; } break; case TOK_SYMBOL_LC: 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 8: parser->stack[++parser->top].state = 16; @@ -762,15 +799,15 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va case 21: parser->stack[++parser->top].state = 24; break; - case 31: - parser->stack[++parser->top].state = 32; + case 32: + parser->stack[++parser->top].state = 33; break; } break; case TOK_TYPE: 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 8: parser->stack[++parser->top].state = 16; @@ -778,15 +815,15 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va case 21: parser->stack[++parser->top].state = 24; break; - case 31: - parser->stack[++parser->top].state = 32; + case 32: + parser->stack[++parser->top].state = 33; break; } break; case ')': 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 8: parser->stack[++parser->top].state = 16; @@ -794,8 +831,8 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va case 21: parser->stack[++parser->top].state = 24; break; - case 31: - parser->stack[++parser->top].state = 32; + case 32: + parser->stack[++parser->top].state = 33; break; } break; @@ -809,7 +846,7 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va switch (token) { case 0: parser->top -= 1; - parser->stack[parser->top].value.symbol_varname = parse_reduce_18(parser->stack[parser->top + 0].value.token.str, grammar); + parser->stack[parser->top].value.symbol_varname = parse_reduce_19(parser->stack[parser->top + 0].value.token.str, grammar); switch (parser->stack[parser->top].state) { case 8: parser->stack[++parser->top].state = 16; @@ -817,15 +854,15 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va case 21: parser->stack[++parser->top].state = 24; break; - case 31: - parser->stack[++parser->top].state = 32; + case 32: + parser->stack[++parser->top].state = 33; break; } break; case TOK_EXTRA_ARG: parser->top -= 1; - parser->stack[parser->top].value.symbol_varname = parse_reduce_18(parser->stack[parser->top + 0].value.token.str, grammar); + parser->stack[parser->top].value.symbol_varname = parse_reduce_19(parser->stack[parser->top + 0].value.token.str, grammar); switch (parser->stack[parser->top].state) { case 8: parser->stack[++parser->top].state = 16; @@ -833,15 +870,15 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va case 21: parser->stack[++parser->top].state = 24; break; - case 31: - parser->stack[++parser->top].state = 32; + case 32: + parser->stack[++parser->top].state = 33; break; } break; case TOK_HEADER: parser->top -= 1; - parser->stack[parser->top].value.symbol_varname = parse_reduce_18(parser->stack[parser->top + 0].value.token.str, grammar); + parser->stack[parser->top].value.symbol_varname = parse_reduce_19(parser->stack[parser->top + 0].value.token.str, grammar); switch (parser->stack[parser->top].state) { case 8: parser->stack[++parser->top].state = 16; @@ -849,15 +886,15 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va case 21: parser->stack[++parser->top].state = 24; break; - case 31: - parser->stack[++parser->top].state = 32; + case 32: + parser->stack[++parser->top].state = 33; break; } break; case TOK_SOURCE: parser->top -= 1; - parser->stack[parser->top].value.symbol_varname = parse_reduce_18(parser->stack[parser->top + 0].value.token.str, grammar); + parser->stack[parser->top].value.symbol_varname = parse_reduce_19(parser->stack[parser->top + 0].value.token.str, grammar); switch (parser->stack[parser->top].state) { case 8: parser->stack[++parser->top].state = 16; @@ -865,15 +902,15 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va case 21: parser->stack[++parser->top].state = 24; break; - case 31: - parser->stack[++parser->top].state = 32; + case 32: + parser->stack[++parser->top].state = 33; break; } break; case TOK_SYMBOL_LC: parser->top -= 1; - parser->stack[parser->top].value.symbol_varname = parse_reduce_18(parser->stack[parser->top + 0].value.token.str, grammar); + parser->stack[parser->top].value.symbol_varname = parse_reduce_19(parser->stack[parser->top + 0].value.token.str, grammar); switch (parser->stack[parser->top].state) { case 8: parser->stack[++parser->top].state = 16; @@ -881,15 +918,15 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va case 21: parser->stack[++parser->top].state = 24; break; - case 31: - parser->stack[++parser->top].state = 32; + case 32: + parser->stack[++parser->top].state = 33; break; } break; case TOK_TYPE: parser->top -= 1; - parser->stack[parser->top].value.symbol_varname = parse_reduce_18(parser->stack[parser->top + 0].value.token.str, grammar); + parser->stack[parser->top].value.symbol_varname = parse_reduce_19(parser->stack[parser->top + 0].value.token.str, grammar); switch (parser->stack[parser->top].state) { case 8: parser->stack[++parser->top].state = 16; @@ -897,15 +934,15 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va case 21: parser->stack[++parser->top].state = 24; break; - case 31: - parser->stack[++parser->top].state = 32; + case 32: + parser->stack[++parser->top].state = 33; break; } break; case ')': parser->top -= 1; - parser->stack[parser->top].value.symbol_varname = parse_reduce_18(parser->stack[parser->top + 0].value.token.str, grammar); + parser->stack[parser->top].value.symbol_varname = parse_reduce_19(parser->stack[parser->top + 0].value.token.str, grammar); switch (parser->stack[parser->top].state) { case 8: parser->stack[++parser->top].state = 16; @@ -913,8 +950,8 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va case 21: parser->stack[++parser->top].state = 24; break; - case 31: - parser->stack[++parser->top].state = 32; + case 32: + parser->stack[++parser->top].state = 33; break; } break; @@ -928,7 +965,7 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va switch (token) { case 0: parser->top -= 1; - parser->stack[parser->top].value.symbol_varname = parse_reduce_19(parser->stack[parser->top + 0].value.token.str, grammar); + parser->stack[parser->top].value.symbol_varname = parse_reduce_20(parser->stack[parser->top + 0].value.token.str, grammar); switch (parser->stack[parser->top].state) { case 8: parser->stack[++parser->top].state = 16; @@ -936,15 +973,15 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va case 21: parser->stack[++parser->top].state = 24; break; - case 31: - parser->stack[++parser->top].state = 32; + case 32: + parser->stack[++parser->top].state = 33; break; } break; case TOK_EXTRA_ARG: parser->top -= 1; - parser->stack[parser->top].value.symbol_varname = parse_reduce_19(parser->stack[parser->top + 0].value.token.str, grammar); + parser->stack[parser->top].value.symbol_varname = parse_reduce_20(parser->stack[parser->top + 0].value.token.str, grammar); switch (parser->stack[parser->top].state) { case 8: parser->stack[++parser->top].state = 16; @@ -952,15 +989,15 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va case 21: parser->stack[++parser->top].state = 24; break; - case 31: - parser->stack[++parser->top].state = 32; + case 32: + parser->stack[++parser->top].state = 33; break; } break; case TOK_HEADER: parser->top -= 1; - parser->stack[parser->top].value.symbol_varname = parse_reduce_19(parser->stack[parser->top + 0].value.token.str, grammar); + parser->stack[parser->top].value.symbol_varname = parse_reduce_20(parser->stack[parser->top + 0].value.token.str, grammar); switch (parser->stack[parser->top].state) { case 8: parser->stack[++parser->top].state = 16; @@ -968,15 +1005,15 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va case 21: parser->stack[++parser->top].state = 24; break; - case 31: - parser->stack[++parser->top].state = 32; + case 32: + parser->stack[++parser->top].state = 33; break; } break; case TOK_SOURCE: parser->top -= 1; - parser->stack[parser->top].value.symbol_varname = parse_reduce_19(parser->stack[parser->top + 0].value.token.str, grammar); + parser->stack[parser->top].value.symbol_varname = parse_reduce_20(parser->stack[parser->top + 0].value.token.str, grammar); switch (parser->stack[parser->top].state) { case 8: parser->stack[++parser->top].state = 16; @@ -984,15 +1021,15 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va case 21: parser->stack[++parser->top].state = 24; break; - case 31: - parser->stack[++parser->top].state = 32; + case 32: + parser->stack[++parser->top].state = 33; break; } break; case TOK_SYMBOL_LC: parser->top -= 1; - parser->stack[parser->top].value.symbol_varname = parse_reduce_19(parser->stack[parser->top + 0].value.token.str, grammar); + parser->stack[parser->top].value.symbol_varname = parse_reduce_20(parser->stack[parser->top + 0].value.token.str, grammar); switch (parser->stack[parser->top].state) { case 8: parser->stack[++parser->top].state = 16; @@ -1000,15 +1037,15 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va case 21: parser->stack[++parser->top].state = 24; break; - case 31: - parser->stack[++parser->top].state = 32; + case 32: + parser->stack[++parser->top].state = 33; break; } break; case TOK_TYPE: parser->top -= 1; - parser->stack[parser->top].value.symbol_varname = parse_reduce_19(parser->stack[parser->top + 0].value.token.str, grammar); + parser->stack[parser->top].value.symbol_varname = parse_reduce_20(parser->stack[parser->top + 0].value.token.str, grammar); switch (parser->stack[parser->top].state) { case 8: parser->stack[++parser->top].state = 16; @@ -1016,15 +1053,15 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va case 21: parser->stack[++parser->top].state = 24; break; - case 31: - parser->stack[++parser->top].state = 32; + case 32: + parser->stack[++parser->top].state = 33; break; } break; case ')': parser->top -= 1; - parser->stack[parser->top].value.symbol_varname = parse_reduce_19(parser->stack[parser->top + 0].value.token.str, grammar); + parser->stack[parser->top].value.symbol_varname = parse_reduce_20(parser->stack[parser->top + 0].value.token.str, grammar); switch (parser->stack[parser->top].state) { case 8: parser->stack[++parser->top].state = 16; @@ -1032,8 +1069,8 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va case 21: parser->stack[++parser->top].state = 24; break; - case 31: - parser->stack[++parser->top].state = 32; + case 32: + parser->stack[++parser->top].state = 33; break; } break; @@ -1055,6 +1092,11 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va parser->stack[++parser->top].state = 23; break; + case TOK_STRING: + parser->stack[parser->top].value.symbol_rhs = parse_reduce_9(grammar); + parser->stack[++parser->top].state = 23; + break; + case TOK_SYMBOL_LC: parser->stack[parser->top].value.symbol_rhs = parse_reduce_9(grammar); parser->stack[++parser->top].state = 23; @@ -1152,11 +1194,16 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va parser->stack[++parser->top].state = 13; return 1; - case TOK_SYMBOL_LC: + case TOK_STRING: parser->stack[parser->top].value.token = *value; parser->stack[++parser->top].state = 29; return 1; + case TOK_SYMBOL_LC: + parser->stack[parser->top].value.token = *value; + parser->stack[++parser->top].state = 30; + return 1; + case TOK_SYMBOL_UC: parser->stack[parser->top].value.token = *value; parser->stack[++parser->top].state = 15; @@ -1164,7 +1211,7 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va case ';': parser->stack[parser->top].value.token = *value; - parser->stack[++parser->top].state = 30; + parser->stack[++parser->top].state = 31; return 1; default: @@ -1272,6 +1319,12 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va parser->stack[++parser->top].state = 23; break; + case TOK_STRING: + parser->top -= 2; + parser->stack[parser->top].value.symbol_rhs = parse_reduce_10(parser->stack[parser->top + 0].value.symbol_rhs, parser->stack[parser->top + 1].value.symbol_symbol, grammar); + parser->stack[++parser->top].state = 23; + break; + case TOK_SYMBOL_LC: parser->top -= 2; parser->stack[parser->top].value.symbol_rhs = parse_reduce_10(parser->stack[parser->top + 0].value.symbol_rhs, parser->stack[parser->top + 1].value.symbol_symbol, grammar); @@ -1286,7 +1339,7 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va case '(': parser->stack[parser->top].value.token = *value; - parser->stack[++parser->top].state = 31; + parser->stack[++parser->top].state = 32; return 1; case ';': @@ -1304,37 +1357,43 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va switch (token) { case TOK_BLOCK: parser->top -= 1; - parser->stack[parser->top].value.symbol_symbol = parse_reduce_14(parser->stack[parser->top + 0].value.symbol_term, grammar); + parser->stack[parser->top].value.symbol_symbol = parse_reduce_15(parser->stack[parser->top + 0].value.symbol_term, grammar); parser->stack[++parser->top].state = 26; break; case TOK_CHAR: parser->top -= 1; - parser->stack[parser->top].value.symbol_symbol = parse_reduce_14(parser->stack[parser->top + 0].value.symbol_term, grammar); + parser->stack[parser->top].value.symbol_symbol = parse_reduce_15(parser->stack[parser->top + 0].value.symbol_term, grammar); + parser->stack[++parser->top].state = 26; + break; + + case TOK_STRING: + parser->top -= 1; + parser->stack[parser->top].value.symbol_symbol = parse_reduce_15(parser->stack[parser->top + 0].value.symbol_term, grammar); parser->stack[++parser->top].state = 26; break; case TOK_SYMBOL_LC: parser->top -= 1; - parser->stack[parser->top].value.symbol_symbol = parse_reduce_14(parser->stack[parser->top + 0].value.symbol_term, grammar); + parser->stack[parser->top].value.symbol_symbol = parse_reduce_15(parser->stack[parser->top + 0].value.symbol_term, grammar); parser->stack[++parser->top].state = 26; break; case TOK_SYMBOL_UC: parser->top -= 1; - parser->stack[parser->top].value.symbol_symbol = parse_reduce_14(parser->stack[parser->top + 0].value.symbol_term, grammar); + parser->stack[parser->top].value.symbol_symbol = parse_reduce_15(parser->stack[parser->top + 0].value.symbol_term, grammar); parser->stack[++parser->top].state = 26; break; case '(': parser->top -= 1; - parser->stack[parser->top].value.symbol_symbol = parse_reduce_14(parser->stack[parser->top + 0].value.symbol_term, grammar); + parser->stack[parser->top].value.symbol_symbol = parse_reduce_15(parser->stack[parser->top + 0].value.symbol_term, grammar); parser->stack[++parser->top].state = 26; break; case ';': parser->top -= 1; - parser->stack[parser->top].value.symbol_symbol = parse_reduce_14(parser->stack[parser->top + 0].value.symbol_term, grammar); + parser->stack[parser->top].value.symbol_symbol = parse_reduce_15(parser->stack[parser->top + 0].value.symbol_term, grammar); parser->stack[++parser->top].state = 26; break; @@ -1347,37 +1406,37 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va switch (token) { case 0: parser->top -= 1; - parser->stack[parser->top].value.symbol_action = parse_reduce_13(parser->stack[parser->top + 0].value.token.str, grammar); + parser->stack[parser->top].value.symbol_action = parse_reduce_14(parser->stack[parser->top + 0].value.token.str, grammar); parser->stack[++parser->top].state = 25; break; case TOK_EXTRA_ARG: parser->top -= 1; - parser->stack[parser->top].value.symbol_action = parse_reduce_13(parser->stack[parser->top + 0].value.token.str, grammar); + parser->stack[parser->top].value.symbol_action = parse_reduce_14(parser->stack[parser->top + 0].value.token.str, grammar); parser->stack[++parser->top].state = 25; break; case TOK_HEADER: parser->top -= 1; - parser->stack[parser->top].value.symbol_action = parse_reduce_13(parser->stack[parser->top + 0].value.token.str, grammar); + parser->stack[parser->top].value.symbol_action = parse_reduce_14(parser->stack[parser->top + 0].value.token.str, grammar); parser->stack[++parser->top].state = 25; break; case TOK_SOURCE: parser->top -= 1; - parser->stack[parser->top].value.symbol_action = parse_reduce_13(parser->stack[parser->top + 0].value.token.str, grammar); + parser->stack[parser->top].value.symbol_action = parse_reduce_14(parser->stack[parser->top + 0].value.token.str, grammar); parser->stack[++parser->top].state = 25; break; case TOK_SYMBOL_LC: parser->top -= 1; - parser->stack[parser->top].value.symbol_action = parse_reduce_13(parser->stack[parser->top + 0].value.token.str, grammar); + parser->stack[parser->top].value.symbol_action = parse_reduce_14(parser->stack[parser->top + 0].value.token.str, grammar); parser->stack[++parser->top].state = 25; break; case TOK_TYPE: parser->top -= 1; - parser->stack[parser->top].value.symbol_action = parse_reduce_13(parser->stack[parser->top + 0].value.token.str, grammar); + parser->stack[parser->top].value.symbol_action = parse_reduce_14(parser->stack[parser->top + 0].value.token.str, grammar); parser->stack[++parser->top].state = 25; break; @@ -1389,38 +1448,87 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va case 29: switch (token) { case TOK_BLOCK: + parser->top -= 2; + parser->stack[parser->top].value.symbol_rhs = parse_reduce_12(parser->stack[parser->top + 0].value.symbol_rhs, parser->stack[parser->top + 1].value.token.str, grammar); + parser->stack[++parser->top].state = 23; + break; + + case TOK_CHAR: + parser->top -= 2; + parser->stack[parser->top].value.symbol_rhs = parse_reduce_12(parser->stack[parser->top + 0].value.symbol_rhs, parser->stack[parser->top + 1].value.token.str, grammar); + parser->stack[++parser->top].state = 23; + break; + + case TOK_STRING: + parser->top -= 2; + parser->stack[parser->top].value.symbol_rhs = parse_reduce_12(parser->stack[parser->top + 0].value.symbol_rhs, parser->stack[parser->top + 1].value.token.str, grammar); + parser->stack[++parser->top].state = 23; + break; + + case TOK_SYMBOL_LC: + parser->top -= 2; + parser->stack[parser->top].value.symbol_rhs = parse_reduce_12(parser->stack[parser->top + 0].value.symbol_rhs, parser->stack[parser->top + 1].value.token.str, grammar); + parser->stack[++parser->top].state = 23; + break; + + case TOK_SYMBOL_UC: + parser->top -= 2; + parser->stack[parser->top].value.symbol_rhs = parse_reduce_12(parser->stack[parser->top + 0].value.symbol_rhs, parser->stack[parser->top + 1].value.token.str, grammar); + parser->stack[++parser->top].state = 23; + break; + + case ';': + parser->top -= 2; + parser->stack[parser->top].value.symbol_rhs = parse_reduce_12(parser->stack[parser->top + 0].value.symbol_rhs, parser->stack[parser->top + 1].value.token.str, grammar); + parser->stack[++parser->top].state = 23; + break; + + default: + return -1; + } + break; + + case 30: + switch (token) { + case TOK_BLOCK: parser->top -= 1; - parser->stack[parser->top].value.symbol_symbol = parse_reduce_15(parser->stack[parser->top + 0].value.token.str, grammar); + parser->stack[parser->top].value.symbol_symbol = parse_reduce_16(parser->stack[parser->top + 0].value.token.str, grammar); parser->stack[++parser->top].state = 26; break; case TOK_CHAR: parser->top -= 1; - parser->stack[parser->top].value.symbol_symbol = parse_reduce_15(parser->stack[parser->top + 0].value.token.str, grammar); + parser->stack[parser->top].value.symbol_symbol = parse_reduce_16(parser->stack[parser->top + 0].value.token.str, grammar); + parser->stack[++parser->top].state = 26; + break; + + case TOK_STRING: + parser->top -= 1; + parser->stack[parser->top].value.symbol_symbol = parse_reduce_16(parser->stack[parser->top + 0].value.token.str, grammar); parser->stack[++parser->top].state = 26; break; case TOK_SYMBOL_LC: parser->top -= 1; - parser->stack[parser->top].value.symbol_symbol = parse_reduce_15(parser->stack[parser->top + 0].value.token.str, grammar); + parser->stack[parser->top].value.symbol_symbol = parse_reduce_16(parser->stack[parser->top + 0].value.token.str, grammar); parser->stack[++parser->top].state = 26; break; case TOK_SYMBOL_UC: parser->top -= 1; - parser->stack[parser->top].value.symbol_symbol = parse_reduce_15(parser->stack[parser->top + 0].value.token.str, grammar); + parser->stack[parser->top].value.symbol_symbol = parse_reduce_16(parser->stack[parser->top + 0].value.token.str, grammar); parser->stack[++parser->top].state = 26; break; case '(': parser->top -= 1; - parser->stack[parser->top].value.symbol_symbol = parse_reduce_15(parser->stack[parser->top + 0].value.token.str, grammar); + parser->stack[parser->top].value.symbol_symbol = parse_reduce_16(parser->stack[parser->top + 0].value.token.str, grammar); parser->stack[++parser->top].state = 26; break; case ';': parser->top -= 1; - parser->stack[parser->top].value.symbol_symbol = parse_reduce_15(parser->stack[parser->top + 0].value.token.str, grammar); + parser->stack[parser->top].value.symbol_symbol = parse_reduce_16(parser->stack[parser->top + 0].value.token.str, grammar); parser->stack[++parser->top].state = 26; break; @@ -1429,41 +1537,41 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va } break; - case 30: + case 31: switch (token) { case 0: parser->top -= 1; - parser->stack[parser->top].value.symbol_action = parse_reduce_12(grammar); + parser->stack[parser->top].value.symbol_action = parse_reduce_13(grammar); parser->stack[++parser->top].state = 25; break; case TOK_EXTRA_ARG: parser->top -= 1; - parser->stack[parser->top].value.symbol_action = parse_reduce_12(grammar); + parser->stack[parser->top].value.symbol_action = parse_reduce_13(grammar); parser->stack[++parser->top].state = 25; break; case TOK_HEADER: parser->top -= 1; - parser->stack[parser->top].value.symbol_action = parse_reduce_12(grammar); + parser->stack[parser->top].value.symbol_action = parse_reduce_13(grammar); parser->stack[++parser->top].state = 25; break; case TOK_SOURCE: parser->top -= 1; - parser->stack[parser->top].value.symbol_action = parse_reduce_12(grammar); + parser->stack[parser->top].value.symbol_action = parse_reduce_13(grammar); parser->stack[++parser->top].state = 25; break; case TOK_SYMBOL_LC: parser->top -= 1; - parser->stack[parser->top].value.symbol_action = parse_reduce_12(grammar); + parser->stack[parser->top].value.symbol_action = parse_reduce_13(grammar); parser->stack[++parser->top].state = 25; break; case TOK_TYPE: parser->top -= 1; - parser->stack[parser->top].value.symbol_action = parse_reduce_12(grammar); + parser->stack[parser->top].value.symbol_action = parse_reduce_13(grammar); parser->stack[++parser->top].state = 25; break; @@ -1472,7 +1580,7 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va } break; - case 31: + case 32: switch (token) { case TOK_SYMBOL: parser->stack[parser->top].value.token = *value; @@ -1494,11 +1602,11 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va } break; - case 32: + case 33: switch (token) { case ')': parser->stack[parser->top].value.token = *value; - parser->stack[++parser->top].state = 33; + parser->stack[++parser->top].state = 34; return 1; default: @@ -1506,7 +1614,7 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va } break; - case 33: + case 34: switch (token) { case TOK_BLOCK: parser->top -= 5; @@ -1520,6 +1628,12 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va parser->stack[++parser->top].state = 23; break; + case TOK_STRING: + parser->top -= 5; + parser->stack[parser->top].value.symbol_rhs = parse_reduce_11(parser->stack[parser->top + 0].value.symbol_rhs, parser->stack[parser->top + 1].value.symbol_symbol, parser->stack[parser->top + 3].value.symbol_varname, grammar); + parser->stack[++parser->top].state = 23; + break; + case TOK_SYMBOL_LC: parser->top -= 5; parser->stack[parser->top].value.symbol_rhs = parse_reduce_11(parser->stack[parser->top + 0].value.symbol_rhs, parser->stack[parser->top + 1].value.symbol_symbol, parser->stack[parser->top + 3].value.symbol_varname, grammar); diff --git a/src/parse.hpp b/src/parse.hpp index 567a38c..86aa095 100644 --- a/src/parse.hpp +++ b/src/parse.hpp @@ -9,10 +9,11 @@ enum parse_token_t { TOK_EXTRA_ARG = 258, TOK_HEADER = 259, TOK_SOURCE = 260, - TOK_SYMBOL = 261, - TOK_SYMBOL_LC = 262, - TOK_SYMBOL_UC = 263, - TOK_TYPE = 264, + TOK_STRING = 261, + TOK_SYMBOL = 262, + TOK_SYMBOL_LC = 263, + TOK_SYMBOL_UC = 264, + TOK_TYPE = 265, }; typedef struct parse_token_value { diff --git a/src/parse.y b/src/parse.y index 46f5ff6..28f13ad 100644 --- a/src/parse.y +++ b/src/parse.y @@ -2,6 +2,7 @@ %type SYMBOL_UC {std::string *} str %type SYMBOL_LC {std::string *} str %type BLOCK {std::string *} str +%type STRING {std::string *} str %type CHAR {char} c %type rule {solar::rule_t *} @@ -65,7 +66,7 @@ grammar |= grammar EXTRA_ARG BLOCK(type) varname(name) { } -rule |= SYMBOL_LC(lhs) '|' '=' rhs(rhs) action(action) { +rule |= SYMBOL_LC(lhs) "|=" rhs(rhs) action(action) { auto *ret = new solar::rule_t {solar::item_t(*lhs, rhs->first), rhs->second, *action}; delete lhs; @@ -98,6 +99,17 @@ rhs |= rhs(rhs) symbol(sym) '(' varname(var) ')' { return rhs; } +rhs |= rhs(rhs) STRING(str) { + for (char c : *str) { + rhs->first.push_back(solar::symbol_t::make_char(c)); + rhs->second.emplace_back(); + } + + delete str; + + return rhs; +} + action |= ';' { return new std::string; |