* data/glr.c: Use American spacing, for consistency.
* data/glr.cc: Likewise.
* data/lalr1.cc: Likewise.
* data/yacc.c: Likewise.
* data/yacc.c: Reformat comments slightly.
* doc/bison.texinfo: Replace "non-" with "non" when that makes sense,
for consistency. Fix some spelling errors and reword recently-included
text slightly.
* tests/cxx-type.at: Cast results of malloc, for C++.
+2005-12-21 Paul Eggert <eggert@cs.ucla.edu>
+
+ * NEWS: Reword %destructor vs YYABORT etc.
+ * data/glr.c: Use American spacing, for consistency.
+ * data/glr.cc: Likewise.
+ * data/lalr1.cc: Likewise.
+ * data/yacc.c: Likewise.
+ * data/yacc.c: Reformat comments slightly.
+ * doc/bison.texinfo: Replace "non-" with "non" when that makes sense,
+ for consistency. Fix some spelling errors and reword recently-included
+ text slightly.
+ * tests/cxx-type.at: Cast results of malloc, for C++.
+
2005-12-21 Joel E. Denny <address@hidden>
* tests/cxx-type.at: Construct a tree, count the parents of shared
Changes in version 2.1a:
-* %destructor vs. YYACCEPT, YYERROR, and YYABORT.
- When the parsing/action is cut by the user using one of these
- special actions, the stack is freed except the right-hand side
- symbols of the current rule.
+* %destructor vs. YYABORT, YYACCEPT, and YYERROR.
+ Destructors are now called when user code invokes YYABORT, YYACCEPT,
+ and YYERROR, for all objects on the stack, other than objects
+ corresponding to the right-hand side of the current rule.
* GLR, C++ LALR(1) parsers.
These parser skeletons are now distributed with the same special
b4_copyright([Skeleton parser for GLR parsing with Bison],
[2002, 2003, 2004, 2005])
[
-/* This is the parser code for GLR (Generalized LR) parser. */
+/* This is the parser code for GLR (Generalized LR) parser. */
]b4_identification
right-hand sides. Unlike the standard yacc.c template,
here we set the default value of $$ to a zeroed-out value.
Since the default value is undefined, this behavior is
- technically correct. */
+ technically correct. */
static YYSTYPE yyval_default;
/* Copy the second part of user declarations. */
# define YYASSERT(condition) ((void) ((condition) || (abort (), 0)))
#endif
-/* YYFINAL -- State number of the termination state. */
+/* YYFINAL -- State number of the termination state. */
#define YYFINAL ]b4_final_state_number[
/* YYLAST -- Last index in YYTABLE. */
#define YYLAST ]b4_last[
-/* YYNTOKENS -- Number of terminals. */
+/* YYNTOKENS -- Number of terminals. */
#define YYNTOKENS ]b4_tokens_number[
-/* YYNNTS -- Number of nonterminals. */
+/* YYNNTS -- Number of nonterminals. */
#define YYNNTS ]b4_nterms_number[
-/* YYNRULES -- Number of rules. */
+/* YYNRULES -- Number of rules. */
#define YYNRULES ]b4_rules_number[
-/* YYNRULES -- Number of states. */
+/* YYNRULES -- Number of states. */
#define YYNSTATES ]b4_states_number[
-/* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
+/* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */
#define YYMAXRHS ]b4_r2_max[
/* YYMAXLEFT -- Maximum number of symbols to the left of a handle
- accessed by $0, $-1, etc., in any rule. */
+ accessed by $0, $-1, etc., in any rule. */
#define YYMAXLEFT ]b4_max_left_semantic_context[
/* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */
]b4_prhs[
};
-/* YYRHS -- A `-1'-separated list of the rules' RHS. */
+/* YYRHS -- A `-1'-separated list of the rules' RHS. */
static const ]b4_int_type_for([b4_rhs])[ yyrhs[] =
{
]b4_rhs[
#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
- First, the terminals, then, starting at YYNTOKENS, nonterminals. */
+ First, the terminals, then, starting at YYNTOKENS, nonterminals. */
static const char *const yytname[] =
{
]b4_tname[
]b4_r2[
};
-/* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
+/* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
static const ]b4_int_type_for([b4_dprec])[ yydprec[] =
{
]b4_dprec[
};
-/* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
+/* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
static const ]b4_int_type_for([b4_merger])[ yymerger[] =
{
]b4_merger[
]b4_defact[
};
-/* YYPDEFGOTO[NTERM-NUM]. */
+/* YYPDEFGOTO[NTERM-NUM]. */
static const ]b4_int_type_for([b4_defgoto])[ yydefgoto[] =
{
]b4_defgoto[
allocation. This is to allow allocation and initialization
to be completed by functions that call yyexpandGLRStack before the
stack is expanded, thus insuring that all necessary pointers get
- properly redirected to new data. */
+ properly redirected to new data. */
#define YYHEADROOM 2
#ifndef YYSTACKEXPANDABLE
typedef struct yyGLRStack yyGLRStack;
struct yyGLRState {
- /** Type tag: always true. */
+ /** Type tag: always true. */
yybool yyisState;
- /** Type tag for yysemantics. If true, yysval applies, otherwise
- * yyfirstVal applies. */
+ /** Type tag for yysemantics. If true, yysval applies, otherwise
+ * yyfirstVal applies. */
yybool yyresolved;
- /** Number of corresponding LALR(1) machine state. */
+ /** Number of corresponding LALR(1) machine state. */
yyStateNum yylrState;
/** Preceding state in this stack */
yyGLRState* yypred;
union {
/** First in a chain of alternative reductions producing the
* non-terminal corresponding to this state, threaded through
- * yynext. */
+ * yynext. */
yySemanticOption* yyfirstVal;
- /** Semantic value for this state. */
+ /** Semantic value for this state. */
YYSTYPE yysval;
} yysemantics;
- /** Source location for this state. */
+ /** Source location for this state. */
YYLTYPE yyloc;
};
};
struct yySemanticOption {
- /** Type tag: always false. */
+ /** Type tag: always false. */
yybool yyisState;
/** Rule number for this reduction */
yyRuleNum yyrule;
- /** The last RHS state in the list of states to be reduced. */
+ /** The last RHS state in the list of states to be reduced. */
yyGLRState* yystate;
- /** Next sibling in chain of options. To facilitate merging,
- * options are chained in decreasing order by address. */
+ /** Next sibling in chain of options. To facilitate merging,
+ * options are chained in decreasing order by address. */
yySemanticOption* yynext;
};
-/** Type of the items in the GLR stack. The yyisState field
- * indicates which item of the union is valid. */
+/** Type of the items in the GLR stack. The yyisState field
+ * indicates which item of the union is valid. */
union yyGLRStackItem {
yyGLRState yystate;
yySemanticOption yyoption;
/** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting
* at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred
- * containing the pointer to the next state in the chain. */
+ * containing the pointer to the next state in the chain. */
static void yyfillin (yyGLRStackItem *, int, int) __attribute__ ((__unused__));
static void
yyfillin (yyGLRStackItem *yyvsp, int yylow0, int yylow1)
/** Perform user action for rule number YYN, with RHS length YYRHSLEN,
* and top stack item YYVSP. YYLVALP points to place to put semantic
* value ($$), and yylocp points to place for location information
- * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
- * yyerr for YYERROR, yyabort for YYABORT. */
+ * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
+ * yyerr for YYERROR, yyabort for YYABORT. */
/*ARGSUSED*/ static YYRESULTTAG
yyuserAction (yyRuleNum yyn, int yyrhslen, yyGLRStackItem* yyvsp,
YYSTYPE* yyvalp,
}
}
-/** Left-hand-side symbol for rule #RULE. */
+/** Left-hand-side symbol for rule #RULE. */
static inline yySymbol
yylhsNonterm (yyRuleNum yyrule)
{
[((yystate) == YYPACT_NINF)])[
/** True iff LR state STATE has only a default reduction (regardless
- * of token). */
+ * of token). */
static inline yybool
yyisDefaultedState (yyStateNum yystate)
{
return yyis_pact_ninf (yypact[yystate]);
}
-/** The default reduction for STATE, assuming it has one. */
+/** The default reduction for STATE, assuming it has one. */
static inline yyRuleNum
yydefaultAction (yyStateNum yystate)
{
/* GLRStacks */
-/** Initialize SET to a singleton set containing an empty stack. */
+/** Initialize SET to a singleton set containing an empty stack. */
static yybool
yyinitStateSet (yyGLRStateSet* yyset)
{
}
/** Initialize STACK to a single empty stack, with total maximum
- * capacity for all stacks of SIZE. */
+ * capacity for all stacks of SIZE. */
static yybool
yyinitGLRStack (yyGLRStack* yystackp, size_t yysize)
{
stack from outside should be considered invalid after this call.
We always expand when there are 1 or fewer items left AFTER an
allocation, so that we can avoid having external pointers exist
- across an allocation. */
+ across an allocation. */
static void
yyexpandGLRStack (yyGLRStack* yystackp)
{
/** Assuming that S is a GLRState somewhere on STACK, update the
* splitpoint of STACK, if needed, so that it is at least as deep as
- * S. */
+ * S. */
static inline void
yyupdateSplit (yyGLRStack* yystackp, yyGLRState* yys)
{
yystackp->yysplitPoint = yys;
}
-/** Invalidate stack #K in STACK. */
+/** Invalidate stack #K in STACK. */
static inline void
yymarkStackDeleted (yyGLRStack* yystackp, size_t yyk)
{
/** Undelete the last stack that was marked as deleted. Can only be
done once after a deletion, and only when all other stacks have
- been deleted. */
+ been deleted. */
static void
yyundeleteLastStack (yyGLRStack* yystackp)
{
}
/** Shift to a new state on stack #K of STACK, corresponding to LR state
- * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
+ * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
static inline void
yyglrShift (yyGLRStack* yystackp, size_t yyk, yyStateNum yylrState,
size_t yyposn,
/** Shift stack #K of YYSTACK, to a new state corresponding to LR
* state YYLRSTATE, at input position YYPOSN, with the (unresolved)
- * semantic value of YYRHS under the action for YYRULE. */
+ * semantic value of YYRHS under the action for YYRULE. */
static inline void
yyglrShiftDefer (yyGLRStack* yystackp, size_t yyk, yyStateNum yylrState,
size_t yyposn, yyGLRState* rhs, yyRuleNum yyrule)
yynewState->yysemantics.yyfirstVal = NULL;
yystackp->yytops.yystates[yyk] = yynewState;
- /* Invokes YY_RESERVE_GLRSTACK. */
+ /* Invokes YY_RESERVE_GLRSTACK. */
yyaddDeferredAction (yystackp, yynewState, rhs, yyrule);
}
/** Pop the symbols consumed by reduction #RULE from the top of stack
* #K of STACK, and perform the appropriate semantic action on their
* semantic values. Assumes that all ambiguities in semantic values
- * have been previously resolved. Set *VALP to the resulting value,
+ * have been previously resolved. Set *VALP to the resulting value,
* and *LOCP to the computed location (if any). Return value is as
- * for userAction. */
+ * for userAction. */
static inline YYRESULTTAG
yydoAction (yyGLRStack* yystackp, size_t yyk, yyRuleNum yyrule,
YYSTYPE* yyvalp, YYLTYPE* yylocp]b4_user_formals[)
if (yystackp->yysplitPoint == NULL)
{
- /* Standard special case: single stack. */
+ /* Standard special case: single stack. */
yyGLRStackItem* rhs = (yyGLRStackItem*) yystackp->yytops.yystates[yyk];
YYASSERT (yyk == 0);
yystackp->yynextFree -= yynrhs;
/* At present, doAction is never called in nondeterministic
* mode, so this branch is never taken. It is here in
* anticipation of a future feature that will allow immediate
- * evaluation of selected actions in nondeterministic mode. */
+ * evaluation of selected actions in nondeterministic mode. */
int yyi;
yyGLRState* yys;
yyGLRStackItem yyrhsVals[YYMAXRHS + YYMAXLEFT + 1];
yys = yyrhsVals[YYMAXRHS + YYMAXLEFT].yystate.yypred
= yystackp->yytops.yystates[yyk];]b4_location_if([[
if (yynrhs == 0)
- /* Set default location. */
+ /* Set default location. */
yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].yystate.yyloc = yys->yyloc;]])[
for (yyi = 0; yyi < yynrhs; yyi += 1)
{
* the new state. If the new state would have an identical input
* position, LR state, and predecessor to an existing state on the stack,
* it is identified with that existing state, eliminating stack #K from
- * the STACK. In this case, the (necessarily deferred) semantic value is
+ * the STACK. In this case, the (necessarily deferred) semantic value is
* added to the options for the existing state's semantic value.
*/
static inline YYRESULTTAG
yyupdateSplit (yystackp, yys);
yynewLRState = yyLRgotoState (yys->yylrState, yylhsNonterm (yyrule));
YYDPRINTF ((stderr,
- "Reduced stack %lu by rule #%d; action deferred. Now in state %d.\n",
+ "Reduced stack %lu by rule #%d; action deferred. Now in state %d.\n",
(unsigned long int) yyk, yyrule - 1, yynewLRState));
for (yyi = 0; yyi < yystackp->yytops.yysize; yyi += 1)
if (yyi != yyk && yystackp->yytops.yystates[yyi] != NULL)
/** True iff Y0 and Y1 represent identical options at the top level.
* That is, they represent the same rule applied to RHS symbols
- * that produce the same terminal symbols. */
+ * that produce the same terminal symbols. */
static yybool
yyidenticalOptions (yySemanticOption* yyy0, yySemanticOption* yyy1)
{
}
/** Assuming identicalOptions (Y0,Y1), destructively merge the
- * alternative semantic values for the RHS-symbols of Y1 and Y0. */
+ * alternative semantic values for the RHS-symbols of Y1 and Y0. */
static void
yymergeOptionSets (yySemanticOption* yyy0, yySemanticOption* yyy1)
{
/** Y0 and Y1 represent two possible actions to take in a given
* parsing state; return 0 if no combination is possible,
- * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
+ * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */
static int
yypreference (yySemanticOption* y0, yySemanticOption* y1)
{
YYCHK (yyresolveStates (yyopt->yystate, yynrhs, yystackp]b4_user_args[));
yyrhsVals[YYMAXRHS + YYMAXLEFT].yystate.yypred = yyopt->yystate;]b4_location_if([[
if (yynrhs == 0)
- /* Set default location. */
+ /* Set default location. */
yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].yystate.yyloc = yyopt->yystate->yyloc;]])[
return yyuserAction (yyopt->yyrule, yynrhs,
yyrhsVals + YYMAXRHS + YYMAXLEFT - 1,
/** Resolve the ambiguity represented by OPTIONLIST, perform the indicated
- * actions, and return the result. */
+ * actions, and return the result. */
static YYRESULTTAG
yyresolveValue (yySemanticOption* yyoptionList, yyGLRStack* yystackp,
YYSTYPE* yyvalp, YYLTYPE* yylocp]b4_user_formals[)
if (*yytokenp != YYEMPTY)
{]b4_location_if([[
/* We throw away the lookahead, but the error range
- of the shifted error token must take it into account. */
+ of the shifted error token must take it into account. */
yyGLRState *yys = yystackp->yytops.yystates[0];
yyGLRStackItem yyerror_range[3];
yyerror_range[1].yystate.yyloc = yys->yyloc;
yyremoveDeletes (yystackp);
yycompressStack (yystackp);
- /* Now pop stack until we find a state that shifts the error token. */
+ /* Now pop stack until we find a state that shifts the error token. */
yystackp->yyerrState = 3;
while (yystackp->yytops.yystates[0] != NULL)
{
m4_ifdef([b4_initial_action], [
m4_pushdef([b4_at_dollar], [yylloc])dnl
m4_pushdef([b4_dollar_dollar], [yylval])dnl
- /* User initialization code. */
+ /* User initialization code. */
b4_initial_action
m4_popdef([b4_dollar_dollar])dnl
m4_popdef([b4_at_dollar])dnl
/* Pacify ``unused variable'' warnings. */
YYUSE (yyvaluep);
YYUSE (yylocationp);
- /* Backward compatibility, but should be removed eventually. */
+ /* Backward compatibility, but should be removed eventually. */
std::ostream& cdebug_ = *yycdebug_;
YYUSE (cdebug_);
[b4_token_defines(b4_tokens)
#ifndef YYSTYPE
- /* Redirection for backward compatibility. */
+ /* Redirection for backward compatibility. */
# define YYSTYPE yy::b4_parser_class_name::semantic_type
#endif
])[
/* Suppress unused-variable warnings by "using" E. */
#define YYUSE(e) ((void) (e))
-/* A pseudo ostream that takes yydebug_ into account. */
+/* A pseudo ostream that takes yydebug_ into account. */
# define YYCDEBUG \
for (bool yydebugcond_ = yydebug_; yydebugcond_; yydebugcond_ = false) \
(*yycdebug_)
]b4_parser_class_name[::yysymprint_ (int yytype,
const semantic_type* yyvaluep, const location_type* yylocationp)
{
- /* Backward compatibility, but should be removed eventually. */
+ /* Backward compatibility, but should be removed eventually. */
std::ostream& cdebug_ = *yycdebug_;
YYUSE (!&cdebug_);
int yylen = 0;
int yystate = 0;
- /* Error handling. */
+ /* Error handling. */
int yynerrs_ = 0;
int yyerrstatus_ = 0;
]m4_ifdef([b4_initial_action], [
m4_pushdef([b4_at_dollar], [yylloc])dnl
m4_pushdef([b4_dollar_dollar], [yylval])dnl
- /* User initialization code. */
+ /* User initialization code. */
b4_initial_action
m4_popdef([b4_dollar_dollar])dnl
m4_popdef([b4_at_dollar])dnl
yyerror_range[0] = yylocation_stack_[yylen - 1];
/* Do not reclaim the symbols of the rule which action triggered
- this YYERROR. */
+ this YYERROR. */
yypop_ (yylen);
yylen = 0;
yystate = yystate_stack_[0];
yysemantic_stack_.push (yylval);
yylocation_stack_.push (yyloc);
- /* Shift the error token. */
+ /* Shift the error token. */
YY_SYMBOL_PRINT ("Shifting", yystos_[yyn],
&yysemantic_stack_[0], &yylocation_stack_[0]);
yydestruct_ ("Cleanup: discarding lookahead", yytoken, &yylval, &yylloc);
/* Do not reclaim the symbols of the rule which action triggered
- this YYABORT or YYACCEPT. */
+ this YYABORT or YYACCEPT. */
yypop_ (yylen);
while (yystate_stack_.height () != 1)
{
#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
- First, the terminals, then, starting at \a yyntokens_, nonterminals. */
+ First, the terminals, then, starting at \a yyntokens_, nonterminals. */
const char*
const ]b4_parser_class_name[::yytname_[] =
{
#endif
#if YYDEBUG
- /* YYRHS -- A `-1'-separated list of the rules' RHS. */
+ /* YYRHS -- A `-1'-separated list of the rules' RHS. */
const ]b4_parser_class_name[::rhs_number_type
]b4_parser_class_name[::yyrhs_[] =
{
# endif
# ifdef YYSTACK_ALLOC
- /* Pacify GCC's `empty if-body' warning. */
+ /* Pacify GCC's `empty if-body' warning. */
# define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
# ifndef YYSTACK_ALLOC_MAXIMUM
/* The OS might guarantee only one guard page at the bottom of the stack,
typedef short int yysigned_char;
#endif
-/* YYFINAL -- State number of the termination state. */
+/* YYFINAL -- State number of the termination state. */
#define YYFINAL ]b4_final_state_number[
/* YYLAST -- Last index in YYTABLE. */
#define YYLAST ]b4_last[
-/* YYNTOKENS -- Number of terminals. */
+/* YYNTOKENS -- Number of terminals. */
#define YYNTOKENS ]b4_tokens_number[
-/* YYNNTS -- Number of nonterminals. */
+/* YYNNTS -- Number of nonterminals. */
#define YYNNTS ]b4_nterms_number[
-/* YYNRULES -- Number of rules. */
+/* YYNRULES -- Number of rules. */
#define YYNRULES ]b4_rules_number[
-/* YYNRULES -- Number of states. */
+/* YYNRULES -- Number of states. */
#define YYNSTATES ]b4_states_number[
/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
]b4_prhs[
};
-/* YYRHS -- A `-1'-separated list of the rules' RHS. */
+/* YYRHS -- A `-1'-separated list of the rules' RHS. */
static const ]b4_int_type_for([b4_rhs])[ yyrhs[] =
{
]b4_rhs[
#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
- First, the terminals, then, starting at YYNTOKENS, nonterminals. */
+ First, the terminals, then, starting at YYNTOKENS, nonterminals. */
static const char *const yytname[] =
{
]b4_tname[
]b4_defact[
};
-/* YYDEFGOTO[NTERM-NUM]. */
+/* YYDEFGOTO[NTERM-NUM]. */
static const ]b4_int_type_for([b4_defgoto])[ yydefgoto[] =
{
]b4_defgoto[
[[short int *top], [top]])[
{
YYFPRINTF (stderr, "Stack now");
- for (/* Nothing. */; bottom <= top; ++bottom)
+ for (; bottom <= top; ++bottom)
YYFPRINTF (stderr, " %d", *bottom);
YYFPRINTF (stderr, "\n");
}
YYLTYPE yylsa[YYINITDEPTH];
YYLTYPE *yyls = yylsa;
YYLTYPE *yylsp;
- /* The locations where the error started and ended. */
+ /* The locations where the error started and ended. */
YYLTYPE yyerror_range[2];]])[
#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)]b4_location_if([, yylsp -= (N)])[)
]b4_location_if([ YYLTYPE yyloc;])[
/* The number of symbols on the RHS of the reduced rule.
- Keep to zero when no symbol should be popped off. */
+ Keep to zero when no symbol should be popped. */
int yylen = 0;
YYDPRINTF ((stderr, "Starting parse\n"));
m4_ifdef([b4_initial_action], [
m4_pushdef([b4_at_dollar], [m4_define([b4_at_dollar_used])yylloc])dnl
m4_pushdef([b4_dollar_dollar], [m4_define([b4_dollar_dollar_used])yylval])dnl
- /* User initialization code. */
+ /* User initialization code. */
b4_initial_action
m4_popdef([b4_dollar_dollar])dnl
m4_popdef([b4_at_dollar])dnl
`------------------------------------------------------------*/
yynewstate:
/* In all cases, when you get here, the value and location stacks
- have just been pushed. so pushing a state here evens the stacks.
- */
+ have just been pushed. So pushing a state here evens the stacks. */
yyssp++;
yysetstate:
#ifdef yyoverflow
{
- /* Give user a chance to reallocate the stack. Use copies of
+ /* Give user a chance to reallocate the stack. Use copies of
these so that the &'s don't force the real ones into
memory. */
YYSTYPE *yyvs1 = yyvs;
yyval = yyvsp[1-yylen];
]b4_location_if(
-[[ /* Default location. */
+[[ /* Default location. */
YYLLOC_DEFAULT (yyloc, yylsp - yylen, yylen);]])[
YY_REDUCE_PRINT (yyn);
switch (yyn)
]b4_location_if([[ yyerror_range[0] = yylsp[1-yylen];
]])[ /* Do not reclaim the symbols of the rule which action triggered
- this YYERROR. */
+ this YYERROR. */
YYPOPSTACK (yylen);
yylen = 0;
YY_STACK_PRINT (yyss, yyssp);
]b4_location_if([[
yyerror_range[1] = yylloc;
/* Using YYLLOC is tempting, but would change the location of
- the look-ahead. YYLOC is available though. */
+ the look-ahead. YYLOC is available though. */
YYLLOC_DEFAULT (yyloc, yyerror_range - 1, 2);
*++yylsp = yyloc;]])[
- /* Shift the error token. */
+ /* Shift the error token. */
YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
yystate = yyn;
yydestruct ("Cleanup: discarding lookahead",
yytoken, &yylval]b4_location_if([, &yylloc])[]b4_user_args[);
/* Do not reclaim the symbols of the rule which action triggered
- this YYABORT or YYACCEPT. */
+ this YYABORT or YYACCEPT. */
YYPOPSTACK (yylen);
YY_STACK_PRINT (yyss, yyssp);
while (yyssp != yyss)
@cindex @acronym{GLR} parsing
@cindex generalized @acronym{LR} (@acronym{GLR}) parsing
@cindex ambiguous grammars
-@cindex non-deterministic parsing
+@cindex nondeterministic parsing
Parsers for @acronym{LALR}(1) grammars are @dfn{deterministic}, meaning
roughly that the next grammar rule to apply at any point in the input is
(called a @dfn{look-ahead}) of the remaining input. A context-free
grammar can be @dfn{ambiguous}, meaning that there are multiple ways to
apply the grammar rules to get the same inputs. Even unambiguous
-grammars can be @dfn{non-deterministic}, meaning that no fixed
+grammars can be @dfn{nondeterministic}, meaning that no fixed
look-ahead always suffices to determine the next grammar rule to apply.
With the proper declarations, Bison is also able to parse these more
general context-free grammars, using a technique known as @acronym{GLR}
It is easy to add new operators to the infix calculator as long as they are
only single-character literals. The lexical analyzer @code{yylex} passes
-back all nonnumber characters as tokens, so new grammar rules suffice for
+back all nonnumeric characters as tokens, so new grammar rules suffice for
adding a new operator. But we want something more flexible: built-in
functions whose syntax has this form:
The function @code{yylex} must now recognize variables, numeric values, and
the single-character arithmetic operators. Strings of alphanumeric
-characters with a leading non-digit are recognized as either variables or
+characters with a leading letter are recognized as either variables or
functions depending on what the symbol table says about them.
The string is passed to @code{getsym} for look up in the symbol table. If
in the other source files that need it. @xref{Invocation, ,Invoking Bison}.
If you want to write a grammar that is portable to any Standard C
-host, you must use only non-null character tokens taken from the basic
+host, you must use only nonnull character tokens taken from the basic
execution character set of Standard C@. This set consists of the ten
digits, the 52 lower- and upper-case English letters, and the
characters in the following C-language string:
During error recovery (@pxref{Error Recovery}), symbols already pushed
on the stack and tokens coming from the rest of the file are discarded
until the parser falls on its feet. If the parser runs out of memory,
-or if the parsing is cut by @code{YYACCEPT} or @code{YYABORT}, all the
+or if it returns via @code{YYABORT} or @code{YYACCEPT}, all the
symbols on the stack must be discarded. Even if the parser succeeds, it
must discard the start symbol.
incoming terminals during the second phase of error recovery,
@item
the current look-ahead and the entire stack (except the current
-right-hand side symbols) when the parser aborts (either via an explicit
-call to @code{YYABORT} or @code{YYACCEPT}, or as a consequence of a
-failed error recovery or of memory exhaustion), and
+right-hand side symbols) when the parser returns immediately, and
@item
the start symbol, when the parser succeeds.
@end itemize
-Note that right-hand size symbols of a rule that explicitly triggers a
-syntax error via @code{YYERROR} are not reclaimed. As a thumb rule,
-destructors are invoked only when you do not have other means to manage
+The parser can @dfn{return immediately} because of an explicit call to
+@code{YYABORT} or @code{YYACCEPT}, or failed error recovery, or memory
+exhaustion.
+
+Right-hand size symbols of a rule that explicitly triggers a syntax
+error via @code{YYERROR} are not discarded automatically. As a rule
+of thumb, destructors are invoked only when user actions cannot manage
the memory.
@node Expect Decl
A @dfn{reentrant} program is one which does not alter in the course of
execution; in other words, it consists entirely of @dfn{pure} (read-only)
code. Reentrancy is important whenever asynchronous execution is possible;
-for example, a non-reentrant program may not be safe to call from a signal
-handler. In systems with multiple threads of control, a non-reentrant
+for example, a nonreentrant program may not be safe to call from a signal
+handler. In systems with multiple threads of control, a nonreentrant
program must be called only within interlocks.
Normally, Bison generates a parser which is not reentrant. This is
@subsection Semantic Values of Tokens
@vindex yylval
-In an ordinary (non-reentrant) parser, the semantic value of the token must
+In an ordinary (nonreentrant) parser, the semantic value of the token must
be stored into the global variable @code{yylval}. When you are using
just one data type for semantic values, @code{yylval} has that type.
Thus, if the type is @code{int} (the default), you might write this in
@cindex @acronym{GLR} parsing
@cindex generalized @acronym{LR} (@acronym{GLR}) parsing
@cindex ambiguous grammars
-@cindex non-deterministic parsing
+@cindex nondeterministic parsing
Bison produces @emph{deterministic} parsers that choose uniquely
when to reduce and which reduction to apply
context-free grammar in cubic worst-case time. However, Bison currently
uses a simpler data structure that requires time proportional to the
length of the input times the maximum number of stacks required for any
-prefix of the input. Thus, really ambiguous or non-deterministic
+prefix of the input. Thus, really ambiguous or nondeterministic
grammars can require exponential time and space to process. Such badly
behaving examples, however, are not generally of practical interest.
-Usually, non-determinism in a grammar is local---the parser is ``in
+Usually, nondeterminism in a grammar is local---the parser is ``in
doubt'' only for a few tokens at a time. Therefore, the current data
structure should generally be adequate. On @acronym{LALR}(1) portions of a
grammar, in particular, it is only slightly slower than with the default
declare and define the parser class in the namespace @code{yy}. The
class name defaults to @code{parser}, but may be changed using
@samp{%define "parser_class_name" "@var{name}"}. The interface of
-this class is detailled below. It can be extended using the
+this class is detailed below. It can be extended using the
@code{%parse-param} feature: its semantics is slightly changed since
it describes an additional member of the parser class, and an
additional argument for its constructor.
@deftypemethod {parser} {debug_level_type} debug_level ()
@deftypemethodx {parser} {void} set_debug_level (debug_level @var{l})
Get or set the tracing level. Currently its value is either 0, no trace,
-or non-zero, full tracing.
+or nonzero, full tracing.
@end deftypemethod
@deftypemethod {parser} {void} error (const location_type& @var{l}, const std::string& @var{m})
@subsection Calc++ --- C++ Calculator
Of course the grammar is dedicated to arithmetics, a single
-expression, possibily preceded by variable assignments. An
+expression, possibly preceded by variable assignments. An
environment containing possibly predefined variables such as
@code{one} and @code{two}, is exchanged with the parser. An example
of valid input follows.
unit: assignments exp @{ driver.result = $2; @};
assignments: assignments assignment @{@}
- | /* Nothing. */ @{@};
+ | /* Nothing. */ @{@};
assignment: "identifier" ":=" exp @{ driver.variables[*$1] = $3; @};
@end example
@noindent
-The following paragraph suffices to track locations acurately. Each
+The following paragraph suffices to track locations accurately. Each
time @code{yylex} is invoked, the begin position is moved onto the end
position. Then when a pattern is matched, the end position is
advanced of its width. In case it matched ends of lines, the end
The rules are simple, just note the use of the driver to report errors.
It is convenient to use a typedef to shorten
@code{yy::calcxx_parser::token::identifier} into
-@code{token::identifier} for isntance.
+@code{token::identifier} for instance.
@comment file: calc++-scanner.ll
@example
@end deffn
@deffn {Directive} %nonassoc
-Bison declaration to assign non-associativity to token(s).
+Bison declaration to assign nonassociativity to token(s).
@xref{Precedence Decl, ,Operator Precedence}.
@end deffn
static Node *
new_nterm (char const *form, Node *child0, Node *child1, Node *child2)
{
- Node *node = malloc (sizeof (Node));
+ Node *node = (Node *) malloc (sizeof (Node));
node->nterm.type = 1;
node->nterm.parents = 0;
node->nterm.form = form;
static Node *
new_term (char *text)
{
- Node *node = malloc (sizeof (Node));
+ Node *node = (Node *) malloc (sizeof (Node));
node->term.type = 0;
node->term.parents = 0;
node->term.text = text;
char *buffer;
if (!node)
{
- buffer = malloc (1);
+ buffer = (char *) malloc (1);
buffer[0] = 0;
}
else if (node->node_info.type == 1)
child0 = node_to_string (node->nterm.children[0]);
child1 = node_to_string (node->nterm.children[1]);
child2 = node_to_string (node->nterm.children[2]);
- buffer = malloc (strlen (node->nterm.form) + strlen (child0)
- + strlen (child1) + strlen (child2) + 1);
+ buffer = (char *) malloc (strlen (node->nterm.form) + strlen (child0)
+ + strlen (child1) + strlen (child2) + 1);
sprintf (buffer, node->nterm.form, child0, child1, child2);
free (child0);
free (child1);