summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/output.cpp19
-rw-r--r--src/output_lr0.cpp1
-rw-r--r--src/output_slr.cpp1
-rw-r--r--src/parse.cpp65
4 files changed, 28 insertions, 58 deletions
diff --git a/src/output.cpp b/src/output.cpp
index cfefbbb..1503c38 100644
--- a/src/output.cpp
+++ b/src/output.cpp
@@ -302,7 +302,7 @@ void output_t::emit_source() {
emit_reductions();
- std::fprintf(source_file, "int %spush(%scontext_t *parser, int token, const %stoken_value_t *value", prefix(), prefix(), prefix());
+ std::fprintf(source_file, "static int %sdo_push(%scontext_t *parser, int token", prefix(), prefix());
for (const auto &arg : get_generator()->get_grammar().extra_args)
std::fprintf(source_file, ", %s %s", arg.first.c_str(), arg.second.c_str());
std::fprintf(source_file, ") {\n");
@@ -314,6 +314,23 @@ void output_t::emit_source() {
std::fprintf(source_file, "\t\t}\n");
std::fprintf(source_file, "\t}\n");
+ std::fprintf(source_file, "}\n\n");
+
+ std::fprintf(source_file, "int %spush(%scontext_t *parser, int token, const %stoken_value_t *value", prefix(), prefix(), prefix());
+ for (const auto &arg : get_generator()->get_grammar().extra_args)
+ std::fprintf(source_file, ", %s %s", arg.first.c_str(), arg.second.c_str());
+ std::fprintf(source_file, ") {\n");
+
+ std::fprintf(source_file, "\tint ret = %sdo_push(parser, token", prefix());
+ for (const auto &arg : get_generator()->get_grammar().extra_args)
+ std::fprintf(source_file, ", %s", arg.second.c_str());
+ std::fprintf(source_file, ");\n\n");
+
+ std::fprintf(source_file, "\tif (ret > 0)\n");
+ std::fprintf(source_file, "\t\tparser->stack[parser->top-1].value.token = *value;\n\n");
+
+ std::fprintf(source_file, "\treturn ret;\n");
+
std::fprintf(source_file, "}\n");
}
diff --git a/src/output_lr0.cpp b/src/output_lr0.cpp
index 9d4897e..62c5966 100644
--- a/src/output_lr0.cpp
+++ b/src/output_lr0.cpp
@@ -43,7 +43,6 @@ void output_lr0_t::emit_state_shift(unsigned state) {
continue;
std::fprintf(source_file, "\t\t\tcase %s:\n", symbol_case(token).c_str());
- std::fprintf(source_file, "\t\t\t\tparser->stack[parser->top].value.token = *value;\n");
std::fprintf(source_file, "\t\t\t\tparser->stack[++parser->top].state = %u;\n", unsigned(it->second));
std::fprintf(source_file, "\t\t\t\treturn 1;\n\n");
}
diff --git a/src/output_slr.cpp b/src/output_slr.cpp
index a58c331..1acd951 100644
--- a/src/output_slr.cpp
+++ b/src/output_slr.cpp
@@ -45,7 +45,6 @@ void output_slr_t::emit_state_shift(unsigned state) {
for (const symbol_t &sym : entry.second)
std::fprintf(source_file, "\t\t\tcase %s:\n", symbol_case(sym).c_str());
- std::fprintf(source_file, "\t\t\t\tparser->stack[parser->top].value.token = *value;\n");
std::fprintf(source_file, "\t\t\t\tparser->stack[++parser->top].state = %u;\n", entry.first);
std::fprintf(source_file, "\t\t\t\treturn 1;\n\n");
}
diff --git a/src/parse.cpp b/src/parse.cpp
index bca53dc..afeafda 100644
--- a/src/parse.cpp
+++ b/src/parse.cpp
@@ -158,7 +158,7 @@ static inline std::string * parse_reduce_22(std::string * v, __attribute__((unus
return v;
}
-int parse_push(parse_context_t *parser, int token, const parse_token_value_t *value, __attribute__((unused)) solar::grammar_t * grammar) {
+static int parse_do_push(parse_context_t *parser, int token, __attribute__((unused)) solar::grammar_t * grammar) {
while (1) {
switch (parser->stack[parser->top].state) {
case 0:
@@ -174,12 +174,10 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va
return 0;
case TOK_SYMBOL_LC:
- parser->stack[parser->top].value.token = *value;
parser->stack[++parser->top].state = 4;
return 1;
case '%':
- parser->stack[parser->top].value.token = *value;
parser->stack[++parser->top].state = 5;
return 1;
@@ -208,7 +206,6 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va
case 4:
switch (token) {
case '|':
- parser->stack[parser->top].value.token = *value;
parser->stack[++parser->top].state = 6;
return 1;
@@ -220,22 +217,18 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va
case 5:
switch (token) {
case 'e':
- parser->stack[parser->top].value.token = *value;
parser->stack[++parser->top].state = 7;
return 1;
case 'h':
- parser->stack[parser->top].value.token = *value;
parser->stack[++parser->top].state = 8;
return 1;
case 's':
- parser->stack[parser->top].value.token = *value;
parser->stack[++parser->top].state = 9;
return 1;
case 't':
- parser->stack[parser->top].value.token = *value;
parser->stack[++parser->top].state = 10;
return 1;
@@ -247,7 +240,6 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va
case 6:
switch (token) {
case '=':
- parser->stack[parser->top].value.token = *value;
parser->stack[++parser->top].state = 11;
return 1;
@@ -259,7 +251,6 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va
case 7:
switch (token) {
case 'x':
- parser->stack[parser->top].value.token = *value;
parser->stack[++parser->top].state = 12;
return 1;
@@ -271,7 +262,6 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va
case 8:
switch (token) {
case 'e':
- parser->stack[parser->top].value.token = *value;
parser->stack[++parser->top].state = 13;
return 1;
@@ -283,7 +273,6 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va
case 9:
switch (token) {
case 'o':
- parser->stack[parser->top].value.token = *value;
parser->stack[++parser->top].state = 14;
return 1;
@@ -295,7 +284,6 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va
case 10:
switch (token) {
case 'y':
- parser->stack[parser->top].value.token = *value;
parser->stack[++parser->top].state = 15;
return 1;
@@ -315,7 +303,6 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va
case 12:
switch (token) {
case 't':
- parser->stack[parser->top].value.token = *value;
parser->stack[++parser->top].state = 17;
return 1;
@@ -327,7 +314,6 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va
case 13:
switch (token) {
case 'a':
- parser->stack[parser->top].value.token = *value;
parser->stack[++parser->top].state = 18;
return 1;
@@ -339,7 +325,6 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va
case 14:
switch (token) {
case 'u':
- parser->stack[parser->top].value.token = *value;
parser->stack[++parser->top].state = 19;
return 1;
@@ -351,7 +336,6 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va
case 15:
switch (token) {
case 'p':
- parser->stack[parser->top].value.token = *value;
parser->stack[++parser->top].state = 20;
return 1;
@@ -363,32 +347,26 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va
case 16:
switch (token) {
case TOK_BLOCK:
- parser->stack[parser->top].value.token = *value;
parser->stack[++parser->top].state = 24;
return 1;
case TOK_CHAR:
- parser->stack[parser->top].value.token = *value;
parser->stack[++parser->top].state = 25;
return 1;
case TOK_STRING:
- parser->stack[parser->top].value.token = *value;
parser->stack[++parser->top].state = 26;
return 1;
case TOK_SYMBOL_LC:
- parser->stack[parser->top].value.token = *value;
parser->stack[++parser->top].state = 27;
return 1;
case TOK_SYMBOL_UC:
- parser->stack[parser->top].value.token = *value;
parser->stack[++parser->top].state = 28;
return 1;
case ';':
- parser->stack[parser->top].value.token = *value;
parser->stack[++parser->top].state = 29;
return 1;
@@ -400,7 +378,6 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va
case 17:
switch (token) {
case 'r':
- parser->stack[parser->top].value.token = *value;
parser->stack[++parser->top].state = 30;
return 1;
@@ -412,7 +389,6 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va
case 18:
switch (token) {
case 'd':
- parser->stack[parser->top].value.token = *value;
parser->stack[++parser->top].state = 31;
return 1;
@@ -424,7 +400,6 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va
case 19:
switch (token) {
case 'r':
- parser->stack[parser->top].value.token = *value;
parser->stack[++parser->top].state = 32;
return 1;
@@ -436,7 +411,6 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va
case 20:
switch (token) {
case 'e':
- parser->stack[parser->top].value.token = *value;
parser->stack[++parser->top].state = 33;
return 1;
@@ -457,7 +431,6 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va
case 22:
switch (token) {
case '(':
- parser->stack[parser->top].value.token = *value;
parser->stack[++parser->top].state = 34;
return 1;
@@ -552,7 +525,6 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va
case 30:
switch (token) {
case 'a':
- parser->stack[parser->top].value.token = *value;
parser->stack[++parser->top].state = 35;
return 1;
@@ -564,7 +536,6 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va
case 31:
switch (token) {
case 'e':
- parser->stack[parser->top].value.token = *value;
parser->stack[++parser->top].state = 36;
return 1;
@@ -576,7 +547,6 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va
case 32:
switch (token) {
case 'c':
- parser->stack[parser->top].value.token = *value;
parser->stack[++parser->top].state = 37;
return 1;
@@ -588,17 +558,14 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va
case 33:
switch (token) {
case TOK_CHAR:
- parser->stack[parser->top].value.token = *value;
parser->stack[++parser->top].state = 25;
return 1;
case TOK_SYMBOL_UC:
- parser->stack[parser->top].value.token = *value;
parser->stack[++parser->top].state = 28;
return 1;
case TOK_SYMBOL_LC:
- parser->stack[parser->top].value.token = *value;
parser->stack[++parser->top].state = 39;
return 1;
@@ -610,17 +577,14 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va
case 34:
switch (token) {
case TOK_SYMBOL:
- parser->stack[parser->top].value.token = *value;
parser->stack[++parser->top].state = 41;
return 1;
case TOK_SYMBOL_LC:
- parser->stack[parser->top].value.token = *value;
parser->stack[++parser->top].state = 42;
return 1;
case TOK_SYMBOL_UC:
- parser->stack[parser->top].value.token = *value;
parser->stack[++parser->top].state = 43;
return 1;
@@ -632,7 +596,6 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va
case 35:
switch (token) {
case '_':
- parser->stack[parser->top].value.token = *value;
parser->stack[++parser->top].state = 44;
return 1;
@@ -644,7 +607,6 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va
case 36:
switch (token) {
case 'r':
- parser->stack[parser->top].value.token = *value;
parser->stack[++parser->top].state = 45;
return 1;
@@ -656,7 +618,6 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va
case 37:
switch (token) {
case 'e':
- parser->stack[parser->top].value.token = *value;
parser->stack[++parser->top].state = 46;
return 1;
@@ -668,7 +629,6 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va
case 38:
switch (token) {
case TOK_BLOCK:
- parser->stack[parser->top].value.token = *value;
parser->stack[++parser->top].state = 47;
return 1;
@@ -680,7 +640,6 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va
case 39:
switch (token) {
case TOK_BLOCK:
- parser->stack[parser->top].value.token = *value;
parser->stack[++parser->top].state = 48;
return 1;
@@ -692,7 +651,6 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va
case 40:
switch (token) {
case ')':
- parser->stack[parser->top].value.token = *value;
parser->stack[++parser->top].state = 49;
return 1;
@@ -770,7 +728,6 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va
case 44:
switch (token) {
case 'a':
- parser->stack[parser->top].value.token = *value;
parser->stack[++parser->top].state = 50;
return 1;
@@ -782,7 +739,6 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va
case 45:
switch (token) {
case TOK_BLOCK:
- parser->stack[parser->top].value.token = *value;
parser->stack[++parser->top].state = 51;
return 1;
@@ -794,7 +750,6 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va
case 46:
switch (token) {
case TOK_BLOCK:
- parser->stack[parser->top].value.token = *value;
parser->stack[++parser->top].state = 52;
return 1;
@@ -806,17 +761,14 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va
case 47:
switch (token) {
case TOK_SYMBOL:
- parser->stack[parser->top].value.token = *value;
parser->stack[++parser->top].state = 41;
return 1;
case TOK_SYMBOL_LC:
- parser->stack[parser->top].value.token = *value;
parser->stack[++parser->top].state = 42;
return 1;
case TOK_SYMBOL_UC:
- parser->stack[parser->top].value.token = *value;
parser->stack[++parser->top].state = 43;
return 1;
@@ -846,7 +798,6 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va
case 50:
switch (token) {
case 'r':
- parser->stack[parser->top].value.token = *value;
parser->stack[++parser->top].state = 54;
return 1;
@@ -885,7 +836,6 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va
case 54:
switch (token) {
case 'g':
- parser->stack[parser->top].value.token = *value;
parser->stack[++parser->top].state = 55;
return 1;
@@ -897,7 +847,6 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va
case 55:
switch (token) {
case TOK_BLOCK:
- parser->stack[parser->top].value.token = *value;
parser->stack[++parser->top].state = 56;
return 1;
@@ -909,17 +858,14 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va
case 56:
switch (token) {
case TOK_SYMBOL:
- parser->stack[parser->top].value.token = *value;
parser->stack[++parser->top].state = 41;
return 1;
case TOK_SYMBOL_LC:
- parser->stack[parser->top].value.token = *value;
parser->stack[++parser->top].state = 42;
return 1;
case TOK_SYMBOL_UC:
- parser->stack[parser->top].value.token = *value;
parser->stack[++parser->top].state = 43;
return 1;
@@ -940,3 +886,12 @@ int parse_push(parse_context_t *parser, int token, const parse_token_value_t *va
}
}
}
+
+int parse_push(parse_context_t *parser, int token, const parse_token_value_t *value, __attribute__((unused)) solar::grammar_t * grammar) {
+ int ret = parse_do_push(parser, token, grammar);
+
+ if (ret > 0)
+ parser->stack[parser->top-1].value.token = *value;
+
+ return ret;
+}