summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2015-04-18 18:30:02 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2015-04-18 18:30:02 +0200
commita6cf9b0956f68a1e68fbbd1a2716fae3398c2582 (patch)
treec60cb6129569731ca5ff0704a2c1cc0ed7c7a3a4
parent3818c8c5282e14a97ff978d0dc2b114ad0fa6edd (diff)
downloadsolar-a6cf9b0956f68a1e68fbbd1a2716fae3398c2582.tar
solar-a6cf9b0956f68a1e68fbbd1a2716fae3398c2582.zip
Refactor parser rule variable handling
-rw-r--r--src/output_source_slr.cpp2
-rw-r--r--src/parse.cpp375
-rw-r--r--src/parse.y33
3 files changed, 194 insertions, 216 deletions
diff --git a/src/output_source_slr.cpp b/src/output_source_slr.cpp
index 4c82922..420d682 100644
--- a/src/output_source_slr.cpp
+++ b/src/output_source_slr.cpp
@@ -74,7 +74,7 @@ void output_source_slr_t::emit_state_reduce_code(const item_t &item, unsigned ru
write_line_("result.symbol_", item.get_lhs(), " = ", call(reduce_func));
for (unsigned i = 0; i < vars.size(); i++) {
- if (!vars[i].second)
+ if (vars[i].second)
continue;
auto it = get_generator()->get_grammar().destructors.find(rhs[i]);
diff --git a/src/parse.cpp b/src/parse.cpp
index 2b5b9f7..c99ceca 100644
--- a/src/parse.cpp
+++ b/src/parse.cpp
@@ -3,7 +3,8 @@
namespace solar {
-typedef std::vector<std::pair<std::string, bool>> vars_t;
+typedef std::pair<std::string, bool> var_t;
+typedef std::vector<var_t> vars_t;
typedef std::pair<std::vector<solar::symbol_t>, vars_t> rhs_t;
}
@@ -14,11 +15,13 @@ namespace solar {
typedef union parse_symbol_value {
parse_token_value_t token;
std::string *symbol_action;
+ bool symbol_consume;
std::string *symbol_csymbol;
std::vector<std::string> *symbol_namespace;
rhs_t *symbol_rhs;
symbol_t *symbol_symbol;
symbol_t *symbol_term;
+ var_t *symbol_variable;
} parse_symbol_value_t;
typedef struct parse_context_state {
@@ -85,28 +88,14 @@ static inline void parse_reduce_11(std::string *lhs, unsigned char c1, unsigned
static inline rhs_t * parse_reduce_12(__attribute__((unused)) grammar_t *grammar) {return new rhs_t();}
-static inline rhs_t * parse_reduce_13(rhs_t *rhs, symbol_t *sym, __attribute__((unused)) grammar_t *grammar) {
+static inline rhs_t * parse_reduce_13(rhs_t *rhs, symbol_t *sym, var_t *var, __attribute__((unused)) grammar_t *grammar) {
rhs->first.push_back(*sym);
- rhs->second.emplace_back();
+ rhs->second.push_back(*var);
return rhs;
}
-static inline rhs_t * parse_reduce_14(rhs_t *rhs, symbol_t *sym, std::string *var, __attribute__((unused)) grammar_t *grammar) {
- rhs->first.push_back(*sym);
- rhs->second.emplace_back(*var, true);
-
- return rhs;
-}
-
-static inline rhs_t * parse_reduce_15(rhs_t *rhs, symbol_t *sym, std::string *var, __attribute__((unused)) grammar_t *grammar) {
- rhs->first.push_back(*sym);
- rhs->second.emplace_back(*var, false);
-
- return rhs;
-}
-
-static inline rhs_t * parse_reduce_16(rhs_t *rhs, std::string *str, __attribute__((unused)) grammar_t *grammar) {
+static inline rhs_t * parse_reduce_14(rhs_t *rhs, std::string *str, __attribute__((unused)) grammar_t *grammar) {
for (char c : *str) {
rhs->first.push_back(symbol_t::make_char(c));
rhs->second.emplace_back();
@@ -115,30 +104,38 @@ static inline rhs_t * parse_reduce_16(rhs_t *rhs, std::string *str, __attribute_
return rhs;
}
-static inline std::string * parse_reduce_17(__attribute__((unused)) grammar_t *grammar) {return new std::string;}
+static inline var_t * parse_reduce_15(__attribute__((unused)) grammar_t *grammar) {return new var_t;}
+
+static inline var_t * parse_reduce_16(bool consume, std::string *var, __attribute__((unused)) grammar_t *grammar) {return new var_t(*var, consume);}
+
+static inline bool parse_reduce_17(__attribute__((unused)) grammar_t *grammar) {return false;}
+
+static inline bool parse_reduce_18(__attribute__((unused)) grammar_t *grammar) {return true;}
-static inline std::string * parse_reduce_18(std::string *v, __attribute__((unused)) grammar_t *grammar) {return v;}
+static inline std::string * parse_reduce_19(__attribute__((unused)) grammar_t *grammar) {return new std::string;}
-static inline std::string * parse_reduce_19(std::string *v, __attribute__((unused)) grammar_t *grammar) {return new std::string("return " + *v + ";");}
+static inline std::string * parse_reduce_20(std::string *v, __attribute__((unused)) grammar_t *grammar) {return v;}
-static inline std::vector<std::string> * parse_reduce_20(std::string *v, __attribute__((unused)) grammar_t *grammar) {return new std::vector<std::string> {*v};}
+static inline std::string * parse_reduce_21(std::string *v, __attribute__((unused)) grammar_t *grammar) {return new std::string("return " + *v + ";");}
-static inline std::vector<std::string> * parse_reduce_21(std::vector<std::string> *ns, std::string *v, __attribute__((unused)) grammar_t *grammar) {
+static inline std::vector<std::string> * parse_reduce_22(std::string *v, __attribute__((unused)) grammar_t *grammar) {return new std::vector<std::string> {*v};}
+
+static inline std::vector<std::string> * parse_reduce_23(std::vector<std::string> *ns, std::string *v, __attribute__((unused)) grammar_t *grammar) {
ns->push_back(*v);
return ns;
}
-static inline symbol_t * parse_reduce_22(std::string *v, __attribute__((unused)) grammar_t *grammar) {return new symbol_t(symbol_t::make_nonterm(*v));}
+static inline symbol_t * parse_reduce_24(std::string *v, __attribute__((unused)) grammar_t *grammar) {return new symbol_t(symbol_t::make_nonterm(*v));}
-static inline symbol_t * parse_reduce_23(symbol_t *v, __attribute__((unused)) grammar_t *grammar) {return v;}
+static inline symbol_t * parse_reduce_25(symbol_t *v, __attribute__((unused)) grammar_t *grammar) {return v;}
-static inline symbol_t * parse_reduce_24(std::string *v, __attribute__((unused)) grammar_t *grammar) {return new symbol_t(symbol_t::make_term(*v));}
+static inline symbol_t * parse_reduce_26(std::string *v, __attribute__((unused)) grammar_t *grammar) {return new symbol_t(symbol_t::make_term(*v));}
-static inline symbol_t * parse_reduce_25(unsigned char v, __attribute__((unused)) grammar_t *grammar) {return new symbol_t(symbol_t::make_char(v));}
+static inline symbol_t * parse_reduce_27(unsigned char v, __attribute__((unused)) grammar_t *grammar) {return new symbol_t(symbol_t::make_char(v));}
-static inline std::string * parse_reduce_26(std::string *v, __attribute__((unused)) grammar_t *grammar) {return v;}
+static inline std::string * parse_reduce_28(std::string *v, __attribute__((unused)) grammar_t *grammar) {return v;}
-static inline std::string * parse_reduce_27(std::string *v, __attribute__((unused)) grammar_t *grammar) {return v;}
+static inline std::string * parse_reduce_29(std::string *v, __attribute__((unused)) grammar_t *grammar) {return v;}
static int parse_do_push(parse_context_t *parser, int token, __attribute__((unused)) grammar_t *grammar) {
@@ -504,15 +501,13 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus
case 28:
switch (token) {
case '(':
- parser->stack[++parser->top].state = 44;
+ parser->stack[++parser->top].state = 45;
return 1;
default:
- parser->top -= 2;
- result.symbol_rhs = parse_reduce_13(parser->stack[parser->top + 0].value.symbol_rhs, parser->stack[parser->top + 1].value.symbol_symbol, grammar);
- delete(parser->stack[parser->top + 1].value.symbol_symbol);
- parser->stack[parser->top].value.symbol_rhs = result.symbol_rhs;
- parser->stack[++parser->top].state = 19;
+ result.symbol_variable = parse_reduce_15(grammar);
+ parser->stack[parser->top].value.symbol_variable = result.symbol_variable;
+ parser->stack[++parser->top].state = 44;
}
break;
@@ -520,7 +515,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus
switch (token) {
default:
parser->top -= 1;
- result.symbol_symbol = parse_reduce_23(parser->stack[parser->top + 0].value.symbol_term, grammar);
+ result.symbol_symbol = parse_reduce_25(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 19:
@@ -539,7 +534,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus
switch (token) {
default:
parser->top -= 1;
- result.symbol_action = parse_reduce_18(parser->stack[parser->top + 0].value.token.str, grammar);
+ result.symbol_action = parse_reduce_20(parser->stack[parser->top + 0].value.token.str, grammar);
parser->stack[parser->top].value.symbol_action = result.symbol_action;
parser->stack[++parser->top].state = 27;
}
@@ -549,7 +544,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus
switch (token) {
default:
parser->top -= 1;
- result.symbol_term = parse_reduce_25(parser->stack[parser->top + 0].value.token.c, grammar);
+ result.symbol_term = parse_reduce_27(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 19:
@@ -558,7 +553,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus
break;
case 43:
- parser->stack[++parser->top].state = 51;
+ parser->stack[++parser->top].state = 52;
break;
}
@@ -569,7 +564,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus
switch (token) {
default:
parser->top -= 1;
- result.symbol_action = parse_reduce_19(parser->stack[parser->top + 0].value.token.str, grammar);
+ result.symbol_action = parse_reduce_21(parser->stack[parser->top + 0].value.token.str, grammar);
delete(parser->stack[parser->top + 0].value.token.str);
parser->stack[parser->top].value.symbol_action = result.symbol_action;
parser->stack[++parser->top].state = 27;
@@ -580,7 +575,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus
switch (token) {
default:
parser->top -= 2;
- result.symbol_rhs = parse_reduce_16(parser->stack[parser->top + 0].value.symbol_rhs, parser->stack[parser->top + 1].value.token.str, grammar);
+ result.symbol_rhs = parse_reduce_14(parser->stack[parser->top + 0].value.symbol_rhs, parser->stack[parser->top + 1].value.token.str, grammar);
delete(parser->stack[parser->top + 1].value.token.str);
parser->stack[parser->top].value.symbol_rhs = result.symbol_rhs;
parser->stack[++parser->top].state = 19;
@@ -591,7 +586,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus
switch (token) {
default:
parser->top -= 1;
- result.symbol_symbol = parse_reduce_22(parser->stack[parser->top + 0].value.token.str, grammar);
+ result.symbol_symbol = parse_reduce_24(parser->stack[parser->top + 0].value.token.str, grammar);
delete(parser->stack[parser->top + 0].value.token.str);
parser->stack[parser->top].value.symbol_symbol = result.symbol_symbol;
switch (parser->stack[parser->top].state) {
@@ -611,7 +606,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus
switch (token) {
default:
parser->top -= 1;
- result.symbol_term = parse_reduce_24(parser->stack[parser->top + 0].value.token.str, grammar);
+ result.symbol_term = parse_reduce_26(parser->stack[parser->top + 0].value.token.str, grammar);
delete(parser->stack[parser->top + 0].value.token.str);
parser->stack[parser->top].value.symbol_term = result.symbol_term;
switch (parser->stack[parser->top].state) {
@@ -621,7 +616,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus
break;
case 43:
- parser->stack[++parser->top].state = 51;
+ parser->stack[++parser->top].state = 52;
break;
}
@@ -632,7 +627,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus
switch (token) {
default:
parser->top -= 1;
- result.symbol_action = parse_reduce_17(grammar);
+ result.symbol_action = parse_reduce_19(grammar);
parser->stack[parser->top].value.symbol_action = result.symbol_action;
parser->stack[++parser->top].state = 27;
}
@@ -641,7 +636,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus
case 37:
switch (token) {
case '.':
- parser->stack[++parser->top].state = 45;
+ parser->stack[++parser->top].state = 46;
return 1;
default:
@@ -652,7 +647,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus
case 38:
switch (token) {
case 'r':
- parser->stack[++parser->top].state = 46;
+ parser->stack[++parser->top].state = 47;
return 1;
default:
@@ -663,7 +658,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus
case 39:
switch (token) {
case 'a':
- parser->stack[++parser->top].state = 47;
+ parser->stack[++parser->top].state = 48;
return 1;
default:
@@ -674,7 +669,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus
case 40:
switch (token) {
case 'e':
- parser->stack[++parser->top].state = 48;
+ parser->stack[++parser->top].state = 49;
return 1;
default:
@@ -685,7 +680,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus
case 41:
switch (token) {
case 's':
- parser->stack[++parser->top].state = 49;
+ parser->stack[++parser->top].state = 50;
return 1;
default:
@@ -696,7 +691,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus
case 42:
switch (token) {
case 'c':
- parser->stack[++parser->top].state = 50;
+ parser->stack[++parser->top].state = 51;
return 1;
default:
@@ -715,7 +710,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus
return 1;
case TOK_SYMBOL:
- parser->stack[++parser->top].state = 52;
+ parser->stack[++parser->top].state = 53;
return 1;
default:
@@ -725,38 +720,33 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus
case 44:
switch (token) {
- case TOK_SYMBOL:
- parser->stack[++parser->top].state = 54;
- return 1;
-
- case TOK_SYMBOL_UC:
- parser->stack[++parser->top].state = 55;
- return 1;
-
- case '=':
- parser->stack[++parser->top].state = 56;
- return 1;
-
default:
- return -1;
+ parser->top -= 3;
+ result.symbol_rhs = parse_reduce_13(parser->stack[parser->top + 0].value.symbol_rhs, parser->stack[parser->top + 1].value.symbol_symbol, parser->stack[parser->top + 2].value.symbol_variable, grammar);
+ delete(parser->stack[parser->top + 1].value.symbol_symbol);
+ delete(parser->stack[parser->top + 2].value.symbol_variable);
+ parser->stack[parser->top].value.symbol_rhs = result.symbol_rhs;
+ parser->stack[++parser->top].state = 19;
}
break;
case 45:
switch (token) {
- case '.':
- parser->stack[++parser->top].state = 57;
+ case '=':
+ parser->stack[++parser->top].state = 55;
return 1;
default:
- return -1;
+ result.symbol_consume = parse_reduce_17(grammar);
+ parser->stack[parser->top].value.symbol_consume = result.symbol_consume;
+ parser->stack[++parser->top].state = 54;
}
break;
case 46:
switch (token) {
- case 'u':
- parser->stack[++parser->top].state = 58;
+ case '.':
+ parser->stack[++parser->top].state = 56;
return 1;
default:
@@ -766,8 +756,8 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus
case 47:
switch (token) {
- case '_':
- parser->stack[++parser->top].state = 59;
+ case 'u':
+ parser->stack[++parser->top].state = 57;
return 1;
default:
@@ -777,8 +767,8 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus
case 48:
switch (token) {
- case 'r':
- parser->stack[++parser->top].state = 60;
+ case '_':
+ parser->stack[++parser->top].state = 58;
return 1;
default:
@@ -788,8 +778,8 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus
case 49:
switch (token) {
- case 'p':
- parser->stack[++parser->top].state = 61;
+ case 'r':
+ parser->stack[++parser->top].state = 59;
return 1;
default:
@@ -799,8 +789,8 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus
case 50:
switch (token) {
- case 'e':
- parser->stack[++parser->top].state = 62;
+ case 'p':
+ parser->stack[++parser->top].state = 60;
return 1;
default:
@@ -810,8 +800,8 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus
case 51:
switch (token) {
- case TOK_BLOCK:
- parser->stack[++parser->top].state = 63;
+ case 'e':
+ parser->stack[++parser->top].state = 61;
return 1;
default:
@@ -822,7 +812,7 @@ 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 = 64;
+ parser->stack[++parser->top].state = 62;
return 1;
default:
@@ -832,8 +822,8 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus
case 53:
switch (token) {
- case ')':
- parser->stack[++parser->top].state = 65;
+ case TOK_BLOCK:
+ parser->stack[++parser->top].state = 63;
return 1;
default:
@@ -843,40 +833,16 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus
case 54:
switch (token) {
- default:
- parser->top -= 1;
- result.symbol_csymbol = parse_reduce_27(parser->stack[parser->top + 0].value.token.str, grammar);
- parser->stack[parser->top].value.symbol_csymbol = result.symbol_csymbol;
- switch (parser->stack[parser->top].state) {
- case 44:
- parser->stack[++parser->top].state = 53;
- break;
-
- case 56:
- parser->stack[++parser->top].state = 66;
- break;
-
- case 63:
- parser->stack[++parser->top].state = 73;
- break;
-
- case 82:
- parser->stack[++parser->top].state = 86;
- break;
-
- case 85:
- parser->stack[++parser->top].state = 89;
- break;
-
- case 88:
- parser->stack[++parser->top].state = 91;
- break;
+ case TOK_SYMBOL:
+ parser->stack[++parser->top].state = 65;
+ return 1;
- case 92:
- parser->stack[++parser->top].state = 93;
- break;
+ case TOK_SYMBOL_UC:
+ parser->stack[++parser->top].state = 66;
+ return 1;
- }
+ default:
+ return -1;
}
break;
@@ -884,57 +850,13 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus
switch (token) {
default:
parser->top -= 1;
- result.symbol_csymbol = parse_reduce_26(parser->stack[parser->top + 0].value.token.str, grammar);
- parser->stack[parser->top].value.symbol_csymbol = result.symbol_csymbol;
- switch (parser->stack[parser->top].state) {
- case 44:
- parser->stack[++parser->top].state = 53;
- break;
-
- case 56:
- parser->stack[++parser->top].state = 66;
- break;
-
- case 63:
- parser->stack[++parser->top].state = 73;
- break;
-
- case 82:
- parser->stack[++parser->top].state = 86;
- break;
-
- case 85:
- parser->stack[++parser->top].state = 89;
- break;
-
- case 88:
- parser->stack[++parser->top].state = 91;
- break;
-
- case 92:
- parser->stack[++parser->top].state = 93;
- break;
-
- }
- }
- break;
-
- case 56:
- switch (token) {
- case TOK_SYMBOL:
+ result.symbol_consume = parse_reduce_18(grammar);
+ parser->stack[parser->top].value.symbol_consume = result.symbol_consume;
parser->stack[++parser->top].state = 54;
- return 1;
-
- case TOK_SYMBOL_UC:
- parser->stack[++parser->top].state = 55;
- return 1;
-
- default:
- return -1;
}
break;
- case 57:
+ case 56:
switch (token) {
case '.':
parser->stack[++parser->top].state = 67;
@@ -945,7 +867,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus
}
break;
- case 58:
+ case 57:
switch (token) {
case 'c':
parser->stack[++parser->top].state = 68;
@@ -956,7 +878,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus
}
break;
- case 59:
+ case 58:
switch (token) {
case 'a':
parser->stack[++parser->top].state = 69;
@@ -967,7 +889,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus
}
break;
- case 60:
+ case 59:
switch (token) {
case TOK_BLOCK:
parser->stack[++parser->top].state = 70;
@@ -978,7 +900,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus
}
break;
- case 61:
+ case 60:
switch (token) {
case 'a':
parser->stack[++parser->top].state = 71;
@@ -989,7 +911,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus
}
break;
- case 62:
+ case 61:
switch (token) {
case TOK_BLOCK:
parser->stack[++parser->top].state = 72;
@@ -1000,14 +922,14 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus
}
break;
- case 63:
+ case 62:
switch (token) {
case TOK_SYMBOL:
- parser->stack[++parser->top].state = 54;
+ parser->stack[++parser->top].state = 65;
return 1;
case TOK_SYMBOL_UC:
- parser->stack[++parser->top].state = 55;
+ parser->stack[++parser->top].state = 66;
return 1;
default:
@@ -1015,7 +937,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus
}
break;
- case 64:
+ case 63:
switch (token) {
default:
parser->top -= 7;
@@ -1026,26 +948,84 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus
}
break;
+ case 64:
+ switch (token) {
+ case ')':
+ parser->stack[++parser->top].state = 74;
+ return 1;
+
+ default:
+ return -1;
+ }
+ break;
+
case 65:
switch (token) {
default:
- parser->top -= 5;
- result.symbol_rhs = parse_reduce_14(parser->stack[parser->top + 0].value.symbol_rhs, parser->stack[parser->top + 1].value.symbol_symbol, parser->stack[parser->top + 3].value.symbol_csymbol, grammar);
- delete(parser->stack[parser->top + 1].value.symbol_symbol);
- delete(parser->stack[parser->top + 3].value.symbol_csymbol);
- parser->stack[parser->top].value.symbol_rhs = result.symbol_rhs;
- parser->stack[++parser->top].state = 19;
+ parser->top -= 1;
+ result.symbol_csymbol = parse_reduce_29(parser->stack[parser->top + 0].value.token.str, grammar);
+ parser->stack[parser->top].value.symbol_csymbol = result.symbol_csymbol;
+ switch (parser->stack[parser->top].state) {
+ case 54:
+ parser->stack[++parser->top].state = 64;
+ break;
+
+ case 62:
+ parser->stack[++parser->top].state = 73;
+ break;
+
+ case 82:
+ parser->stack[++parser->top].state = 86;
+ break;
+
+ case 85:
+ parser->stack[++parser->top].state = 89;
+ break;
+
+ case 88:
+ parser->stack[++parser->top].state = 91;
+ break;
+
+ case 92:
+ parser->stack[++parser->top].state = 93;
+ break;
+
+ }
}
break;
case 66:
switch (token) {
- case ')':
- parser->stack[++parser->top].state = 74;
- return 1;
-
default:
- return -1;
+ parser->top -= 1;
+ result.symbol_csymbol = parse_reduce_28(parser->stack[parser->top + 0].value.token.str, grammar);
+ parser->stack[parser->top].value.symbol_csymbol = result.symbol_csymbol;
+ switch (parser->stack[parser->top].state) {
+ case 54:
+ parser->stack[++parser->top].state = 64;
+ break;
+
+ case 62:
+ parser->stack[++parser->top].state = 73;
+ break;
+
+ case 82:
+ parser->stack[++parser->top].state = 86;
+ break;
+
+ case 85:
+ parser->stack[++parser->top].state = 89;
+ break;
+
+ case 88:
+ parser->stack[++parser->top].state = 91;
+ break;
+
+ case 92:
+ parser->stack[++parser->top].state = 93;
+ break;
+
+ }
}
break;
@@ -1128,12 +1108,11 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus
case 74:
switch (token) {
default:
- parser->top -= 6;
- result.symbol_rhs = parse_reduce_15(parser->stack[parser->top + 0].value.symbol_rhs, parser->stack[parser->top + 1].value.symbol_symbol, parser->stack[parser->top + 4].value.symbol_csymbol, grammar);
- delete(parser->stack[parser->top + 1].value.symbol_symbol);
- delete(parser->stack[parser->top + 4].value.symbol_csymbol);
- parser->stack[parser->top].value.symbol_rhs = result.symbol_rhs;
- parser->stack[++parser->top].state = 19;
+ parser->top -= 4;
+ result.symbol_variable = parse_reduce_16(parser->stack[parser->top + 1].value.symbol_consume, parser->stack[parser->top + 2].value.symbol_csymbol, grammar);
+ delete(parser->stack[parser->top + 2].value.symbol_csymbol);
+ parser->stack[parser->top].value.symbol_variable = result.symbol_variable;
+ parser->stack[++parser->top].state = 44;
}
break;
@@ -1217,11 +1196,11 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus
case 82:
switch (token) {
case TOK_SYMBOL:
- parser->stack[++parser->top].state = 54;
+ parser->stack[++parser->top].state = 65;
return 1;
case TOK_SYMBOL_UC:
- parser->stack[++parser->top].state = 55;
+ parser->stack[++parser->top].state = 66;
return 1;
default:
@@ -1261,11 +1240,11 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus
case 85:
switch (token) {
case TOK_SYMBOL:
- parser->stack[++parser->top].state = 54;
+ parser->stack[++parser->top].state = 65;
return 1;
case TOK_SYMBOL_UC:
- parser->stack[++parser->top].state = 55;
+ parser->stack[++parser->top].state = 66;
return 1;
default:
@@ -1277,7 +1256,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus
switch (token) {
default:
parser->top -= 1;
- result.symbol_namespace = parse_reduce_20(parser->stack[parser->top + 0].value.symbol_csymbol, grammar);
+ result.symbol_namespace = parse_reduce_22(parser->stack[parser->top + 0].value.symbol_csymbol, grammar);
delete(parser->stack[parser->top + 0].value.symbol_csymbol);
parser->stack[parser->top].value.symbol_namespace = result.symbol_namespace;
parser->stack[++parser->top].state = 87;
@@ -1301,11 +1280,11 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus
case 88:
switch (token) {
case TOK_SYMBOL:
- parser->stack[++parser->top].state = 54;
+ parser->stack[++parser->top].state = 65;
return 1;
case TOK_SYMBOL_UC:
- parser->stack[++parser->top].state = 55;
+ parser->stack[++parser->top].state = 66;
return 1;
default:
@@ -1349,11 +1328,11 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus
case 92:
switch (token) {
case TOK_SYMBOL:
- parser->stack[++parser->top].state = 54;
+ parser->stack[++parser->top].state = 65;
return 1;
case TOK_SYMBOL_UC:
- parser->stack[++parser->top].state = 55;
+ parser->stack[++parser->top].state = 66;
return 1;
default:
@@ -1365,7 +1344,7 @@ static int parse_do_push(parse_context_t *parser, int token, __attribute__((unus
switch (token) {
default:
parser->top -= 4;
- result.symbol_namespace = parse_reduce_21(parser->stack[parser->top + 0].value.symbol_namespace, parser->stack[parser->top + 3].value.symbol_csymbol, grammar);
+ result.symbol_namespace = parse_reduce_23(parser->stack[parser->top + 0].value.symbol_namespace, parser->stack[parser->top + 3].value.symbol_csymbol, grammar);
delete(parser->stack[parser->top + 3].value.symbol_csymbol);
parser->stack[parser->top].value.symbol_namespace = result.symbol_namespace;
parser->stack[++parser->top].state = 87;
diff --git a/src/parse.y b/src/parse.y
index 9e445e7..9959b0b 100644
--- a/src/parse.y
+++ b/src/parse.y
@@ -7,7 +7,8 @@
%source {
namespace solar {
-typedef std::vector<std::pair<std::string, bool>> vars_t;
+typedef std::pair<std::string, bool> var_t;
+typedef std::vector<var_t> vars_t;
typedef std::pair<std::vector<solar::symbol_t>, vars_t> rhs_t;
}
@@ -38,6 +39,9 @@ typedef std::pair<std::vector<solar::symbol_t>, vars_t> rhs_t;
%type rhs {rhs_t *}
%destructor rhs delete
+%type variable {var_t *}
+%destructor variable delete
+
%type action {std::string *}
%destructor action delete
@@ -50,6 +54,8 @@ typedef std::pair<std::vector<solar::symbol_t>, vars_t> rhs_t;
%type csymbol {std::string *}
%destructor csymbol delete
+%type consume {bool}
+
%extra_arg {__attribute__((unused)) grammar_t *} grammar
@@ -100,23 +106,9 @@ directive |= SYMBOL(lhs) "|=" '(' CHAR(c1) "..." CHAR(c2) ')' ';' {
rhs |= [new rhs_t()]
-rhs |= rhs(=rhs) symbol(sym) {
- rhs->first.push_back(*sym);
- rhs->second.emplace_back();
-
- return rhs;
-}
-
-rhs |= rhs(=rhs) symbol(sym) '(' csymbol(var) ')' {
+rhs |= rhs(=rhs) symbol(sym) variable(var) {
rhs->first.push_back(*sym);
- rhs->second.emplace_back(*var, true);
-
- return rhs;
-}
-
-rhs |= rhs(=rhs) symbol(sym) '(' '=' csymbol(var) ')' {
- rhs->first.push_back(*sym);
- rhs->second.emplace_back(*var, false);
+ rhs->second.push_back(*var);
return rhs;
}
@@ -131,6 +123,13 @@ rhs |= rhs(=rhs) STRING(str) {
}
+variable |= [new var_t]
+variable |= '(' consume(consume) csymbol(var) ')' [new var_t(*var, consume)]
+
+consume |= [false]
+consume |= '=' [true]
+
+
action |= ';' [new std::string]
action |= BLOCK(=v) [v]
action |= SQBLOCK(v) [new std::string("return " + *v + ";")]