/[bison]/bison/data/glr.c
ViewVC logotype

Diff of /bison/data/glr.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by hilfinger, Fri Jun 28 01:51:33 2002 UTC revision 1.2 by akim, Fri Jun 28 17:27:29 2002 UTC
# Line 1  Line 1 
1  m4_divert(-1)                                                       -*- YYC -*-  m4_divert(-1)                                                       -*- YYC -*-
2    
3  # b4_sint_type(MAX)  # GLR skeleton for Bison
4  # -----------------  # Copyright (C) 2002 Free Software Foundation, Inc.
5  # Return the smallest signed int type able to handle the number MAX.  
6  m4_define([b4_sint_type],  # This program is free software; you can redistribute it and/or modify
7  [m4_if(m4_eval([$1 <= 127]),        [1], [signed char],  # it under the terms of the GNU General Public License as published by
8         m4_eval([$1 <= 32767]),      [1], [signed short],  # the Free Software Foundation; either version 2 of the License, or
9         [signed int])])  # (at your option) any later version.
10    
11    # This program is distributed in the hope that it will be useful,
12    # but WITHOUT ANY WARRANTY; without even the implied warranty of
13    # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    # GNU General Public License for more details.
15    
16    # You should have received a copy of the GNU General Public License
17    # along with this program; if not, write to the Free Software
18    # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19    # 02111-1307  USA
20    
21    m4_include([c.m4])
22    
 # b4_uint_type(MAX)  
 # -----------------  
 # Return the smallest unsigned int type able to handle the number MAX.  
 m4_define([b4_uint_type],  
 [m4_if(m4_eval([$1 <= 255]),        [1], [unsigned char],  
        m4_eval([$1 <= 65535]),      [1], [unsigned short],  
        [unsigned int])])  
23    
24    
25  # b4_lhs_value([TYPE])  # b4_lhs_value([TYPE])
# Line 99  m4_define_default([b4_header_guard], Line 104  m4_define_default([b4_header_guard],
104                                  [[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]], [_])])                                  [[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]], [_])])
105    
106    
 ## ------------------------- ##  
 ## Assigning token numbers.  ##  
 ## ------------------------- ##  
   
 # b4_token_define(TOKEN-NAME, TOKEN-NUMBER)  
 # -----------------------------------------  
 # Output the definition of this token as #define.  
 m4_define([b4_token_define],  
 [#define $1 $2  
 ])  
   
   
 # b4_token_enum(TOKEN-NAME, TOKEN-NUMBER)  
 # ---------------------------------------  
 # Output the definition of this token as an enum.  
 m4_define([b4_token_enum],  
 [$1 = $2])  
   
   
 # b4_token_defines(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)  
 # -------------------------------------------------------  
 # Output the definition of the tokens (if there are) as enums and #define.  
 m4_define([b4_token_defines],  
 [m4_if([$@], [[]], [],  
 [/* Tokens.  */  
 #ifndef YYTOKENTYPE  
 # if defined (__STDC__) || defined (__cplusplus)  
    /* Put the tokens into the symbol table, so that GDB and other debuggers  
       know about them.  */  
    enum yytokentype {  
 m4_map_sep([     b4_token_enum], [,  
 ],  
            [$@])  
    };  
 # endif  
   /* POSIX requires `int' for tokens in interfaces.  */  
 # define YYTOKENTYPE int  
 #endif /* !YYTOKENTYPE */  
 m4_map([b4_token_define], [$@])  
 ])  
 ])  
   
   
107  m4_divert(0)dnl  m4_divert(0)dnl
108  #output "b4_output_parser_name"  #output "b4_output_parser_name"
109  [/* Skeleton parser for GLR parsing with Bison,  b4_copyright([Skeleton parser for GLR parsing with Bison], [2002])
110     Copyright (C) 2002 Free Software Foundation, Inc.  [
   
    This program is free software; you can redistribute it and/or modify  
    it under the terms of the GNU General Public License as published by  
    the Free Software Foundation; either version 2, or (at your option)  
    any later version.  
   
    This program is distributed in the hope that it will be useful,  
    but WITHOUT ANY WARRANTY; without even the implied warranty of  
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  
    GNU General Public License for more details.  
   
    You should have received a copy of the GNU General Public License  
    along with this program; if not, write to the Free Software  
    Foundation, Inc., 59 Temple Place - Suite 330,  
    Boston, MA 02111-1307, USA.  */  
   
 /* As a special exception, when this file is copied by Bison into a  
    Bison output file, you may use that output file without restriction.  
    This special exception was added by the Free Software Foundation  
    in version 1.24 of Bison.  */  
   
111  /* This is the parser code for GLR (Generalized LR) parser. */  /* This is the parser code for GLR (Generalized LR) parser. */
112    
113  /* FIXME: minimize these */  /* FIXME: minimize these */
# Line 240  typedef struct yyltype Line 181  typedef struct yyltype
181  #endif  #endif
182    
183  /* Default (constant) values used for initialization for null  /* Default (constant) values used for initialization for null
184     right-hand sides.  Unlike the standard bison.simple template,     right-hand sides.  Unlike the standard bison.simple template,
185     here we set the default values of the $$ and $@ to zeroed-out     here we set the default values of the $$ and $@ to zeroed-out
186     values.  Since the default value of these quantities is undefined,     values.  Since the default value of these quantities is undefined,
187     this behavior is technically correct. */     this behavior is technically correct. */
# Line 260  static YYLTYPE yyloc_default; Line 201  static YYLTYPE yyloc_default;
201  #endif  #endif
202    
203  #if ! defined (yy__GNUC__)  #if ! defined (yy__GNUC__)
204  #  define inline  #  define inline
205  #endif  #endif
206    
207  /* YYFINAL -- State number of the termination state. */  /* YYFINAL -- State number of the termination state. */
# Line 385  static const short yytable[] = Line 326  static const short yytable[] =
326    
327  /* YYCONFLP[YYPACT[STATE-NUM]] -- pointer into yyconfl of start of list  /* YYCONFLP[YYPACT[STATE-NUM]] -- pointer into yyconfl of start of list
328     of conflicting reductions corresponding to action entry for state     of conflicting reductions corresponding to action entry for state
329     STATE-NUM in yytable.  0 means no conflicts.  The list in yyconfl     STATE-NUM in yytable.  0 means no conflicts.  The list in yyconfl
330     is terminated by a rule number of 0. */     is terminated by a rule number of 0. */
331  static const short yyconflp[] =  static const short yyconflp[] =
332  {  {
333    ]b4_conflict_list_heads[    ]b4_conflict_list_heads[
334  };  };
335    
336  /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated  /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated
337     by 0, pointed into by YYCONFLP. */     by 0, pointed into by YYCONFLP. */
338  static const short yyconfl[] =  static const short yyconfl[] =
339  {  {
# Line 502  int yydebug; Line 443  int yydebug;
443     if the built-in stack extension method is used).     if the built-in stack extension method is used).
444    
445     Do not make this value too large; the results are undefined if     Do not make this value too large; the results are undefined if
446     SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)     SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem)
447     evaluated with infinite-precision integer arithmetic.  */     evaluated with infinite-precision integer arithmetic.  */
448    
449  #if YYMAXDEPTH == 0  #if YYMAXDEPTH == 0
# Line 514  int yydebug; Line 455  int yydebug;
455  #endif  #endif
456    
457  /* Minimum number of free items on the stack allowed after an  /* Minimum number of free items on the stack allowed after an
458     allocation.  This is to allow allocation and initialization     allocation.  This is to allow allocation and initialization
459     to be completed by functions that call expandGLRStack before the     to be completed by functions that call expandGLRStack before the
460     stack is expanded, thus insuring that all necessary pointers get     stack is expanded, thus insuring that all necessary pointers get
461     properly redirected to new data. */     properly redirected to new data. */
462  #define YYHEADROOM 2  #define YYHEADROOM 2
463    
# Line 546  typedef struct yyGLRStack yyGLRStack; Line 487  typedef struct yyGLRStack yyGLRStack;
487  typedef struct yyGLRStateSet yyGLRStateSet;  typedef struct yyGLRStateSet yyGLRStateSet;
488    
489  struct yyGLRState {  struct yyGLRState {
490    bool yyisState;          bool yyisState;
491    bool yyresolved;    bool yyresolved;
492    yyStateNum yylrState;    yyStateNum yylrState;
493    yyGLRState* yypred;    yyGLRState* yypred;
# Line 598  static void yyexpandGLRStack (yyGLRStack Line 539  static void yyexpandGLRStack (yyGLRStack
539  static void yyfreeGLRStack (yyGLRStack* yystack);  static void yyfreeGLRStack (yyGLRStack* yystack);
540    
541  static void  static void
542  yyFail (yyGLRStack* yystack, const char* yyformat, ...)  yyFail (yyGLRStack* yystack, const char* yyformat, ...)
543  {  {
544    if (yyformat != NULL)    if (yyformat != NULL)
545      {      {
# Line 615  yyFail (yyGLRStack* yystack, const char* Line 556  yyFail (yyGLRStack* yystack, const char*
556  #if YYDEBUG || YYERROR_VERBOSE  #if YYDEBUG || YYERROR_VERBOSE
557  /** A printable representation of TOKEN.  Valid until next call to  /** A printable representation of TOKEN.  Valid until next call to
558   *  tokenName. */   *  tokenName. */
559  static inline const char*  static inline const char*
560  yytokenName (yySymbol yytoken)  yytokenName (yySymbol yytoken)
561  {  {
562    return yytname[yytoken];    return yytname[yytoken];
563  }  }
# Line 628  yytokenName (yySymbol yytoken) Line 569  yytokenName (yySymbol yytoken)
569   *  (@$). Returns yyok for normal return, yyaccept for YYACCEPT,   *  (@$). Returns yyok for normal return, yyaccept for YYACCEPT,
570   *  yyerr for YYERROR, yyabort for YYABORT. */   *  yyerr for YYERROR, yyabort for YYABORT. */
571  static YYRESULTTAG  static YYRESULTTAG
572  yyuserAction (yyRuleNum yyn, int yyrhslen, yyGLRStackItem* yyvsp,  yyuserAction (yyRuleNum yyn, int yyrhslen, yyGLRStackItem* yyvsp,
573                YYSTYPE* yyvalp, YYLTYPE* yylocp, yyGLRStack* yystack)                YYSTYPE* yyvalp, YYLTYPE* yylocp, yyGLRStack* yystack)
574  {  {
575    if (yyrhslen == 0)    if (yyrhslen == 0)
576      {      {
577        *yyvalp = yyval_default;        *yyvalp = yyval_default;
578        *yylocp = yyloc_default;        *yylocp = yyloc_default;
579      }      }
580    else    else
581      {      {
582        *yyvalp = yyvsp[1-yyrhslen].yystate.yysemantics.yysval;        *yyvalp = yyvsp[1-yyrhslen].yystate.yysemantics.yysval;
583        *yylocp = yyvsp[1-yyrhslen].yystate.yyloc;        *yylocp = yyvsp[1-yyrhslen].yystate.yyloc;
# Line 663  yyuserAction (yyRuleNum yyn, int yyrhsle Line 604  yyuserAction (yyRuleNum yyn, int yyrhsle
604    } while (0)    } while (0)
605    
606  ]  ]
607     switch (yyn)     switch (yyn)
608       {       {
609         b4_actions         b4_actions
610       }       }
# Line 686  static YYSTYPE Line 627  static YYSTYPE
627  yyuserMerge (int yyn, YYSTYPE* yy0, YYSTYPE* yy1)  yyuserMerge (int yyn, YYSTYPE* yy0, YYSTYPE* yy1)
628  {  {
629    YYSTYPE yyval = *yy0;    YYSTYPE yyval = *yy0;
630    switch (yyn)    switch (yyn)
631      {      {
632        b4_mergers        b4_mergers
633      }      }
# Line 697  yyuserMerge (int yyn, YYSTYPE* yy0, YYST Line 638  yyuserMerge (int yyn, YYSTYPE* yy0, YYST
638    
639  /** Number of symbols composing the right hand side of rule #RULE. */  /** Number of symbols composing the right hand side of rule #RULE. */
640  static inline int  static inline int
641  yyrhsLength (yyRuleNum yyrule)  yyrhsLength (yyRuleNum yyrule)
642  {  {
643    return yyr2[yyrule];    return yyr2[yyrule];
644  }  }
645    
646  /** Left-hand-side symbol for rule #RULE. */  /** Left-hand-side symbol for rule #RULE. */
647  static inline yySymbol  static inline yySymbol
648  yylhsNonterm (yyRuleNum yyrule)  yylhsNonterm (yyRuleNum yyrule)
649  {  {
650    return yyr1[yyrule];    return yyr1[yyrule];
651  }  }
# Line 716  yyisDefaultedState (yyStateNum yystate) Line 657  yyisDefaultedState (yyStateNum yystate)
657  {  {
658    return yypact[yystate] == YYFLAG;    return yypact[yystate] == YYFLAG;
659  }  }
660      
661  /** The default reduction for STATE, assuming it has one. */  /** The default reduction for STATE, assuming it has one. */
662  static inline yyRuleNum  static inline yyRuleNum
663  yydefaultAction (yyStateNum yystate)  yydefaultAction (yyStateNum yystate)
# Line 724  yydefaultAction (yyStateNum yystate) Line 665  yydefaultAction (yyStateNum yystate)
665    return yydefact[yystate];    return yydefact[yystate];
666  }  }
667    
668  /** Set *ACTION to the action to take in STATE on seeing TOKEN.    /** Set *ACTION to the action to take in STATE on seeing TOKEN.
669   *  Result R means   *  Result R means
670   *    R < 0:  Reduce on rule -R.   *    R < 0:  Reduce on rule -R.
671   *    R = 0:  Error.   *    R = 0:  Error.
672   *    R > 0:  Shift to state R.   *    R > 0:  Shift to state R.
673   *  Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of   *  Set *CONFLICTS to a pointer into yyconfl to 0-terminated list of
674   *  conflicting reductions.   *  conflicting reductions.
675   */   */
676  static inline void  static inline void
677  yygetLRActions (yyStateNum yystate, int yytoken,  yygetLRActions (yyStateNum yystate, int yytoken,
678                  int* yyaction, const short** yyconflicts)                  int* yyaction, const short** yyconflicts)
679  {  {
680    int yyindex = yypact[yystate] + yytoken;    int yyindex = yypact[yystate] + yytoken;
# Line 742  yygetLRActions (yyStateNum yystate, int Line 683  yygetLRActions (yyStateNum yystate, int
683        *yyaction = -yydefact[yystate];        *yyaction = -yydefact[yystate];
684        *yyconflicts = yyconfl;        *yyconflicts = yyconfl;
685      }      }
686    else    else
687      {      {
688        *yyaction = yytable[yyindex];        *yyaction = yytable[yyindex];
689        *yyconflicts = yyconfl + yyconflp[yyindex];        *yyconflicts = yyconfl + yyconflp[yyindex];
# Line 761  yyLRgotoState (yyStateNum yystate, yySym Line 702  yyLRgotoState (yyStateNum yystate, yySym
702  }  }
703    
704  static inline bool  static inline bool
705  yyisShiftAction (int yyaction)  yyisShiftAction (int yyaction)
706  {  {
707    return yyaction > 0;    return yyaction > 0;
708  }  }
709    
710  static inline bool  static inline bool
711  yyisErrorAction (int yyaction)  yyisErrorAction (int yyaction)
712  {  {
713    return yyaction == 0 || yyaction == YYFLAG;    return yyaction == 0 || yyaction == YYFLAG;
714  }  }
# Line 777  yyisErrorAction (int yyaction) Line 718  yyisErrorAction (int yyaction)
718  /** True iff the semantic value of the edge leading to STATE is  /** True iff the semantic value of the edge leading to STATE is
719   *  resolved. */   *  resolved. */
720  static inline bool  static inline bool
721  yyhasResolvedValue (yyGLRState* yystate)  yyhasResolvedValue (yyGLRState* yystate)
722  {  {
723    return yystate->yyresolved;    return yystate->yyresolved;
724  }  }
725    
726  void yyaddDeferredAction (yyGLRStack* yystack, yyGLRState* yystate,  void yyaddDeferredAction (yyGLRStack* yystack, yyGLRState* yystate,
727                            yyGLRState* yyrhs, yyRuleNum yyrule)                            yyGLRState* yyrhs, yyRuleNum yyrule)
728  {  {
729    yySemanticOption* yynewItem;    yySemanticOption* yynewItem;
# Line 791  void yyaddDeferredAction (yyGLRStack* yy Line 732  void yyaddDeferredAction (yyGLRStack* yy
732    yystack->yynextFree += 1;    yystack->yynextFree += 1;
733    yynewItem->yyisState = yyfalse;    yynewItem->yyisState = yyfalse;
734    yynewItem->yystate = yyrhs;    yynewItem->yystate = yyrhs;
735    yynewItem->yyrule = yyrule;    yynewItem->yyrule = yyrule;
736    yynewItem->yynext = yystate->yysemantics.yyfirstVal;    yynewItem->yynext = yystate->yysemantics.yyfirstVal;
737    yystate->yysemantics.yyfirstVal = yynewItem;    yystate->yysemantics.yyfirstVal = yynewItem;
738    if (yystack->yyspaceLeft < YYHEADROOM)    if (yystack->yyspaceLeft < YYHEADROOM)
# Line 810  yyinitStateSet (yyGLRStateSet* yyset) Line 751  yyinitStateSet (yyGLRStateSet* yyset)
751    yyset->yystates[0] = NULL;    yyset->yystates[0] = NULL;
752  }  }
753    
754  static void yyfreeStateSet (yyGLRStateSet* yyset)  static void yyfreeStateSet (yyGLRStateSet* yyset)
755  {  {
756    free (yyset->yystates);    free (yyset->yystates);
757  }  }
# Line 824  yyinitGLRStack (yyGLRStack* yystack, siz Line 765  yyinitGLRStack (yyGLRStack* yystack, siz
765    yystack->yyerrState = 0;    yystack->yyerrState = 0;
766    yynerrs = 0;    yynerrs = 0;
767    yystack->yyspaceLeft = yysize;    yystack->yyspaceLeft = yysize;
768    yystack->yynextFree = yystack->yyitems =    yystack->yynextFree = yystack->yyitems =
769      (yyGLRStackItem*) malloc (yysize * sizeof (yystack->yynextFree[0]));      (yyGLRStackItem*) malloc (yysize * sizeof (yystack->yynextFree[0]));
770    yystack->yysplitPoint = NULL;    yystack->yysplitPoint = NULL;
771    yystack->yylastDeleted = NULL;    yystack->yylastDeleted = NULL;
# Line 840  yyinitGLRStack (yyGLRStack* yystack, siz Line 781  yyinitGLRStack (yyGLRStack* yystack, siz
781      allocation, so that we can avoid having external pointers exist      allocation, so that we can avoid having external pointers exist
782      across an allocation. */      across an allocation. */
783  static void  static void
784  yyexpandGLRStack (yyGLRStack* yystack)  yyexpandGLRStack (yyGLRStack* yystack)
785  {  {
786  #if YYSTACKEXPANDABLE  #if YYSTACKEXPANDABLE
787    yyGLRStack yynewStack;    yyGLRStack yynewStack;
# Line 854  yyexpandGLRStack (yyGLRStack* yystack) Line 795  yyexpandGLRStack (yyGLRStack* yystack)
795    if (yynewSize > YYMAXDEPTH)    if (yynewSize > YYMAXDEPTH)
796      yynewSize = YYMAXDEPTH;      yynewSize = YYMAXDEPTH;
797    yyinitGLRStack (&yynewStack, yynewSize);    yyinitGLRStack (&yynewStack, yynewSize);
798    for (yyp0 = yystack->yyitems, yyp1 = yynewStack.yyitems, yyn = yysize;    for (yyp0 = yystack->yyitems, yyp1 = yynewStack.yyitems, yyn = yysize;
799         yyn > 0;         yyn > 0;
800         yyn -= 1, yyp0 += 1, yyp1 += 1)         yyn -= 1, yyp0 += 1, yyp1 += 1)
801      {      {
802        *yyp1 = *yyp0;        *yyp1 = *yyp0;
803        if (*(bool*) yyp0)        if (*(bool*) yyp0)
804          {            {
805            yyGLRState* yys0 = &yyp0->yystate;            yyGLRState* yys0 = &yyp0->yystate;
806            yyGLRState* yys1 = &yyp1->yystate;            yyGLRState* yys1 = &yyp1->yystate;
807            if (yys0->yypred != NULL)            if (yys0->yypred != NULL)
808              yys1->yypred =              yys1->yypred =
809                YYRELOC (yyp0, yyp1, yys0->yypred, yystate);                YYRELOC (yyp0, yyp1, yys0->yypred, yystate);
810            if (! yys0->yyresolved && yys0->yysemantics.yyfirstVal != NULL)            if (! yys0->yyresolved && yys0->yysemantics.yyfirstVal != NULL)
811              yys1->yysemantics.yyfirstVal =              yys1->yysemantics.yyfirstVal =
812                YYRELOC(yyp0, yyp1, yys0->yysemantics.yyfirstVal, yyoption);                YYRELOC(yyp0, yyp1, yys0->yysemantics.yyfirstVal, yyoption);
813          }          }
814        else        else
815          {          {
816            yySemanticOption* yyv0 = &yyp0->yyoption;            yySemanticOption* yyv0 = &yyp0->yyoption;
817            yySemanticOption* yyv1 = &yyp1->yyoption;            yySemanticOption* yyv1 = &yyp1->yyoption;
# Line 881  yyexpandGLRStack (yyGLRStack* yystack) Line 822  yyexpandGLRStack (yyGLRStack* yystack)
822          }          }
823      }      }
824    if (yystack->yysplitPoint != NULL)    if (yystack->yysplitPoint != NULL)
825      yystack->yysplitPoint = YYRELOC (yystack->yyitems, yynewStack.yyitems,      yystack->yysplitPoint = YYRELOC (yystack->yyitems, yynewStack.yyitems,
826                                   yystack->yysplitPoint, yystate);                                   yystack->yysplitPoint, yystate);
827      
828    for (yyn = 0; yyn < yystack->yytops.yysize; yyn += 1)    for (yyn = 0; yyn < yystack->yytops.yysize; yyn += 1)
829      if (yystack->yytops.yystates[yyn] != NULL)      if (yystack->yytops.yystates[yyn] != NULL)
830        yystack->yytops.yystates[yyn] =        yystack->yytops.yystates[yyn] =
831          YYRELOC (yystack->yyitems, yynewStack.yyitems,          YYRELOC (yystack->yyitems, yynewStack.yyitems,
832                   yystack->yytops.yystates[yyn], yystate);                   yystack->yytops.yystates[yyn], yystate);
833    free (yystack->yyitems);    free (yystack->yyitems);
834    yystack->yyitems = yynewStack.yyitems;    yystack->yyitems = yynewStack.yyitems;
# Line 895  yyexpandGLRStack (yyGLRStack* yystack) Line 836  yyexpandGLRStack (yyGLRStack* yystack)
836    yystack->yyspaceLeft = yynewStack.yyspaceLeft - yysize;    yystack->yyspaceLeft = yynewStack.yyspaceLeft - yysize;
837    
838  #else  #else
839      
840    yyFail (yystack, "parsing stack overflow (%d items)", yysize);    yyFail (yystack, "parsing stack overflow (%d items)", yysize);
841    
842  #endif    #endif
843  }  }
844    
845  static void  static void
846  yyfreeGLRStack (yyGLRStack* yystack)  yyfreeGLRStack (yyGLRStack* yystack)
847  {  {
848    free (yystack->yyitems);    free (yystack->yyitems);
849    yyfreeStateSet (&yystack->yytops);    yyfreeStateSet (&yystack->yytops);
850  }  }
851    
852  /** Assuming that S is a GLRState somewhere on STACK, update the  /** Assuming that S is a GLRState somewhere on STACK, update the
853   *  splitpoint of STACK, if needed, so that it is at least as deep as   *  splitpoint of STACK, if needed, so that it is at least as deep as
854   *  S. */   *  S. */
855  static inline void  static inline void
856  yyupdateSplit (yyGLRStack* yystack, yyGLRState* yys)  yyupdateSplit (yyGLRStack* yystack, yyGLRState* yys)
857  {  {
858    if (yystack->yysplitPoint != NULL && yystack->yysplitPoint > yys)    if (yystack->yysplitPoint != NULL && yystack->yysplitPoint > yys)
859      yystack->yysplitPoint = yys;      yystack->yysplitPoint = yys;
860  }  }
861    
862  /** Invalidate stack #K in STACK. */  /** Invalidate stack #K in STACK. */
863  static inline void  static inline void
864  yymarkStackDeleted (yyGLRStack* yystack, int yyk)  yymarkStackDeleted (yyGLRStack* yystack, int yyk)
865  {  {
866    if (yystack->yytops.yystates[yyk] != NULL)    if (yystack->yytops.yystates[yyk] != NULL)
867      yystack->yylastDeleted = yystack->yytops.yystates[yyk];      yystack->yylastDeleted = yystack->yytops.yystates[yyk];
868    yystack->yytops.yystates[yyk] = NULL;    yystack->yytops.yystates[yyk] = NULL;
869  }  }
870    
871  /** Undelete the last stack that was marked as deleted.  Can only be  /** Undelete the last stack that was marked as deleted.  Can only be
872      done once after a deletion, and only when all other stacks have      done once after a deletion, and only when all other stacks have
873      been deleted. */      been deleted. */
874  static void  static void
# Line 935  yyundeleteLastStack (yyGLRStack* yystack Line 876  yyundeleteLastStack (yyGLRStack* yystack
876  {  {
877    if (yystack->yylastDeleted == NULL || yystack->yytops.yysize != 0)    if (yystack->yylastDeleted == NULL || yystack->yytops.yysize != 0)
878      return;      return;
879    yystack->yytops.yystates[0] = yystack->yylastDeleted;    yystack->yytops.yystates[0] = yystack->yylastDeleted;
880    yystack->yytops.yysize = 1;    yystack->yytops.yysize = 1;
881    YYDPRINTF ((stderr, "Restoring last deleted stack as stack #0.\n"));    YYDPRINTF ((stderr, "Restoring last deleted stack as stack #0.\n"));
882    yystack->yylastDeleted = NULL;    yystack->yylastDeleted = NULL;
# Line 946  yyremoveDeletes (yyGLRStack* yystack) Line 887  yyremoveDeletes (yyGLRStack* yystack)
887  {  {
888    int yyi, yyj;    int yyi, yyj;
889    yyi = yyj = 0;    yyi = yyj = 0;
890    while (yyj < yystack->yytops.yysize)    while (yyj < yystack->yytops.yysize)
891      {      {
892        if (yystack->yytops.yystates[yyi] == NULL)        if (yystack->yytops.yystates[yyi] == NULL)
893          {          {
894            if (YYDEBUG && yyi == yyj)            if (YYDEBUG && yyi == yyj)
895              YYDPRINTF ((stderr, "Removing dead stacks.\n"));              YYDPRINTF ((stderr, "Removing dead stacks.\n"));
896            yystack->yytops.yysize -= 1;            yystack->yytops.yysize -= 1;
897          }          }
898        else        else
899          {          {
900            yystack->yytops.yystates[yyj] = yystack->yytops.yystates[yyi];            yystack->yytops.yystates[yyj] = yystack->yytops.yystates[yyi];
901            if (yyj != yyi)            if (yyj != yyi)
# Line 965  yyremoveDeletes (yyGLRStack* yystack) Line 906  yyremoveDeletes (yyGLRStack* yystack)
906      }      }
907  }  }
908    
909  /** Shift to a new state on stack #K of STACK, corresponding to LR state  /** Shift to a new state on stack #K of STACK, corresponding to LR state
910   * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */   * LRSTATE, at input position POSN, with (resolved) semantic value SVAL. */
911  static inline void  static inline void
912  yyglrShift (yyGLRStack* yystack, int yyk, yyStateNum yylrState, size_t yyposn,  yyglrShift (yyGLRStack* yystack, int yyk, yyStateNum yylrState, size_t yyposn,
913              YYSTYPE yysval, YYLTYPE* yylocp)              YYSTYPE yysval, YYLTYPE* yylocp)
914  {  {
915    yyGLRStackItem* yynewItem;    yyGLRStackItem* yynewItem;
916    
# Line 992  yyglrShift (yyGLRStack* yystack, int yyk Line 933  yyglrShift (yyGLRStack* yystack, int yyk
933   *  corresponding to LR state LRSTATE, at input position POSN, with   *  corresponding to LR state LRSTATE, at input position POSN, with
934   * the (unresolved) semantic value of RHS under the action for RULE. */   * the (unresolved) semantic value of RHS under the action for RULE. */
935  static inline void  static inline void
936  yyglrShiftDefer (yyGLRStack* yystack, int yyk, yyStateNum yylrState,  yyglrShiftDefer (yyGLRStack* yystack, int yyk, yyStateNum yylrState,
937                   size_t yyposn, yyGLRState* yyrhs, yyRuleNum yyrule)                   size_t yyposn, yyGLRState* yyrhs, yyRuleNum yyrule)
938  {  {
939    yyGLRStackItem* yynewItem;    yyGLRStackItem* yynewItem;
# Line 1011  yyglrShiftDefer (yyGLRStack* yystack, in Line 952  yyglrShiftDefer (yyGLRStack* yystack, in
952  }  }
953    
954  /** Pop the symbols consumed by reduction #RULE from the top of stack  /** Pop the symbols consumed by reduction #RULE from the top of stack
955   *  #K of STACK, and perform the appropriate semantic action on their   *  #K of STACK, and perform the appropriate semantic action on their
956   *  semantic values.  Assumes that all ambiguities in semantic values   *  semantic values.  Assumes that all ambiguities in semantic values
957   *  have been previously resolved. Set *VALP to the resulting value,   *  have been previously resolved. Set *VALP to the resulting value,
958   *  and *LOCP to the computed location (if any).  Return value is as   *  and *LOCP to the computed location (if any).  Return value is as
959   *  for userAction. */   *  for userAction. */
# Line 1022  yydoAction (yyGLRStack* yystack, int yyk Line 963  yydoAction (yyGLRStack* yystack, int yyk
963  {  {
964    int yynrhs = yyrhsLength (yyrule);    int yynrhs = yyrhsLength (yyrule);
965    
966    if (yystack->yysplitPoint == NULL)    if (yystack->yysplitPoint == NULL)
967      {      {
968        /* Standard special case: single stack. */        /* Standard special case: single stack. */
969        yyGLRStackItem* yyrhs = (yyGLRStackItem*) yystack->yytops.yystates[yyk];        yyGLRStackItem* yyrhs = (yyGLRStackItem*) yystack->yytops.yystates[yyk];
# Line 1030  yydoAction (yyGLRStack* yystack, int yyk Line 971  yydoAction (yyGLRStack* yystack, int yyk
971        yystack->yynextFree -= yynrhs;        yystack->yynextFree -= yynrhs;
972        yystack->yyspaceLeft += yynrhs;        yystack->yyspaceLeft += yynrhs;
973        yystack->yytops.yystates[0] = & yystack->yynextFree[-1].yystate;        yystack->yytops.yystates[0] = & yystack->yynextFree[-1].yystate;
974        if (yynrhs == 0)        if (yynrhs == 0)
975          {          {
976            *yyvalp = yyval_default;            *yyvalp = yyval_default;
977            *yylocp = yyloc_default;            *yylocp = yyloc_default;
978          }          }
979        else        else
980          {          {
981            *yyvalp = yyrhs[1-yynrhs].yystate.yysemantics.yysval;            *yyvalp = yyrhs[1-yynrhs].yystate.yysemantics.yysval;
982            *yylocp = yyrhs[1-yynrhs].yystate.yyloc;            *yylocp = yyrhs[1-yynrhs].yystate.yyloc;
983          }          }
984        return yyuserAction (yyrule, yynrhs, yyrhs, yyvalp, yylocp, yystack);        return yyuserAction (yyrule, yynrhs, yyrhs, yyvalp, yylocp, yystack);
985      }      }
986    else    else
987      {      {
988        int yyi;        int yyi;
989        yyGLRState* yys;        yyGLRState* yys;
990        yyGLRStackItem yyrhsVals[YYMAXRHS];        yyGLRStackItem yyrhsVals[YYMAXRHS];
991        for (yyi = yynrhs-1, yys = yystack->yytops.yystates[yyk]; yyi >= 0;        for (yyi = yynrhs-1, yys = yystack->yytops.yystates[yyk]; yyi >= 0;
992             yyi -= 1, yys = yys->yypred)             yyi -= 1, yys = yys->yypred)
993          {          {
994            assert (yys->yypred != NULL);            assert (yys->yypred != NULL);
995            yyrhsVals[yyi].yystate.yyresolved = yytrue;            yyrhsVals[yyi].yystate.yyresolved = yytrue;
# Line 1057  yydoAction (yyGLRStack* yystack, int yyk Line 998  yydoAction (yyGLRStack* yystack, int yyk
998          }          }
999        yyupdateSplit (yystack, yys);        yyupdateSplit (yystack, yys);
1000        yystack->yytops.yystates[yyk] = yys;        yystack->yytops.yystates[yyk] = yys;
1001        if (yynrhs == 0)        if (yynrhs == 0)
1002          {          {
1003            *yyvalp = yyval_default;            *yyvalp = yyval_default;
1004            *yylocp = yyloc_default;            *yylocp = yyloc_default;
1005          }          }
1006        else        else
1007          {          {
1008            *yyvalp = yyrhsVals[0].yystate.yysemantics.yysval;            *yyvalp = yyrhsVals[0].yystate.yysemantics.yysval;
1009            *yylocp = yyrhsVals[0].yystate.yyloc;            *yylocp = yyrhsVals[0].yystate.yyloc;
1010          }          }
1011        return yyuserAction (yyrule, yynrhs, yyrhsVals + (yynrhs-1),        return yyuserAction (yyrule, yynrhs, yyrhsVals + (yynrhs-1),
1012                             yyvalp, yylocp, yystack);                             yyvalp, yylocp, yystack);
1013      }      }
1014  }  }
1015    
1016  /** Pop items off stack #K of STACK according to grammar rule RULE,  /** Pop items off stack #K of STACK according to grammar rule RULE,
1017   *  and push back on the resulting nonterminal symbol.  Perform the   *  and push back on the resulting nonterminal symbol.  Perform the
1018   *  semantic action associated with RULE and store its value with the   *  semantic action associated with RULE and store its value with the
1019   *  newly pushed state, if FORCEEVAL or if STACK is currently   *  newly pushed state, if FORCEEVAL or if STACK is currently
1020   *  unambiguous.  Otherwise, store the deferred semantic action with   *  unambiguous.  Otherwise, store the deferred semantic action with
1021   *  the new state.  If the new state would have an identical input   *  the new state.  If the new state would have an identical input
1022   *  position, LR state, and predecessor to an existing state on the stack,   *  position, LR state, and predecessor to an existing state on the stack,
1023   *  it is identified with that existing state, eliminating stack #K from   *  it is identified with that existing state, eliminating stack #K from
1024   *  the STACK. In this case, the (necessarily deferred) semantic value is   *  the STACK. In this case, the (necessarily deferred) semantic value is
1025   *  added to the options for the existing state's semantic value.   *  added to the options for the existing state's semantic value.
1026   */   */
1027  static inline YYRESULTTAG  static inline YYRESULTTAG
1028  yyglrReduce (yyGLRStack* yystack, int yyk, yyRuleNum yyrule, bool yyforceEval)  yyglrReduce (yyGLRStack* yystack, int yyk, yyRuleNum yyrule, bool yyforceEval)
1029  {  {
1030    int yyposn = yystack->yytops.yystates[yyk]->yyposn;    int yyposn = yystack->yytops.yystates[yyk]->yyposn;
1031    
1032    if (yyforceEval || yystack->yysplitPoint == NULL)    if (yyforceEval || yystack->yysplitPoint == NULL)
1033      {      {
1034        YYSTYPE yysval;        YYSTYPE yysval;
1035        YYLTYPE yyloc;        YYLTYPE yyloc;
1036        
1037        YYCHK (yydoAction (yystack, yyk, yyrule, &yysval, &yyloc));        YYCHK (yydoAction (yystack, yyk, yyrule, &yysval, &yyloc));
1038        yyglrShift (yystack, yyk,        yyglrShift (yystack, yyk,
1039                    yyLRgotoState (yystack->yytops.yystates[yyk]->yylrState,                    yyLRgotoState (yystack->yytops.yystates[yyk]->yylrState,
1040                                   yylhsNonterm (yyrule)),                                   yylhsNonterm (yyrule)),
1041                  yyposn, yysval, &yyloc);                  yyposn, yysval, &yyloc);
1042        YYDPRINTF ((stderr, "Reduced stack %d by rule #%d. Now in state %d.\n",        YYDPRINTF ((stderr, "Reduced stack %d by rule #%d. Now in state %d.\n",
1043                    yyk, yyrule-1, yystack->yytops.yystates[yyk]->yylrState));                    yyk, yyrule-1, yystack->yytops.yystates[yyk]->yylrState));
1044      }      }
1045    else    else
1046      {      {
1047        int yyi, yyn;        int yyi, yyn;
1048        yyGLRState* yys, *yys0 = yystack->yytops.yystates[yyk];        yyGLRState* yys, *yys0 = yystack->yytops.yystates[yyk];
1049        yyStateNum yynewLRState;        yyStateNum yynewLRState;
1050    
1051        for (yys = yystack->yytops.yystates[yyk], yyn = yyrhsLength (yyrule);        for (yys = yystack->yytops.yystates[yyk], yyn = yyrhsLength (yyrule);
1052             yyn > 0; yyn -= 1)             yyn > 0; yyn -= 1)
1053          {          {
1054            yys = yys->yypred;            yys = yys->yypred;
1055            assert (yys != NULL);            assert (yys != NULL);
1056          }          }
1057        yyupdateSplit (yystack, yys);        yyupdateSplit (yystack, yys);
1058        yynewLRState = yyLRgotoState (yys->yylrState, yylhsNonterm (yyrule));        yynewLRState = yyLRgotoState (yys->yylrState, yylhsNonterm (yyrule));
1059        YYDPRINTF ((stderr,        YYDPRINTF ((stderr,
1060                    "Reduced stack %d by rule #%d; action deferred. "                    "Reduced stack %d by rule #%d; action deferred. "
1061                    "Now in state %d.\n",                    "Now in state %d.\n",
1062                    yyk, yyrule-1, yynewLRState));                    yyk, yyrule-1, yynewLRState));
1063        for (yyi = 0; yyi < yystack->yytops.yysize; yyi += 1)        for (yyi = 0; yyi < yystack->yytops.yysize; yyi += 1)
1064          if (yyi != yyk && yystack->yytops.yystates[yyi] != NULL)          if (yyi != yyk && yystack->yytops.yystates[yyi] != NULL)
1065            {            {
1066              yyGLRState* yyp, *yysplit = yystack->yysplitPoint;              yyGLRState* yyp, *yysplit = yystack->yysplitPoint;
1067              yyp = yystack->yytops.yystates[yyi];              yyp = yystack->yytops.yystates[yyi];
1068              while (yyp != yys && yyp != yysplit && yyp->yyposn >= yyposn)              while (yyp != yys && yyp != yysplit && yyp->yyposn >= yyposn)
1069                {                {
1070                  if (yyp->yylrState == yynewLRState && yyp->yypred == yys)                  if (yyp->yylrState == yynewLRState && yyp->yypred == yys)
1071                    {                    {
1072                      yyaddDeferredAction (yystack, yyp, yys0, yyrule);                      yyaddDeferredAction (yystack, yyp, yys0, yyrule);
1073                      yymarkStackDeleted (yystack, yyk);                      yymarkStackDeleted (yystack, yyk);
# Line 1139  yyglrReduce (yyGLRStack* yystack, int yy Line 1080  yyglrReduce (yyGLRStack* yystack, int yy
1080            }            }
1081        yystack->yytops.yystates[yyk] = yys;        yystack->yytops.yystates[yyk] = yys;
1082        yyglrShiftDefer (yystack, yyk, yynewLRState, yyposn, yys0, yyrule);        yyglrShiftDefer (yystack, yyk, yynewLRState, yyposn, yys0, yyrule);
1083      }          }
1084    return 0;    return 0;
1085  }  }
1086    
1087  static int  static int
1088  yysplitStack (yyGLRStack* yystack, int yyk)  yysplitStack (yyGLRStack* yystack, int yyk)
1089  {  {
1090    if (yystack->yysplitPoint == NULL)    if (yystack->yysplitPoint == NULL)
1091      {      {
1092        assert (yyk == 0);        assert (yyk == 0);
1093        yystack->yysplitPoint = yystack->yytops.yystates[yyk];        yystack->yysplitPoint = yystack->yytops.yystates[yyk];
1094      }      }
1095    if (yystack->yytops.yysize >= yystack->yytops.yycapacity)    if (yystack->yytops.yysize >= yystack->yytops.yycapacity)
1096      {      {
1097        yystack->yytops.yycapacity *= 2;        yystack->yytops.yycapacity *= 2;
1098        yystack->yytops.yystates =        yystack->yytops.yystates =
1099          (yyGLRState**) realloc (yystack->yytops.yystates,          (yyGLRState**) realloc (yystack->yytops.yystates,
1100                                  yystack->yytops.yycapacity                                  yystack->yytops.yycapacity
1101                                  * sizeof (yyGLRState*));                                  * sizeof (yyGLRState*));
1102      }      }
1103    yystack->yytops.yystates[yystack->yytops.yysize]    yystack->yytops.yystates[yystack->yytops.yysize]
1104      = yystack->yytops.yystates[yyk];      = yystack->yytops.yystates[yyk];
1105    yystack->yytops.yysize += 1;    yystack->yytops.yysize += 1;
1106    return yystack->yytops.yysize-1;    return yystack->yytops.yysize-1;
# Line 1171  yysplitStack (yyGLRStack* yystack, int y Line 1112  yysplitStack (yyGLRStack* yystack, int y
1112  static bool  static bool
1113  yyidenticalOptions (yySemanticOption* yyy0, yySemanticOption* yyy1)  yyidenticalOptions (yySemanticOption* yyy0, yySemanticOption* yyy1)
1114  {  {
1115    if (yyy0->yyrule == yyy1->yyrule)    if (yyy0->yyrule == yyy1->yyrule)
1116      {      {
1117        yyGLRState *yys0, *yys1;        yyGLRState *yys0, *yys1;
1118        int yyn;        int yyn;
1119        for (yys0 = yyy0->yystate, yys1 = yyy1->yystate,        for (yys0 = yyy0->yystate, yys1 = yyy1->yystate,
1120             yyn = yyrhsLength (yyy0->yyrule);             yyn = yyrhsLength (yyy0->yyrule);
1121             yyn > 0;             yyn > 0;
1122             yys0 = yys0->yypred, yys1 = yys1->yypred, yyn -= 1)             yys0 = yys0->yypred, yys1 = yys1->yypred, yyn -= 1)
# Line 1188  yyidenticalOptions (yySemanticOption* yy Line 1129  yyidenticalOptions (yySemanticOption* yy
1129  }  }
1130    
1131  /** Assuming identicalOptions (Y0,Y1), (destructively) merge the  /** Assuming identicalOptions (Y0,Y1), (destructively) merge the
1132   *  alternative semantic values for the RHS-symbols of Y1 into the   *  alternative semantic values for the RHS-symbols of Y1 into the
1133   *  corresponding semantic value sets of the symbols of Y0. */   *  corresponding semantic value sets of the symbols of Y0. */
1134  static void  static void
1135  yymergeOptionSets (yySemanticOption* yyy0, yySemanticOption* yyy1)  yymergeOptionSets (yySemanticOption* yyy0, yySemanticOption* yyy1)
1136  {  {
1137    yyGLRState *yys0, *yys1;    yyGLRState *yys0, *yys1;
1138    int yyn;    int yyn;
1139    for (yys0 = yyy0->yystate, yys1 = yyy1->yystate,    for (yys0 = yyy0->yystate, yys1 = yyy1->yystate,
1140         yyn = yyrhsLength (yyy0->yyrule);         yyn = yyrhsLength (yyy0->yyrule);
1141         yyn > 0;         yyn > 0;
1142         yys0 = yys0->yypred, yys1 = yys1->yypred, yyn -= 1)         yys0 = yys0->yypred, yys1 = yys1->yypred, yyn -= 1)
1143      if (yys0 == yys1)      if (yys0 == yys1)
1144        break;        break;
1145      else if (! yys0->yyresolved && ! yys1->yyresolved)      else if (! yys0->yyresolved && ! yys1->yyresolved)
1146        {        {
1147          yySemanticOption* yyz;          yySemanticOption* yyz;
1148          for (yyz = yys0->yysemantics.yyfirstVal; yyz->yynext != NULL;          for (yyz = yys0->yysemantics.yyfirstVal; yyz->yynext != NULL;
1149               yyz = yyz->yynext)               yyz = yyz->yynext)
1150            ;            ;
1151          yyz->yynext = yys1->yysemantics.yyfirstVal;          yyz->yynext = yys1->yysemantics.yyfirstVal;
# Line 1220  yypreference (yySemanticOption* yyy0, yy Line 1161  yypreference (yySemanticOption* yyy0, yy
1161    yyRuleNum yyr0 = yyy0->yyrule, yyr1 = yyy1->yyrule;    yyRuleNum yyr0 = yyy0->yyrule, yyr1 = yyy1->yyrule;
1162    int yyp0 = yydprec[yyr0], yyp1 = yydprec[yyr1];    int yyp0 = yydprec[yyr0], yyp1 = yydprec[yyr1];
1163    
1164    if (yyp0 == yyp1)    if (yyp0 == yyp1)
1165      {      {
1166        if (yymerger[yyr0] == 0 || yymerger[yyr0] != yymerger[yyr1])        if (yymerger[yyr0] == 0 || yymerger[yyr0] != yymerger[yyr1])
1167          return 0;          return 0;
# Line 1236  yypreference (yySemanticOption* yyy0, yy Line 1177  yypreference (yySemanticOption* yyy0, yy
1177    return 0;    return 0;
1178  }  }
1179    
1180  static YYRESULTTAG yyresolveValue (yySemanticOption* yyoptionList,  static YYRESULTTAG yyresolveValue (yySemanticOption* yyoptionList,
1181                                     yyGLRStack* yystack, YYSTYPE* yyvalp,                                     yyGLRStack* yystack, YYSTYPE* yyvalp,
1182                                     YYLTYPE* yylocp);                                     YYLTYPE* yylocp);
1183    
1184  static YYRESULTTAG  static YYRESULTTAG
1185  yyresolveStates (yyGLRState* yys, int yyn, yyGLRStack* yystack)  yyresolveStates (yyGLRState* yys, int yyn, yyGLRStack* yystack)
1186  {  {
1187    YYRESULTTAG yyflag;    YYRESULTTAG yyflag;
1188    if (yyn > 0)    if (yyn > 0)
1189      {      {
1190        assert (yys->yypred != NULL);        assert (yys->yypred != NULL);
1191        yyflag = yyresolveStates (yys->yypred, yyn-1, yystack);        yyflag = yyresolveStates (yys->yypred, yyn-1, yystack);
1192        if (yyflag != yyok)        if (yyflag != yyok)
1193          return yyflag;          return yyflag;
1194        if (! yys->yyresolved)        if (! yys->yyresolved)
1195          {          {
1196            yyflag = yyresolveValue (yys->yysemantics.yyfirstVal, yystack,            yyflag = yyresolveValue (yys->yysemantics.yyfirstVal, yystack,
1197                                 &yys->yysemantics.yysval, &yys->yyloc);                                 &yys->yysemantics.yysval, &yys->yyloc);
# Line 1263  yyresolveStates (yyGLRState* yys, int yy Line 1204  yyresolveStates (yyGLRState* yys, int yy
1204  }  }
1205    
1206  static YYRESULTTAG  static YYRESULTTAG
1207  yyresolveAction (yySemanticOption* yyopt, yyGLRStack* yystack,  yyresolveAction (yySemanticOption* yyopt, yyGLRStack* yystack,
1208                   YYSTYPE* yyvalp, YYLTYPE* yylocp)                   YYSTYPE* yyvalp, YYLTYPE* yylocp)
1209  {  {
1210    yyGLRStackItem yyrhsVals[YYMAXRHS];    yyGLRStackItem yyrhsVals[YYMAXRHS];
# Line 1272  yyresolveAction (yySemanticOption* yyopt Line 1213  yyresolveAction (yySemanticOption* yyopt
1213    
1214    yynrhs = yyrhsLength (yyopt->yyrule);    yynrhs = yyrhsLength (yyopt->yyrule);
1215    YYCHK (yyresolveStates (yyopt->yystate, yynrhs, yystack));    YYCHK (yyresolveStates (yyopt->yystate, yynrhs, yystack));
1216    for (yyi = yynrhs-1, yys = yyopt->yystate; yyi >= 0;    for (yyi = yynrhs-1, yys = yyopt->yystate; yyi >= 0;
1217         yyi -= 1, yys = yys->yypred)         yyi -= 1, yys = yys->yypred)
1218      {      {
1219        assert (yys->yypred != NULL);        assert (yys->yypred != NULL);
1220        yyrhsVals[yyi].yystate.yyresolved = yytrue;        yyrhsVals[yyi].yystate.yyresolved = yytrue;
1221        yyrhsVals[yyi].yystate.yysemantics.yysval = yys->yysemantics.yysval;        yyrhsVals[yyi].yystate.yysemantics.yysval = yys->yysemantics.yysval;
1222        yyrhsVals[yyi].yystate.yyloc = yys->yyloc;        yyrhsVals[yyi].yystate.yyloc = yys->yyloc;
1223      }        }
1224    return yyuserAction (yyopt->yyrule, yynrhs, yyrhsVals + (yynrhs-1),    return yyuserAction (yyopt->yyrule, yynrhs, yyrhsVals + (yynrhs-1),
1225                         yyvalp, yylocp, yystack);                         yyvalp, yylocp, yystack);
1226  }  }
1227    
1228  #if YYDEBUG  #if YYDEBUG
1229  static yyGLRState YYLEFTMOST_STATE = { 0, NULL, -1, 0, { NULL } };  static yyGLRState YYLEFTMOST_STATE = { 0, NULL, -1, 0, { NULL } };
1230    
1231  static void yyreportTree (yySemanticOption* yyx, int yyindent)  static void yyreportTree (yySemanticOption* yyx, int yyindent)
1232  {  {
1233    int yynrhs = yyrhsLength (yyx->yyrule);    int yynrhs = yyrhsLength (yyx->yyrule);
1234    int yyi;    int yyi;
# Line 1303  static void yyreportTree (yySemanticOpti Line 1244  static void yyreportTree (yySemanticOpti
1244    
1245    if (yys->yyposn+1 > yyx->yystate->yyposn)    if (yys->yyposn+1 > yyx->yystate->yyposn)
1246      YYFPRINTF (stderr, "%*s%s -> <Rule %d, empty>\n",      YYFPRINTF (stderr, "%*s%s -> <Rule %d, empty>\n",
1247                 yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)),                 yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)),
1248                 yyx->yyrule);                 yyx->yyrule);
1249    else    else
1250      YYFPRINTF (stderr, "%*s%s -> <Rule %d, tokens %d .. %d>\n",      YYFPRINTF (stderr, "%*s%s -> <Rule %d, tokens %d .. %d>\n",
1251                 yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)),                 yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)),
1252                 yyx->yyrule, yys->yyposn+1, yyx->yystate->yyposn);                 yyx->yyrule, yys->yyposn+1, yyx->yystate->yyposn);
1253    for (yyi = 1; yyi <= yynrhs; yyi += 1)    for (yyi = 1; yyi <= yynrhs; yyi += 1)
1254      {      {
1255        if (yystates[yyi]->yyresolved)        if (yystates[yyi]->yyresolved)
1256          {          {
1257            if (yystates[yyi-1]->yyposn+1 > yystates[yyi]->yyposn)            if (yystates[yyi-1]->yyposn+1 > yystates[yyi]->yyposn)
1258              YYFPRINTF (stderr, "%*s%s <empty>\n", yyindent+2, "",              YYFPRINTF (stderr, "%*s%s <empty>\n", yyindent+2, "",
# Line 1321  static void yyreportTree (yySemanticOpti Line 1262  static void yyreportTree (yySemanticOpti
1262                         yytokenName (yyrhs[yyprhs[yyx->yyrule]+yyi-1]),                         yytokenName (yyrhs[yyprhs[yyx->yyrule]+yyi-1]),
1263                         yystates[yyi-1]->yyposn+1, yystates[yyi]->yyposn);                         yystates[yyi-1]->yyposn+1, yystates[yyi]->yyposn);
1264          }          }
1265        else        else
1266          yyreportTree (yystates[yyi]->yysemantics.yyfirstVal, yyindent+2);          yyreportTree (yystates[yyi]->yysemantics.yyfirstVal, yyindent+2);
1267      }      }
1268  }  }
1269  #endif      #endif
1270    
1271  static void  static void
1272  yyreportAmbiguity (yySemanticOption* yyx0, yySemanticOption* yyx1,  yyreportAmbiguity (yySemanticOption* yyx0, yySemanticOption* yyx1,
# Line 1346  yyreportAmbiguity (yySemanticOption* yyx Line 1287  yyreportAmbiguity (yySemanticOption* yyx
1287  /** Resolve the ambiguity represented by OPTIONLIST, perform the indicated  /** Resolve the ambiguity represented by OPTIONLIST, perform the indicated
1288   *  actions, and return the result. */   *  actions, and return the result. */
1289  static YYRESULTTAG  static YYRESULTTAG
1290  yyresolveValue (yySemanticOption* yyoptionList, yyGLRStack* yystack,  yyresolveValue (yySemanticOption* yyoptionList, yyGLRStack* yystack,
1291                  YYSTYPE* yyvalp, YYLTYPE* yylocp)                  YYSTYPE* yyvalp, YYLTYPE* yylocp)
1292  {  {
1293    yySemanticOption* yybest;    yySemanticOption* yybest;
1294    yySemanticOption* yyp;    yySemanticOption* yyp;
1295    int yymerge;    int yymerge;
1296    
1297    yybest = yyoptionList;    yybest = yyoptionList;
1298    yymerge = 0;    yymerge = 0;
1299    for (yyp = yyoptionList->yynext; yyp != NULL; yyp = yyp->yynext)    for (yyp = yyoptionList->yynext; yyp != NULL; yyp = yyp->yynext)
1300      {      {
1301        if (yyidenticalOptions (yybest, yyp))        if (yyidenticalOptions (yybest, yyp))
1302          yymergeOptionSets (yybest, yyp);          yymergeOptionSets (yybest, yyp);
1303        else        else
1304          switch (yypreference (yybest, yyp))          switch (yypreference (yybest, yyp))
1305            {            {
1306            case 0:            case 0:
1307              yyreportAmbiguity (yybest, yyp, yystack);              yyreportAmbiguity (yybest, yyp, yystack);
# Line 1377  yyresolveValue (yySemanticOption* yyopti Line 1318  yyresolveValue (yySemanticOption* yyopti
1318            }            }
1319      }      }
1320    
1321    if (yymerge)    if (yymerge)
1322      {      {
1323        int yyprec = yydprec[yybest->yyrule];        int yyprec = yydprec[yybest->yyrule];
1324        YYCHK (yyresolveAction (yybest, yystack, yyvalp, yylocp));        YYCHK (yyresolveAction (yybest, yystack, yyvalp, yylocp));
1325        for (yyp = yybest->yynext; yyp != NULL; yyp = yyp->yynext)        for (yyp = yybest->yynext; yyp != NULL; yyp = yyp->yynext)
1326          {          {
1327            if (yyprec == yydprec[yyp->yyrule])            if (yyprec == yydprec[yyp->yyrule])
1328              {              {
1329                YYSTYPE yyval1;                YYSTYPE yyval1;
1330                YYLTYPE yydummy;                YYLTYPE yydummy;
# Line 1398  yyresolveValue (yySemanticOption* yyopti Line 1339  yyresolveValue (yySemanticOption* yyopti
1339  }  }
1340    
1341  static YYRESULTTAG  static YYRESULTTAG
1342  yyresolveStack (yyGLRStack* yystack)  yyresolveStack (yyGLRStack* yystack)
1343  {  {
1344    if (yystack->yysplitPoint != NULL)    if (yystack->yysplitPoint != NULL)
1345      {      {
1346        yyGLRState* yys;        yyGLRState* yys;
1347        int yyn;        int yyn;
1348    
1349        for (yyn = 0, yys = yystack->yytops.yystates[0];        for (yyn = 0, yys = yystack->yytops.yystates[0];
1350             yys != yystack->yysplitPoint;             yys != yystack->yysplitPoint;
1351             yys = yys->yypred, yyn += 1)             yys = yys->yypred, yyn += 1)
1352          ;          ;
1353        YYCHK (yyresolveStates (yystack->yytops.yystates[0], yyn, yystack));        YYCHK (yyresolveStates (yystack->yytops.yystates[0], yyn, yystack));
# Line 1415  yyresolveStack (yyGLRStack* yystack) Line 1356  yyresolveStack (yyGLRStack* yystack)
1356  }  }
1357    
1358  static void  static void
1359  yycompressStack (yyGLRStack* yystack)  yycompressStack (yyGLRStack* yystack)
1360  {  {
1361    yyGLRState* yyp, *yyq, *yyr;    yyGLRState* yyp, *yyq, *yyr;
1362    
1363    if (yystack->yytops.yysize != 1 || yystack->yysplitPoint == NULL)    if (yystack->yytops.yysize != 1 || yystack->yysplitPoint == NULL)
1364      return;      return;
1365    
1366    for (yyp = yystack->yytops.yystates[0], yyq = yyp->yypred, yyr = NULL;    for (yyp = yystack->yytops.yystates[0], yyq = yyp->yypred, yyr = NULL;
1367         yyp != yystack->yysplitPoint;         yyp != yystack->yysplitPoint;
1368         yyr = yyp, yyp = yyq, yyq = yyp->yypred)         yyr = yyp, yyp = yyq, yyq = yyp->yypred)
1369      yyp->yypred = yyr;      yyp->yypred = yyr;
1370      
1371    yystack->yyspaceLeft += yystack->yynextFree - yystack->yyitems;    yystack->yyspaceLeft += yystack->yynextFree - yystack->yyitems;
1372    yystack->yynextFree = ((yyGLRStackItem*) yystack->yysplitPoint) + 1;    yystack->yynextFree = ((yyGLRStackItem*) yystack->yysplitPoint) + 1;
1373    yystack->yyspaceLeft -= yystack->yynextFree - yystack->yyitems;    yystack->yyspaceLeft -= yystack->yynextFree - yystack->yyitems;
1374    yystack->yysplitPoint = NULL;    yystack->yysplitPoint = NULL;
1375    yystack->yylastDeleted = NULL;    yystack->yylastDeleted = NULL;
1376      
1377    while (yyr != NULL)    while (yyr != NULL)
1378      {        {
1379        yystack->yynextFree->yystate = *yyr;        yystack->yynextFree->yystate = *yyr;
1380        yyr = yyr->yypred;        yyr = yyr->yypred;
1381        yystack->yynextFree->yystate.yypred = & yystack->yynextFree[-1].yystate;        yystack->yynextFree->yystate.yypred = & yystack->yynextFree[-1].yystate;
# Line 1445  yycompressStack (yyGLRStack* yystack) Line 1386  yycompressStack (yyGLRStack* yystack)
1386  }  }
1387    
1388  static YYRESULTTAG  static YYRESULTTAG
1389  yyprocessOneStack (yyGLRStack* yystack, int yyk,  yyprocessOneStack (yyGLRStack* yystack, int yyk,
1390                     size_t yyposn, YYSTYPE* yylvalp, YYLTYPE* yyllocp)                     size_t yyposn, YYSTYPE* yylvalp, YYLTYPE* yyllocp)
1391  {  {
1392    int yyaction;    int yyaction;
# Line 1453  yyprocessOneStack (yyGLRStack* yystack, Line 1394  yyprocessOneStack (yyGLRStack* yystack,
1394    yyRuleNum yyrule;    yyRuleNum yyrule;
1395    yySymbol* const yytokenp = yystack->yytokenp;    yySymbol* const yytokenp = yystack->yytokenp;
1396    
1397    while (yystack->yytops.yystates[yyk] != NULL)    while (yystack->yytops.yystates[yyk] != NULL)
1398      {      {
1399        yyStateNum yystate = yystack->yytops.yystates[yyk]->yylrState;        yyStateNum yystate = yystack->yytops.yystates[yyk]->yylrState;
1400    
1401        assert (yystate != YYFINAL);        assert (yystate != YYFINAL);
1402        if (yyisDefaultedState (yystate))        if (yyisDefaultedState (yystate))
1403          {          {
1404            yyrule = yydefaultAction (yystate);            yyrule = yydefaultAction (yystate);
1405            if (yyrule == 0)            if (yyrule == 0)
1406              {              {
1407                YYDPRINTF ((stderr, "Stack %d dies.\n", yyk));                YYDPRINTF ((stderr, "Stack %d dies.\n", yyk));
1408                yymarkStackDeleted (yystack, yyk);                yymarkStackDeleted (yystack, yyk);
# Line 1469  yyprocessOneStack (yyGLRStack* yystack, Line 1410  yyprocessOneStack (yyGLRStack* yystack,
1410              }              }
1411            YYCHK (yyglrReduce (yystack, yyk, yyrule, yyfalse));            YYCHK (yyglrReduce (yystack, yyk, yyrule, yyfalse));
1412          }          }
1413        else        else
1414          {          {
1415            if (*yytokenp == YYEMPTY)            if (*yytokenp == YYEMPTY)
1416              {              {
1417                yychar = YYLEX;                yychar = YYLEX;
1418                *yytokenp = YYTRANSLATE(yychar);                *yytokenp = YYTRANSLATE(yychar);
# Line 1479  yyprocessOneStack (yyGLRStack* yystack, Line 1420  yyprocessOneStack (yyGLRStack* yystack,
1420              }              }
1421            yygetLRActions (yystate, *yytokenp, &yyaction, &yyconflicts);            yygetLRActions (yystate, *yytokenp, &yyaction, &yyconflicts);
1422    
1423            while (*yyconflicts != 0)            while (*yyconflicts != 0)
1424              {              {
1425                int yynewStack = yysplitStack (yystack, yyk);                int yynewStack = yysplitStack (yystack, yyk);
1426                YYDPRINTF ((stderr, "Splitting off stack %d from %d.\n",                YYDPRINTF ((stderr, "Splitting off stack %d from %d.\n",
1427                            yynewStack, yyk));                            yynewStack, yyk));
1428                YYCHK (yyglrReduce (yystack, yynewStack, *yyconflicts, yyfalse));                YYCHK (yyglrReduce (yystack, yynewStack, *yyconflicts, yyfalse));
1429                YYCHK (yyprocessOneStack (yystack, yynewStack, yyposn,                YYCHK (yyprocessOneStack (yystack, yynewStack, yyposn,
1430                                          yylvalp, yyllocp));                                          yylvalp, yyllocp));
1431                yyconflicts += 1;                yyconflicts += 1;
1432              }              }
1433          
1434            if (yyisShiftAction (yyaction))            if (yyisShiftAction (yyaction))
1435              {              {
1436                YYDPRINTF ((stderr, "Shifted token %s on stack %d, ",                YYDPRINTF ((stderr, "Shifted token %s on stack %d, ",
1437                            yytokenName (*yytokenp), yyk));                            yytokenName (*yytokenp), yyk));
1438                yyglrShift (yystack, yyk, yyaction, yyposn+1, *yylvalp, yyllocp);                yyglrShift (yystack, yyk, yyaction, yyposn+1, *yylvalp, yyllocp);
1439                YYDPRINTF ((stderr, "which is now in state #%d\n",                YYDPRINTF ((stderr, "which is now in state #%d\n",
1440                            yystack->yytops.yystates[yyk]->yylrState));                            yystack->yytops.yystates[yyk]->yylrState));
1441                break;                break;
1442              }              }
1443            else if (yyisErrorAction (yyaction))            else if (yyisErrorAction (yyaction))
1444              {              {
1445                YYDPRINTF ((stderr, "Stack %d dies.\n", yyk));                YYDPRINTF ((stderr, "Stack %d dies.\n", yyk));
1446                yymarkStackDeleted (yystack, yyk);                yymarkStackDeleted (yystack, yyk);
# Line 1519  yyreportParseError (yyGLRStack* yystack, Line 1460  yyreportParseError (yyGLRStack* yystack,
1460    
1461    if (yystack->yyerrState == 0)    if (yystack->yyerrState == 0)
1462      {      {
1463  #if YYERROR_VERBOSE    #if YYERROR_VERBOSE
1464        int yyn, yyx, yycount, yysize;        int yyn, yyx, yycount, yysize;
1465        char* yyprefix;        char* yyprefix;
1466        char* yyp;        char* yyp;
# Line 1530  yyreportParseError (yyGLRStack* yystack, Line 1471  yyreportParseError (yyGLRStack* yystack,
1471            yycount = 0;            yycount = 0;
1472            /* Start YYX at -YYN if negative to avoid negative indexes in            /* Start YYX at -YYN if negative to avoid negative indexes in
1473               YYCHECK.  */               YYCHECK.  */
1474            yysize = sizeof ("parse error, unexpected ")            yysize = sizeof ("parse error, unexpected ")
1475              + strlen (yytokenName (*yytokenp));              + strlen (yytokenName (*yytokenp));
1476            yyprefix = ", expecting ";            yyprefix = ", expecting ";
1477            for (yyx = yyn < 0 ? -yyn : 0; yyx < yytname_size && yycount <= 5;            for (yyx = yyn < 0 ? -yyn : 0; yyx < yytname_size && yycount <= 5;
1478                 yyx += 1)                 yyx += 1)
1479              if (yycheck[yyx + yyn] == yyx)              if (yycheck[yyx + yyn] == yyx)
1480                yysize += strlen (yytokenName (yyx)) + strlen (yyprefix),                yysize += strlen (yytokenName (yyx)) + strlen (yyprefix),
1481                  yycount += 1, yyprefix = " or ";                  yycount += 1, yyprefix = " or ";
1482            yymsg = yyp = (char*) malloc (yysize);            yymsg = yyp = (char*) malloc (yysize);
1483            yyp += sprintf (yyp, "parse error, unexpected %s",            yyp += sprintf (yyp, "parse error, unexpected %s",
1484                            yytokenName (*yytokenp));                            yytokenName (*yytokenp));
1485            if (yycount < 5)            if (yycount < 5)
1486              {              {
# Line 1563  yyreportParseError (yyGLRStack* yystack, Line 1504  yyreportParseError (yyGLRStack* yystack,
1504    
1505  /* Recover from a syntax error on STACK, assuming that TOKENP,  /* Recover from a syntax error on STACK, assuming that TOKENP,
1506     YYLVALP, and YYLLOCP point to the syntactic category, semantic     YYLVALP, and YYLLOCP point to the syntactic category, semantic
1507     value, and location of the lookahead.       value, and location of the lookahead.
1508     NOTE: This uses the panic-mode recovery algorithm described in the     NOTE: This uses the panic-mode recovery algorithm described in the
1509     Bison documentation, which differs from what is in bison.simple.       Bison documentation, which differs from what is in bison.simple.
1510     Specifically, this routine performs no reductions before shifting     Specifically, this routine performs no reductions before shifting
1511     the error token. */     the error token. */
1512  static void  static void
1513  yyrecoverParseError (yyGLRStack* yystack, YYSTYPE* yylvalp, YYLTYPE* yyllocp)  yyrecoverParseError (yyGLRStack* yystack, YYSTYPE* yylvalp, YYLTYPE* yyllocp)
1514  {  {
1515    yySymbol* const yytokenp = yystack->yytokenp;    yySymbol* const yytokenp = yystack->yytokenp;
1516    int yyk, yyj;    int yyk, yyj;
1517    
1518    if (yystack->yyerrState == 0)    if (yystack->yyerrState == 0)
1519      yystack->yyerrState = 3;      yystack->yyerrState = 3;
1520    else if (yystack->yyerrState == 3)    else if (yystack->yyerrState == 3)
1521      {      {
1522        /* We just shifted the error token and (perhaps) took some        /* We just shifted the error token and (perhaps) took some
1523           reductions. Skip tokens until we can proceed. */           reductions. Skip tokens until we can proceed. */
# Line 1584  yyrecoverParseError (yyGLRStack* yystack Line 1525  yyrecoverParseError (yyGLRStack* yystack
1525          if (*yytokenp == YYEOF)          if (*yytokenp == YYEOF)
1526            yyFail (yystack, NULL);            yyFail (yystack, NULL);
1527          if (*yytokenp != YYEMPTY)          if (*yytokenp != YYEMPTY)
1528            YYDPRINTF ((stderr, "Discarding token %s\n",            YYDPRINTF ((stderr, "Discarding token %s\n",
1529                        yytokenName (*yytokenp)));                        yytokenName (*yytokenp)));
1530          yychar = YYLEX;          yychar = YYLEX;
1531          *yytokenp = YYTRANSLATE (yychar);          *yytokenp = YYTRANSLATE (yychar);
# Line 1603  yyrecoverParseError (yyGLRStack* yystack Line 1544  yyrecoverParseError (yyGLRStack* yystack
1544            return;            return;
1545        } while (yytrue);        } while (yytrue);
1546      }      }
1547          
1548    /* Reduce to one stack */    /* Reduce to one stack */
1549    for (yyk = 0; yyk < yystack->yytops.yysize; yyk += 1)    for (yyk = 0; yyk < yystack->yytops.yysize; yyk += 1)
1550      if (yystack->yytops.yystates[yyk] != NULL)      if (yystack->yytops.yystates[yyk] != NULL)
# Line 1616  yyrecoverParseError (yyGLRStack* yystack Line 1557  yyrecoverParseError (yyGLRStack* yystack
1557    yycompressStack (yystack);    yycompressStack (yystack);
1558    
1559    /* 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. */
1560    while (yystack->yytops.yystates[0] != NULL)    while (yystack->yytops.yystates[0] != NULL)
1561      {      {
1562        yyj = yypact[yystack->yytops.yystates[0]->yylrState] + YYTERROR;        yyj = yypact[yystack->yytops.yystates[0]->yylrState] + YYTERROR;
1563        if (yyj != YYFLAG + YYTERROR && yyj >= 0 && yyj <= YYLAST &&        if (yyj != YYFLAG + YYTERROR && yyj >= 0 && yyj <= YYLAST &&
1564            yycheck[yyj] == YYTERROR && yyisShiftAction (yytable[yyj]))            yycheck[yyj] == YYTERROR && yyisShiftAction (yytable[yyj]))
1565          {          {
1566            yyglrShift (yystack, 0, yytable[yyj],            yyglrShift (yystack, 0, yytable[yyj],
1567                        yystack->yytops.yystates[0]->yyposn, *yylvalp, yyllocp);                        yystack->yytops.yystates[0]->yyposn, *yylvalp, yyllocp);
1568            break;            break;
1569          }          }
# Line 1632  yyrecoverParseError (yyGLRStack* yystack Line 1573  yyrecoverParseError (yyGLRStack* yystack
1573      }      }
1574    if (yystack->yytops.yystates[0] == NULL)    if (yystack->yytops.yystates[0] == NULL)
1575      yyFail (yystack, NULL);      yyFail (yystack, NULL);
1576  }      }
1577      
1578  #define YYCHK1(YYE)                                                          \  #define YYCHK1(YYE)                                                          \
1579    do {                                                                       \    do {                                                                       \
1580      switch (YYE) {                                                           \      switch (YYE) {                                                           \
# Line 1648  yyrecoverParseError (yyGLRStack* yystack Line 1589  yyrecoverParseError (yyGLRStack* yystack
1589      case yyerr:                                                              \      case yyerr:                                                              \
1590        goto yyuser_error;                                                     \        goto yyuser_error;                                                     \
1591      }                                                                        \      }                                                                        \
1592    } while (0)    } while (0)
1593    
1594  int  int
1595  yyparse (YYPARSE_PARAM_ARG)  yyparse (YYPARSE_PARAM_ARG)
1596  {  {
1597    yySymbol yytoken;    yySymbol yytoken;
1598    yyGLRStack yystack;    yyGLRStack yystack;
# Line 1666  yyparse (YYPARSE_PARAM_ARG) Line 1607  yyparse (YYPARSE_PARAM_ARG)
1607    
1608    YYSTYPE* const yylvalp = &yylval;    YYSTYPE* const yylvalp = &yylval;
1609    YYLTYPE* const yyllocp = &yylloc;    YYLTYPE* const yyllocp = &yylloc;
1610      
1611    yyinitGLRStack (&yystack, YYINITDEPTH);    yyinitGLRStack (&yystack, YYINITDEPTH);
1612    yystack.yytokenp = &yytoken;    yystack.yytokenp = &yytoken;
1613    
# Line 1677  yyparse (YYPARSE_PARAM_ARG) Line 1618  yyparse (YYPARSE_PARAM_ARG)
1618    yytoken = YYEMPTY;    yytoken = YYEMPTY;
1619    yyposn = 0;    yyposn = 0;
1620    
1621    while (yytrue)    while (yytrue)
1622      {      {
1623        /* For efficiency, we have two loops, of which the first of which        /* For efficiency, we have two loops, of which the first of which
1624         * is specialized to deterministic operation (single stack, no         * is specialized to deterministic operation (single stack, no
1625         * potential ambiguity). */         * potential ambiguity). */
1626          
1627        /* Standard mode */        /* Standard mode */
1628        while (yytrue)        while (yytrue)
1629          {          {
1630            yyRuleNum yyrule;            yyRuleNum yyrule;
1631            int yyaction;            int yyaction;
# Line 1693  yyparse (YYPARSE_PARAM_ARG) Line 1634  yyparse (YYPARSE_PARAM_ARG)
1634            yyStateNum yystate = yystack.yytops.yystates[0]->yylrState;            yyStateNum yystate = yystack.yytops.yystates[0]->yylrState;
1635            if (yystate == YYFINAL)            if (yystate == YYFINAL)
1636              goto yyDone;              goto yyDone;
1637            if (yyisDefaultedState (yystate))            if (yyisDefaultedState (yystate))
1638              {              {
1639                yyrule = yydefaultAction (yystate);                yyrule = yydefaultAction (yystate);
1640                if (yyrule == 0)                if (yyrule == 0)
1641                  {                  {
1642                    yyreportParseError (&yystack, yylvalp, yyllocp);                    yyreportParseError (&yystack, yylvalp, yyllocp);
1643                    goto yyuser_error;                    goto yyuser_error;
1644                  }                  }
1645                YYCHK1 (yyglrReduce (&yystack, 0, yyrule, yytrue));                YYCHK1 (yyglrReduce (&yystack, 0, yyrule, yytrue));
1646              }              }
1647            else            else
1648              {              {
1649                if (yytoken == YYEMPTY)                if (yytoken == YYEMPTY)
1650                  {                  {
1651                    yychar = YYLEX;                    yychar = YYLEX;
1652                    yytoken = YYTRANSLATE (yychar);                    yytoken = YYTRANSLATE (yychar);
1653                    YYDPRINTF ((stderr, "Read token %s\n",                    YYDPRINTF ((stderr, "Read token %s\n",
1654                                yytokenName (yytoken)));                                yytokenName (yytoken)));
1655                  }                  }
1656                yygetLRActions (yystate, yytoken, &yyaction, &yyconflicts);                yygetLRActions (yystate, yytoken, &yyaction, &yyconflicts);
1657                if (*yyconflicts != 0)                if (*yyconflicts != 0)
1658                  break;                  break;
1659                if (yyisShiftAction (yyaction))                if (yyisShiftAction (yyaction))
1660                  {                  {
1661                    YYDPRINTF ((stderr, "Shifted token %s. ",                    YYDPRINTF ((stderr, "Shifted token %s. ",
1662                                yytokenName (yytoken)));                                yytokenName (yytoken)));
1663                    if (yytoken != YYEOF)                    if (yytoken != YYEOF)
1664                      yytoken = YYEMPTY;                      yytoken = YYEMPTY;
# Line 1725  yyparse (YYPARSE_PARAM_ARG) Line 1666  yyparse (YYPARSE_PARAM_ARG)
1666                    yyglrShift (&yystack, 0, yyaction, yyposn, yylval, yyllocp);                    yyglrShift (&yystack, 0, yyaction, yyposn, yylval, yyllocp);
1667                    if (yystack.yyerrState > 0)                    if (yystack.yyerrState > 0)
1668                      yystack.yyerrState -= 1;                      yystack.yyerrState -= 1;
1669                    YYDPRINTF ((stderr, "Now in state #%d\n",                    YYDPRINTF ((stderr, "Now in state #%d\n",
1670                                yystack.yytops.yystates[0]->yylrState));                                yystack.yytops.yystates[0]->yylrState));
1671                  }                  }
1672                else if (yyisErrorAction (yyaction))                else if (yyisErrorAction (yyaction))
# Line 1738  yyparse (YYPARSE_PARAM_ARG) Line 1679  yyparse (YYPARSE_PARAM_ARG)
1679              }              }
1680          }          }
1681    
1682        while (yytrue)        while (yytrue)
1683          {          {
1684            int yys;            int yys;
1685            int yyn = yystack.yytops.yysize;            int yyn = yystack.yytops.yysize;
# Line 1758  yyparse (YYPARSE_PARAM_ARG) Line 1699  yyparse (YYPARSE_PARAM_ARG)
1699                yyreportParseError (&yystack, yylvalp, yyllocp);                yyreportParseError (&yystack, yylvalp, yyllocp);
1700                goto yyuser_error;                goto yyuser_error;
1701              }              }
1702            else if (yystack.yytops.yysize == 1)            else if (yystack.yytops.yysize == 1)
1703              {              {
1704                YYCHK1 (yyresolveStack (&yystack));                YYCHK1 (yyresolveStack (&yystack));
1705                YYDPRINTF ((stderr, "Returning to deterministic operation.\n"));                YYDPRINTF ((stderr, "Returning to deterministic operation.\n"));
# Line 1781  yyparse (YYPARSE_PARAM_ARG) Line 1722  yyparse (YYPARSE_PARAM_ARG)
1722  /* DEBUGGING ONLY */  /* DEBUGGING ONLY */
1723    
1724  void  void
1725  yypstates (yyGLRState* yyst)  yypstates (yyGLRState* yyst)
1726  {  {
1727    void yy_yypstack (yyGLRState* yys)    void yy_yypstack (yyGLRState* yys)
1728      {      {
1729        if (yys->yypred == NULL)        if (yys->yypred == NULL)
1730          fprintf (stderr, "%d@%d", yys->yylrState, yys->yyposn);          fprintf (stderr, "%d@%d", yys->yylrState, yys->yyposn);
1731        else        else
1732          {          {
1733            yy_yypstack (yys->yypred);            yy_yypstack (yys->yypred);
1734            fprintf (stderr, " -> %d@%d", yys->yylrState, yys->yyposn);            fprintf (stderr, " -> %d@%d", yys->yylrState, yys->yyposn);
1735          }          }
1736      }      }
1737    
1738    if (yyst == NULL)    if (yyst == NULL)
1739      fprintf (stderr, "<null>");      fprintf (stderr, "<null>");
1740    else    else
1741      yy_yypstack (yyst);      yy_yypstack (yyst);
1742    fprintf (stderr, "\n");    fprintf (stderr, "\n");
1743  }  }
1744    
1745  void  void
1746  yypstack (yyGLRStack* yystack, int yyk)  yypstack (yyGLRStack* yystack, int yyk)
1747  {  {
1748    yypstates (yystack->yytops.yystates[yyk]);    yypstates (yystack->yytops.yystates[yyk]);
1749  }  }
# Line 1812  yypstack (yyGLRStack* yystack, int yyk) Line 1753  yypstack (yyGLRStack* yystack, int yyk)
1753    
1754    
1755  void  void
1756  yypdumpstack (yyGLRStack* yystack)  yypdumpstack (yyGLRStack* yystack)
1757  {  {
1758    yyGLRStackItem* yyp;    yyGLRStackItem* yyp;
1759    int yyi;    int yyi;
1760    for (yyp = yystack->yyitems; yyp < yystack->yynextFree; yyp += 1)    for (yyp = yystack->yyitems; yyp < yystack->yynextFree; yyp += 1)
1761      {      {
1762        fprintf (stderr, "%3d. ", yyp - yystack->yyitems);        fprintf (stderr, "%3d. ", yyp - yystack->yyitems);
1763        if (*(bool*) yyp)        if (*(bool*) yyp)
1764          {          {
1765            fprintf (stderr, "Res: %d, LR State: %d, posn: %d, pred: %d",            fprintf (stderr, "Res: %d, LR State: %d, posn: %d, pred: %d",
1766                     yyp->yystate.yyresolved, yyp->yystate.yylrState,                     yyp->yystate.yyresolved, yyp->yystate.yylrState,
1767                     yyp->yystate.yyposn,                     yyp->yystate.yyposn,
1768                     YYINDEX(yyp->yystate.yypred));                     YYINDEX(yyp->yystate.yypred));
1769            if (! yyp->yystate.yyresolved)            if (! yyp->yystate.yyresolved)
1770              fprintf (stderr, ", firstVal: %d",              fprintf (stderr, ", firstVal: %d",
1771                       YYINDEX (yyp->yystate.yysemantics.yyfirstVal));                       YYINDEX (yyp->yystate.yysemantics.yyfirstVal));
1772          }          }
1773        else          else
1774          {          {
1775            fprintf (stderr, "Option. rule: %d, state: %d, next: %d",            fprintf (stderr, "Option. rule: %d, state: %d, next: %d",
1776                     yyp->yyoption.yyrule, YYINDEX (yyp->yyoption.yystate),                     yyp->yyoption.yyrule, YYINDEX (yyp->yyoption.yystate),
1777                     YYINDEX (yyp->yyoption.yynext));                     YYINDEX (yyp->yyoption.yynext));
1778          }          }
1779        fprintf (stderr, "\n");        fprintf (stderr, "\n");
# Line 1848  yypdumpstack (yyGLRStack* yystack) Line 1789  yypdumpstack (yyGLRStack* yystack)
1789  b4_epilogue  b4_epilogue
1790  m4_if(b4_defines_flag, 0, [],  m4_if(b4_defines_flag, 0, [],
1791  [#output "b4_output_header_name"  [#output "b4_output_header_name"
1792    b4_copyright([Skeleton parser for GLR parsing with Bison], [2002])
1793  #ifndef b4_header_guard  #ifndef b4_header_guard
1794  # define b4_header_guard  # define b4_header_guard
1795    

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26