skeletons: add support for %code epilogue

When building the test cases, emitting code in the epilogue is very
constraining.  Let's make it simpler thanks to %code epilogue.

However, I don't want to document this: it is bad style to use it (we
should avoid having too many ways to write the same thing,
TI!MTOWTDI), just put your code in the true epilogue section.

* data/skeletons/glr.c, data/skeletons/lalr1.d, data/skeletons/lalr1.java,
* data/skeletons/yacc.c: Implement support for %code epilogue.
Remove useless comments.
* tests/calc.at, tests/java.at: Simplify.
This commit is contained in:
Akim Demaille
2020-02-01 08:38:53 +01:00
parent 493359b758
commit 0774b2c6e3
6 changed files with 13 additions and 19 deletions

View File

@@ -2720,5 +2720,6 @@ m4_if(b4_prefix, [yy], [],
#define yynerrs ]b4_prefix[nerrs]b4_locations_if([[ #define yynerrs ]b4_prefix[nerrs]b4_locations_if([[
#define yylloc ]b4_prefix[lloc]])])[ #define yylloc ]b4_prefix[lloc]])])[
]b4_epilogue[]dnl ]b4_percent_code_get([[epilogue]])[]dnl
b4_epilogue[]dnl
b4_output_end b4_output_end

View File

@@ -902,9 +902,8 @@ m4_popdef([b4_at_dollar])])dnl
stream.writeln (); stream.writeln ();
}]])[ }]])[
} }
/* User implementation code. */
]b4_percent_code_get[ ]b4_percent_code_get[
} }
]b4_epilogue[]dnl ]b4_percent_code_get([[epilogue]])[]dnl
b4_epilogue[]dnl
b4_output_end b4_output_end

View File

@@ -1036,10 +1036,8 @@ b4_dollar_popdef[]dnl
private static final int yyfinal_ = ]b4_final_state_number[; private static final int yyfinal_ = ]b4_final_state_number[;
private static final int yyntokens_ = ]b4_tokens_number[; private static final int yyntokens_ = ]b4_tokens_number[;
/* User implementation code. */ ]b4_percent_code_get[
]b4_percent_code_get[]dnl
} }
]b4_percent_code_get([[epilogue]])[]dnl
b4_epilogue[]dnl b4_epilogue[]dnl
b4_output_end b4_output_end

View File

@@ -2065,5 +2065,6 @@ yypushreturn:]])[
YYSTACK_FREE (yymsg);]])[ YYSTACK_FREE (yymsg);]])[
return yyresult; return yyresult;
} }
]b4_epilogue[]dnl ]b4_percent_code_get([[epilogue]])[]dnl
b4_epilogue[]dnl
b4_output_end b4_output_end

View File

@@ -25,6 +25,7 @@
m4_pushdef([AT_CALC_MAIN], [AT_LANG_DISPATCH([$0], $@)]) m4_pushdef([AT_CALC_MAIN], [AT_LANG_DISPATCH([$0], $@)])
# Whether token translation is supported.
m4_pushdef([AT_TOKEN_TRANSLATE_IF], m4_pushdef([AT_TOKEN_TRANSLATE_IF],
[AT_ERROR_CUSTOM_IF([$1], [AT_ERROR_DETAILED_IF([$1], [$2])])]) [AT_ERROR_CUSTOM_IF([$1], [AT_ERROR_DETAILED_IF([$1], [$2])])])

View File

@@ -117,13 +117,8 @@ exp:
| '-' error { $$ = new Integer (0); return YYERROR; } | '-' error { $$ = new Integer (0); return YYERROR; }
; ;
]AT_LEXPARAM_IF([[ ]AT_LEXPARAM_IF([[%code lexer {]],
%code lexer { [[%code epilogue { class CalcLexer implements Calc.Lexer {]])[
]],
[[
%%
class CalcLexer implements Calc.Lexer {
]])[
StreamTokenizer st; StreamTokenizer st;
public ]AT_LEXPARAM_IF([[YYLexer]], [[CalcLexer]])[ (InputStream is) public ]AT_LEXPARAM_IF([[YYLexer]], [[CalcLexer]])[ (InputStream is)
@@ -176,10 +171,9 @@ class CalcLexer implements Calc.Lexer {
else else
return st.ttype; return st.ttype;
} }
]AT_LEXPARAM_IF([[ ]AT_LEXPARAM_IF([], [[}]])[
}; };
%%]], [[ %%
}]])[
]AT_JAVA_POSITION_DEFINE[ ]AT_JAVA_POSITION_DEFINE[
]]) ]])
])# _AT_DATA_JAVA_CALC_Y ])# _AT_DATA_JAVA_CALC_Y