# --------------------------
# Join two lists with a comma if necessary.
m4_define([b4_list2],
- [$1[]m4_ifval(m4_quote($1), [m4_ifval(m4_quote($2), [[, ]])])[]$2])
+ [$1[]m4_ifval(m4_quote($1), [m4_ifval(m4_quote($2), [[, ]])])[]$2])
# b4_percent_define_get3(DEF, PRE, POST, NOT)
# Expand to the value of DEF surrounded by PRE and POST if it's %define'ed,
# otherwise NOT.
m4_define([b4_percent_define_get3],
- [m4_ifval(m4_quote(b4_percent_define_get([$1])),
- [$2[]b4_percent_define_get([$1])[]$3], [$4])])
+ [m4_ifval(m4_quote(b4_percent_define_get([$1])),
+ [$2[]b4_percent_define_get([$1])[]$3], [$4])])
m4_define([b4_int_type],
[m4_if(b4_ints_in($@, [-128], [127]), [1], [byte],
b4_ints_in($@, [-32768], [32767]), [1], [short],
- [int])])
+ [int])])
# b4_int_type_for(NAME)
# ---------------------
m4_define([b4_lex_param_decl],
[m4_ifset([b4_lex_param],
[b4_remove_comma([$1],
- b4_param_decls(b4_lex_param))],
- [$1])])
+ b4_param_decls(b4_lex_param))],
+ [$1])])
m4_define([b4_param_decls],
- [m4_map([b4_param_decl], [$@])])
+ [m4_map([b4_param_decl], [$@])])
m4_define([b4_param_decl], [, $1])
m4_define([b4_remove_comma], [m4_ifval(m4_quote($1), [$1, ], [])m4_shift2($@)])
m4_define([b4_parse_param_decl],
[m4_ifset([b4_parse_param],
[b4_remove_comma([$1],
- b4_param_decls(b4_parse_param))],
- [$1])])
+ b4_param_decls(b4_parse_param))],
+ [$1])])
# Delegating the lexer parameters to the lexer constructor.
m4_define([b4_lex_param_call],
[m4_ifset([b4_lex_param],
- [b4_remove_comma([$1],
- b4_param_calls(b4_lex_param))],
- [$1])])
+ [b4_remove_comma([$1],
+ b4_param_calls(b4_lex_param))],
+ [$1])])
m4_define([b4_param_calls],
- [m4_map([b4_param_call], [$@])])
+ [m4_map([b4_param_call], [$@])])
m4_define([b4_param_call], [, $2])
# Extra initialisations of the constructor.
m4_define([b4_parse_param_cons],
[m4_ifset([b4_parse_param],
- [b4_constructor_calls(b4_parse_param)])])
+ [b4_constructor_calls(b4_parse_param)])])
m4_define([b4_constructor_calls],
- [m4_map([b4_constructor_call], [$@])])
+ [m4_map([b4_constructor_call], [$@])])
m4_define([b4_constructor_call],
- [this.$2 = $2;
- ])
+ [this.$2 = $2;
+ ])
# Extra instance variables.
m4_define([b4_parse_param_vars],
[m4_ifset([b4_parse_param],
- [
+ [
/* User arguments. */
b4_var_decls(b4_parse_param)])])
m4_define([b4_var_decls],
- [m4_map_sep([b4_var_decl], [
+ [m4_map_sep([b4_var_decl], [
], [$@])])
m4_define([b4_var_decl],
- [ protected final $1;])
+ [ protected final $1;])
# -----------------------
# Expand to either an empty string or "throws THROWS".
m4_define([b4_maybe_throws],
- [m4_ifval($1, [throws $1])])
+ [m4_ifval($1, [throws $1])])
public int height = -1;
public final void push (int state, ]b4_yystype[ value]dnl
- b4_locations_if([, ]b4_location_type[ loc])[) {
+ b4_locations_if([, ]b4_location_type[ loc])[) {
height++;
if (size == height)
{
- int[] newStateStack = new int[size * 2];
- System.arraycopy (stateStack, 0, newStateStack, 0, height);
- stateStack = newStateStack;
- ]b4_locations_if([[
- ]b4_location_type[[] newLocStack = new ]b4_location_type[[size * 2];
- System.arraycopy (locStack, 0, newLocStack, 0, height);
- locStack = newLocStack;]])
-
- b4_yystype[[] newValueStack = new ]b4_yystype[[size * 2];
- System.arraycopy (valueStack, 0, newValueStack, 0, height);
- valueStack = newValueStack;
-
- size *= 2;
- }
+ int[] newStateStack = new int[size * 2];
+ System.arraycopy (stateStack, 0, newStateStack, 0, height);
+ stateStack = newStateStack;
+ ]b4_locations_if([[
+ ]b4_location_type[[] newLocStack = new ]b4_location_type[[size * 2];
+ System.arraycopy (locStack, 0, newLocStack, 0, height);
+ locStack = newLocStack;]])
+
+ b4_yystype[[] newValueStack = new ]b4_yystype[[size * 2];
+ System.arraycopy (valueStack, 0, newValueStack, 0, height);
+ valueStack = newValueStack;
+
+ size *= 2;
+ }
stateStack[height] = state;
]b4_locations_if([[locStack[height] = loc;]])[
public final void pop (int num) {
// Avoid memory leaks... garbage collection is a white lie!
if (num > 0) {
- java.util.Arrays.fill (valueStack, height - num + 1, height, null);
+ java.util.Arrays.fill (valueStack, height - num + 1, height, null);
]b4_locations_if([[java.util.Arrays.fill (locStack, height - num + 1, height, null);]])[
}
height -= num;
for (int i = 0; i < height; i++)
{
- out.print (' ');
- out.print (stateStack[i]);
+ out.print (' ');
+ out.print (stateStack[i]);
}
out.println ();
}
switch (yyn)
{
- ]b4_user_actions[
- default: break;
+ ]b4_user_actions[
+ default: break;
}
yy_symbol_print ("-> $$ =", yyr1_[yyn], yyval]b4_locations_if([, yyloc])[);
yyn = yyr1_[yyn];
int yystate = yypgoto_[yyn - yyntokens_] + yystack.stateAt (0);
if (0 <= yystate && yystate <= yylast_
- && yycheck_[yystate] == yystack.stateAt (0))
+ && yycheck_[yystate] == yystack.stateAt (0))
yystate = yytable_[yystate];
else
yystate = yydefgoto_[yyn - yyntokens_];
break strip_quotes;
case '\\':
- if (yystr.charAt(++i) != '\\')
+ if (yystr.charAt(++i) != '\\')
break strip_quotes;
/* Fall through. */
default:
`--------------------------------*/
private void yy_symbol_print (String s, int yytype,
- ]b4_yystype[ yyvaluep]dnl
- b4_locations_if([, Object yylocationp])[)
+ ]b4_yystype[ yyvaluep]dnl
+ b4_locations_if([, Object yylocationp])[)
{
if (yydebug > 0)
yycdebug (s + (yytype < yyntokens_ ? " token " : " nterm ")
- + yytname_[yytype] + " ("]b4_locations_if([
- + yylocationp + ": "])[
- + (yyvaluep == null ? "(null)" : yyvaluep.toString ()) + ")");
+ + yytname_[yytype] + " ("]b4_locations_if([
+ + yylocationp + ": "])[
+ + (yyvaluep == null ? "(null)" : yyvaluep.toString ()) + ")");
}
/**
switch (label)
{
/* New state. Unlike in the C/C++ skeletons, the state is already
- pushed when we come here. */
+ pushed when we come here. */
case YYNEWSTATE:
yycdebug ("Entering state " + yystate + "\n");
if (yydebug > 0)
if (yyn == yypact_ninf_)
{
label = YYDEFAULT;
- break;
+ break;
}
/* Read a lookahead token. */
}
else
{
- yytoken = yytranslate_ (yychar);
- yy_symbol_print ("Next token is", yytoken,
- yylval]b4_locations_if([, yylloc])[);
+ yytoken = yytranslate_ (yychar);
+ yy_symbol_print ("Next token is", yytoken,
+ yylval]b4_locations_if([, yylloc])[);
}
/* If the proper action on seeing token YYTOKEN is to reduce or to
/* <= 0 means reduce or error. */
else if ((yyn = yytable_[yyn]) <= 0)
{
- if (yyn == 0 || yyn == yytable_ninf_)
- label = YYFAIL;
- else
- {
- yyn = -yyn;
- label = YYREDUCE;
- }
+ if (yyn == 0 || yyn == yytable_ninf_)
+ label = YYFAIL;
+ else
+ {
+ yyn = -yyn;
+ label = YYREDUCE;
+ }
}
else
{
/* Shift the lookahead token. */
- yy_symbol_print ("Shifting", yytoken,
- yylval]b4_locations_if([, yylloc])[);
+ yy_symbol_print ("Shifting", yytoken,
+ yylval]b4_locations_if([, yylloc])[);
/* Discard the token being shifted. */
yychar = yyempty_;
case YYREDUCE:
yylen = yyr2_[yyn];
label = yyaction (yyn, yystack, yylen);
- yystate = yystack.stateAt (0);
+ yystate = yystack.stateAt (0);
break;
/*------------------------------------.
/* If not already recovering from an error, report this error. */
if (yyerrstatus_ == 0)
{
- ++yynerrs_;
- yyerror (]b4_locations_if([yylloc, ])[yysyntax_error (yystate, yytoken));
+ ++yynerrs_;
+ yyerror (]b4_locations_if([yylloc, ])[yysyntax_error (yystate, yytoken));
}
]b4_locations_if([yyerrloc = yylloc;])[
return false;
}
else
- yychar = yyempty_;
+ yychar = yyempty_;
}
/* Else will try to reuse lookahead token after shifting the error
| yyerrlab1 -- common code for both syntax error and YYERROR. |
`-------------------------------------------------------------*/
case YYERRLAB1:
- yyerrstatus_ = 3; /* Each real token shifted decrements this. */
+ yyerrstatus_ = 3; /* Each real token shifted decrements this. */
for (;;)
{
- yyn = yypact_[yystate];
- if (yyn != yypact_ninf_)
- {
- yyn += yyterror_;
- if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_)
- {
- yyn = yytable_[yyn];
- if (0 < yyn)
- break;
- }
- }
-
- /* Pop the current state because it cannot handle the error token. */
- if (yystack.height == 1)
- return false;
-
- ]b4_locations_if([yyerrloc = yystack.locationAt (0);])[
- yystack.pop ();
- yystate = yystack.stateAt (0);
- if (yydebug > 0)
- yystack.print (yyDebugStream);
+ yyn = yypact_[yystate];
+ if (yyn != yypact_ninf_)
+ {
+ yyn += yyterror_;
+ if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_)
+ {
+ yyn = yytable_[yyn];
+ if (0 < yyn)
+ break;
+ }
+ }
+
+ /* Pop the current state because it cannot handle the error token. */
+ if (yystack.height == 1)
+ return false;
+
+ ]b4_locations_if([yyerrloc = yystack.locationAt (0);])[
+ yystack.pop ();
+ yystate = yystack.stateAt (0);
+ if (yydebug > 0)
+ yystack.print (yyDebugStream);
}
- ]b4_locations_if([
- /* Muck with the stack to setup for yylloc. */
- yystack.push (0, null, yylloc);
- yystack.push (0, null, yyerrloc);
+ ]b4_locations_if([
+ /* Muck with the stack to setup for yylloc. */
+ yystack.push (0, null, yylloc);
+ yystack.push (0, null, yyerrloc);
yyloc = yylloc (yystack, 2);
- yystack.pop (2);])[
+ yystack.pop (2);])[
/* Shift the error token. */
yy_symbol_print ("Shifting", yystos_[yyn],
- yylval]b4_locations_if([, yyloc])[);
+ yylval]b4_locations_if([, yyloc])[);
yystate = yyn;
- yystack.push (yyn, yylval]b4_locations_if([, yyloc])[);
+ yystack.push (yyn, yylval]b4_locations_if([, yyloc])[);
label = YYNEWSTATE;
break;
int yyn = yypact_[yystate];
if (yypact_ninf_ < yyn && yyn <= yylast_)
{
- StringBuffer res;
-
- /* Start YYX at -YYN if negative to avoid negative indexes in
- YYCHECK. */
- int yyxbegin = yyn < 0 ? -yyn : 0;
-
- /* Stay within bounds of both yycheck and yytname. */
- int yychecklim = yylast_ - yyn + 1;
- int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_;
- int count = 0;
- for (int x = yyxbegin; x < yyxend; ++x)
- if (yycheck_[x + yyn] == x && x != yyterror_)
- ++count;
-
- // FIXME: This method of building the message is not compatible
- // with internationalization.
- res = new StringBuffer ("syntax error, unexpected ");
- res.append (yytnamerr_ (yytname_[tok]));
- if (count < 5)
- {
- count = 0;
- for (int x = yyxbegin; x < yyxend; ++x)
- if (yycheck_[x + yyn] == x && x != yyterror_)
- {
- res.append (count++ == 0 ? ", expecting " : " or ");
- res.append (yytnamerr_ (yytname_[x]));
- }
- }
+ StringBuffer res;
+
+ /* Start YYX at -YYN if negative to avoid negative indexes in
+ YYCHECK. */
+ int yyxbegin = yyn < 0 ? -yyn : 0;
+
+ /* Stay within bounds of both yycheck and yytname. */
+ int yychecklim = yylast_ - yyn + 1;
+ int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_;
+ int count = 0;
+ for (int x = yyxbegin; x < yyxend; ++x)
+ if (yycheck_[x + yyn] == x && x != yyterror_)
+ ++count;
+
+ // FIXME: This method of building the message is not compatible
+ // with internationalization.
+ res = new StringBuffer ("syntax error, unexpected ");
+ res.append (yytnamerr_ (yytname_[tok]));
+ if (count < 5)
+ {
+ count = 0;
+ for (int x = yyxbegin; x < yyxend; ++x)
+ if (yycheck_[x + yyn] == x && x != yyterror_)
+ {
+ res.append (count++ == 0 ? ", expecting " : " or ");
+ res.append (yytnamerr_ (yytname_[x]));
+ }
+ }
return res.toString ();
}
}
int yynrhs = yyr2_[yyrule];
/* Print the symbols being reduced, and their result. */
yycdebug ("Reducing stack by rule " + (yyrule - 1)
- + " (line " + yylno + "), ");
+ + " (line " + yylno + "), ");
/* The symbols being reduced. */
for (int yyi = 0; yyi < yynrhs; yyi++)
yy_symbol_print (" $" + (yyi + 1) + " =",
- yyrhs_[yyprhs_[yyrule] + yyi],
- ]b4_rhs_value(yynrhs, yyi + 1)b4_locations_if([,
- b4_rhs_location(yynrhs, yyi + 1)])[);
+ yyrhs_[yyprhs_[yyrule] + yyi],
+ ]b4_rhs_value(yynrhs, yyi + 1)b4_locations_if([,
+ b4_rhs_location(yynrhs, yyi + 1)])[);
}
/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
]], [[
public void yyerror (String s)
{
- System.err.println (s);
+ System.err.println (s);
}
]])[
# first error is ")", which is needed to recover from the error and
# produce the "0" that triggers the "0 != 1" error.
#
-_AT_CHECK_JAVA_CALC_ERROR([$1],
+_AT_CHECK_JAVA_CALC_ERROR([$1],
[() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1],
[1: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
1: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
{
$3
}
-
+
$4
}], [$5], [$7])])
AT_CHECK_JAVA_MINIMAL([[%parse-param {int parse_param1}]])
AT_CHECK_JAVA_GREP([[ *protected final int parse_param1;]])
AT_CHECK_JAVA_GREP([[ *public YYParser (Lexer yylexer, *int parse_param1) *]])
-AT_CHECK_JAVA_GREP([[[ ]*this.parse_param1 = parse_param1;]])
+AT_CHECK_JAVA_GREP([[ *this.parse_param1 = parse_param1;]])
AT_CHECK_JAVA_MINIMAL([[
%parse-param {int parse_param1}
AT_CHECK_JAVA_GREP([[ *protected final int parse_param1;]])
AT_CHECK_JAVA_GREP([[ *protected final long parse_param2;]])
AT_CHECK_JAVA_GREP([[ *public YYParser (Lexer yylexer, *int parse_param1, *long parse_param2) *]])
-AT_CHECK_JAVA_GREP([[[ ]*this.parse_param1 = parse_param1;]])
-AT_CHECK_JAVA_GREP([[[ ]*this.parse_param2 = parse_param2;]])
+AT_CHECK_JAVA_GREP([[ *this.parse_param1 = parse_param1;]])
+AT_CHECK_JAVA_GREP([[ *this.parse_param2 = parse_param2;]])
AT_CHECK_JAVA_MINIMAL_W_LEXER([], [], [[return EOF;]])
AT_CHECK_JAVA_GREP([[ *public YYParser () *]])
AT_CHECK_JAVA_GREP([[ *protected final int parse_param1;]])
AT_CHECK_JAVA_GREP([[ *public YYParser (int parse_param1) *]])
AT_CHECK_JAVA_GREP([[ *protected YYParser (Lexer yylexer, *int parse_param1) *]])
-AT_CHECK_JAVA_GREP([[[ ]*this.parse_param1 = parse_param1;]], [2])
+AT_CHECK_JAVA_GREP([[ *this.parse_param1 = parse_param1;]], [2])
AT_CHECK_JAVA_MINIMAL_W_LEXER([[
%parse-param {int parse_param1}
AT_CHECK_JAVA_GREP([[ *protected final long parse_param2;]])
AT_CHECK_JAVA_GREP([[ *public YYParser (int parse_param1, *long parse_param2) *]])
AT_CHECK_JAVA_GREP([[ *protected YYParser (Lexer yylexer, *int parse_param1, *long parse_param2) *]])
-AT_CHECK_JAVA_GREP([[[ ]*this.parse_param1 = parse_param1;]], [2])
-AT_CHECK_JAVA_GREP([[[ ]*this.parse_param2 = parse_param2;]], [2])
+AT_CHECK_JAVA_GREP([[ *this.parse_param1 = parse_param1;]], [2])
+AT_CHECK_JAVA_GREP([[ *this.parse_param2 = parse_param2;]], [2])
AT_CHECK_JAVA_MINIMAL_W_LEXER([[%lex-param {char lex_param1}]],
[], [[return EOF;]], [[YYLexer (char lex_param1) {}]])
AT_CHECK_JAVA_GREP([[ *public YYParser (char lex_param1, *short lex_param2, *int parse_param1, *long parse_param2) *]])
AT_CHECK_JAVA_GREP([[.* = new YYLexer *(lex_param1, *lex_param2);]])
AT_CHECK_JAVA_GREP([[ *protected YYParser (Lexer yylexer, *int parse_param1, *long parse_param2) *]])
-AT_CHECK_JAVA_GREP([[[ ]*this.parse_param1 = parse_param1;]], [2])
-AT_CHECK_JAVA_GREP([[[ ]*this.parse_param2 = parse_param2;]], [2])
+AT_CHECK_JAVA_GREP([[ *this.parse_param1 = parse_param1;]], [2])
+AT_CHECK_JAVA_GREP([[ *this.parse_param2 = parse_param2;]], [2])
AT_CLEANUP