diff options
-rw-r--r-- | src/lex.cpp | 13 | ||||
-rw-r--r-- | src/parse.cpp | 199 | ||||
-rw-r--r-- | src/parse.hpp | 3 | ||||
-rw-r--r-- | src/parse.y | 10 |
4 files changed, 83 insertions, 142 deletions
diff --git a/src/lex.cpp b/src/lex.cpp index 3c86f25..29bdd4e 100644 --- a/src/lex.cpp +++ b/src/lex.cpp @@ -241,17 +241,17 @@ int lex_t::lex_symbol(parse_token_value_t *value) { if (needspace) return syntax_error(value); - bool uc = true; - bool lc = true; + bool uc = false; + bool lc = false; do { switch (current()) { case 'A' ... 'Z': - lc = false; + uc = true; continue; case 'a' ... 'z': - uc = false; + lc = true; continue; case '0' ... '9': @@ -264,10 +264,8 @@ int lex_t::lex_symbol(parse_token_value_t *value) { value->str = get_token(); - if (uc) + if (uc && !lc) return TOK_SYMBOL_UC; - else if (lc) - return TOK_SYMBOL_LC; else return TOK_SYMBOL; } @@ -420,6 +418,7 @@ int lex_t::lex(parse_token_value_t *value) { case 'a' ... 'z': case 'A' ... 'Z': + case '_': return lex_symbol(value); case '%': diff --git a/src/parse.cpp b/src/parse.cpp index fe3a026..9a24c03 100644 --- a/src/parse.cpp +++ b/src/parse.cpp @@ -141,8 +141,6 @@ static inline std::string * parse_reduce_23(std::string *v, __attribute__((unuse static inline std::string * parse_reduce_24(std::string *v, __attribute__((unused)) solar::grammar_t *grammar) {return v;} -static inline std::string * parse_reduce_25(std::string *v, __attribute__((unused)) solar::grammar_t *grammar) {return v;} - static int parse_do_push(parse_context_t *parser, int token, __attribute__((unused)) solar::grammar_t *grammar) { parse_symbol_value_t result; @@ -161,7 +159,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus case 0: return 0; - case TOK_SYMBOL_LC: + case TOK_SYMBOL: parser->stack[++parser->top].state = 4; return 1; @@ -378,7 +376,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus parser->stack[++parser->top].state = 30; return 1; - case TOK_SYMBOL_LC: + case TOK_SYMBOL: parser->stack[++parser->top].state = 31; return 1; @@ -489,8 +487,8 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus parser->stack[++parser->top].state = 25; break; - case 69: - parser->stack[++parser->top].state = 71; + case 68: + parser->stack[++parser->top].state = 70; break; } @@ -515,7 +513,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus parser->stack[parser->top].value.symbol_term = result.symbol_term; switch (parser->stack[parser->top].state) { case 18: - case 69: + case 68: parser->stack[++parser->top].state = 26; break; @@ -561,8 +559,8 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus parser->stack[++parser->top].state = 25; break; - case 69: - parser->stack[++parser->top].state = 71; + case 68: + parser->stack[++parser->top].state = 70; break; } @@ -578,7 +576,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus parser->stack[parser->top].value.symbol_term = result.symbol_term; switch (parser->stack[parser->top].state) { case 18: - case 69: + case 68: parser->stack[++parser->top].state = 26; break; @@ -654,7 +652,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus parser->stack[++parser->top].state = 32; return 1; - case TOK_SYMBOL_LC: + case TOK_SYMBOL: parser->stack[++parser->top].state = 45; return 1; @@ -669,16 +667,12 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus parser->stack[++parser->top].state = 47; return 1; - case TOK_SYMBOL_LC: - parser->stack[++parser->top].state = 48; - return 1; - case TOK_SYMBOL_UC: - parser->stack[++parser->top].state = 49; + parser->stack[++parser->top].state = 48; return 1; case '=': - parser->stack[++parser->top].state = 50; + parser->stack[++parser->top].state = 49; return 1; default: @@ -689,7 +683,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus case 40: switch (token) { case 'u': - parser->stack[++parser->top].state = 51; + parser->stack[++parser->top].state = 50; return 1; default: @@ -700,7 +694,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus case 41: switch (token) { case '_': - parser->stack[++parser->top].state = 52; + parser->stack[++parser->top].state = 51; return 1; default: @@ -711,7 +705,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus case 42: switch (token) { case 'r': - parser->stack[++parser->top].state = 53; + parser->stack[++parser->top].state = 52; return 1; default: @@ -722,7 +716,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus case 43: switch (token) { case 'e': - parser->stack[++parser->top].state = 54; + parser->stack[++parser->top].state = 53; return 1; default: @@ -733,7 +727,7 @@ 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 = 55; + parser->stack[++parser->top].state = 54; return 1; default: @@ -744,7 +738,7 @@ 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 = 56; + parser->stack[++parser->top].state = 55; return 1; default: @@ -755,7 +749,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus case 46: switch (token) { case ')': - parser->stack[++parser->top].state = 57; + parser->stack[++parser->top].state = 56; return 1; default: @@ -767,27 +761,27 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus switch (token) { default: parser->top -= 1; - result.symbol_varname = parse_reduce_25(parser->stack[parser->top + 0].value.token.str, grammar); + 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 50: - parser->stack[++parser->top].state = 58; + case 49: + parser->stack[++parser->top].state = 57; break; - case 55: - parser->stack[++parser->top].state = 63; + case 54: + parser->stack[++parser->top].state = 62; break; - case 70: - parser->stack[++parser->top].state = 72; + case 69: + parser->stack[++parser->top].state = 71; break; - case 71: - parser->stack[++parser->top].state = 73; + case 70: + parser->stack[++parser->top].state = 72; break; } @@ -805,69 +799,34 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus parser->stack[++parser->top].state = 46; break; - case 50: - parser->stack[++parser->top].state = 58; + case 49: + parser->stack[++parser->top].state = 57; break; - case 55: - parser->stack[++parser->top].state = 63; + case 54: + parser->stack[++parser->top].state = 62; break; - case 70: - parser->stack[++parser->top].state = 72; - break; - - case 71: - parser->stack[++parser->top].state = 73; - break; - - } - } - 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 39: - parser->stack[++parser->top].state = 46; - break; - - case 50: - parser->stack[++parser->top].state = 58; - break; - - case 55: - parser->stack[++parser->top].state = 63; + case 69: + parser->stack[++parser->top].state = 71; break; case 70: parser->stack[++parser->top].state = 72; break; - case 71: - parser->stack[++parser->top].state = 73; - break; - } } break; - case 50: + case 49: switch (token) { case TOK_SYMBOL: parser->stack[++parser->top].state = 47; return 1; - case TOK_SYMBOL_LC: - parser->stack[++parser->top].state = 48; - return 1; - case TOK_SYMBOL_UC: - parser->stack[++parser->top].state = 49; + parser->stack[++parser->top].state = 48; return 1; default: @@ -875,10 +834,10 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 51: + case 50: switch (token) { case 'c': - parser->stack[++parser->top].state = 59; + parser->stack[++parser->top].state = 58; return 1; default: @@ -886,10 +845,10 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 52: + case 51: switch (token) { case 'a': - parser->stack[++parser->top].state = 60; + parser->stack[++parser->top].state = 59; return 1; default: @@ -897,10 +856,10 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 53: + case 52: switch (token) { case TOK_BLOCK: - parser->stack[++parser->top].state = 61; + parser->stack[++parser->top].state = 60; return 1; default: @@ -908,10 +867,10 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 54: + case 53: switch (token) { case TOK_BLOCK: - parser->stack[++parser->top].state = 62; + parser->stack[++parser->top].state = 61; return 1; default: @@ -919,18 +878,14 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 55: + case 54: switch (token) { case TOK_SYMBOL: parser->stack[++parser->top].state = 47; return 1; - case TOK_SYMBOL_LC: - parser->stack[++parser->top].state = 48; - return 1; - case TOK_SYMBOL_UC: - parser->stack[++parser->top].state = 49; + parser->stack[++parser->top].state = 48; return 1; default: @@ -938,7 +893,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 56: + case 55: switch (token) { default: parser->top -= 7; @@ -949,7 +904,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 57: + case 56: switch (token) { default: parser->top -= 5; @@ -961,10 +916,10 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 58: + case 57: switch (token) { case ')': - parser->stack[++parser->top].state = 64; + parser->stack[++parser->top].state = 63; return 1; default: @@ -972,10 +927,10 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 59: + case 58: switch (token) { case 't': - parser->stack[++parser->top].state = 65; + parser->stack[++parser->top].state = 64; return 1; default: @@ -983,10 +938,10 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 60: + case 59: switch (token) { case 'r': - parser->stack[++parser->top].state = 66; + parser->stack[++parser->top].state = 65; return 1; default: @@ -994,7 +949,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 61: + case 60: switch (token) { default: parser->top -= 8; @@ -1004,7 +959,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 62: + case 61: switch (token) { default: parser->top -= 8; @@ -1014,7 +969,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 63: + case 62: switch (token) { default: parser->top -= 8; @@ -1026,7 +981,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 64: + case 63: switch (token) { default: parser->top -= 6; @@ -1038,10 +993,10 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 65: + case 64: switch (token) { case 'o': - parser->stack[++parser->top].state = 67; + parser->stack[++parser->top].state = 66; return 1; default: @@ -1049,10 +1004,10 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 66: + case 65: switch (token) { case 'g': - parser->stack[++parser->top].state = 68; + parser->stack[++parser->top].state = 67; return 1; default: @@ -1060,10 +1015,10 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 67: + case 66: switch (token) { case 'r': - parser->stack[++parser->top].state = 69; + parser->stack[++parser->top].state = 68; return 1; default: @@ -1071,10 +1026,10 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 68: + case 67: switch (token) { case TOK_BLOCK: - parser->stack[++parser->top].state = 70; + parser->stack[++parser->top].state = 69; return 1; default: @@ -1082,13 +1037,13 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 69: + case 68: switch (token) { case TOK_CHAR: parser->stack[++parser->top].state = 28; return 1; - case TOK_SYMBOL_LC: + case TOK_SYMBOL: parser->stack[++parser->top].state = 31; return 1; @@ -1101,18 +1056,14 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 70: + case 69: switch (token) { case TOK_SYMBOL: parser->stack[++parser->top].state = 47; return 1; - case TOK_SYMBOL_LC: - parser->stack[++parser->top].state = 48; - return 1; - case TOK_SYMBOL_UC: - parser->stack[++parser->top].state = 49; + parser->stack[++parser->top].state = 48; return 1; default: @@ -1120,18 +1071,14 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 71: + case 70: switch (token) { case TOK_SYMBOL: parser->stack[++parser->top].state = 47; return 1; - case TOK_SYMBOL_LC: - parser->stack[++parser->top].state = 48; - return 1; - case TOK_SYMBOL_UC: - parser->stack[++parser->top].state = 49; + parser->stack[++parser->top].state = 48; return 1; default: @@ -1139,7 +1086,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 72: + case 71: switch (token) { default: parser->top -= 12; @@ -1150,7 +1097,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus } break; - case 73: + case 72: switch (token) { default: parser->top -= 13; diff --git a/src/parse.hpp b/src/parse.hpp index 2d73755..e080ceb 100644 --- a/src/parse.hpp +++ b/src/parse.hpp @@ -10,8 +10,7 @@ typedef enum parse_token { TOK_SQBLOCK = 258, TOK_STRING = 259, TOK_SYMBOL = 260, - TOK_SYMBOL_LC = 261, - TOK_SYMBOL_UC = 262, + TOK_SYMBOL_UC = 261, } parse_token_t; typedef struct parse_token_value { diff --git a/src/parse.y b/src/parse.y index f0ff040..56fc567 100644 --- a/src/parse.y +++ b/src/parse.y @@ -31,9 +31,6 @@ static inline void free_rhs(rhs_t *v) { %type SYMBOL_UC {std::string *} str %destructor SYMBOL_UC free_string -%type SYMBOL_LC {std::string *} str -%destructor SYMBOL_LC free_string - %type BLOCK {std::string *} str %destructor BLOCK free_string @@ -72,7 +69,7 @@ grammar |=; grammar |= grammar directive; -directive |= "%type" SYMBOL_LC(nonterm) BLOCK(type) { +directive |= "%type" SYMBOL(nonterm) BLOCK(type) { grammar->nonterm_types.insert(std::make_pair(*nonterm, *type)); } @@ -107,7 +104,7 @@ directive |= rule(rule) { } -rule |= SYMBOL_LC(lhs) "|=" rhs(rhs) action(action) +rule |= SYMBOL(lhs) "|=" rhs(rhs) action(action) [new solar::rule_t {solar::item_t(*lhs, rhs->first), rhs->second, *action}] @@ -149,12 +146,11 @@ action |= BLOCK(=v) [v] action |= SQBLOCK(v) [new std::string("return " + *v + ";")] -symbol |= SYMBOL_LC(v) [new solar::symbol_t(solar::symbol_t::make_nonterm(*v))] +symbol |= SYMBOL(v) [new solar::symbol_t(solar::symbol_t::make_nonterm(*v))] symbol |= term(=v) [v] term |= SYMBOL_UC(v) [new solar::symbol_t(solar::symbol_t::make_term(*v))] term |= CHAR(v) [new solar::symbol_t(solar::symbol_t::make_char(v))] -varname |= SYMBOL_LC(=v) [v] varname |= SYMBOL_UC(=v) [v] varname |= SYMBOL(=v) [v] |