parse.c

来自「C++版 词法分析、语法分析器」· C语言 代码 · 共 1,995 行 · 第 1/4 页

C
1,995
字号
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
     2,     2,     2,     2,     2,     1,     2,     3,     4,     5,
     6,     7,     8,     9,    10,    11
};

#if YY_parse_DEBUG != 0
static const short yyprhs[] = {     0,
     0,     6,     7,    13,    14,    17,    19,    21,    23,    27,
    29,    31,    36,    37,    38,    42,    45,    48,    50,    53,
    55,    57,    61,    65,    67,    69,    72,    76,    79,    81,
    85,    87,    90,    93,    95,    98,   101,   104,   111,   117,
   122,   124,   126,   128,   132,   136,   138,   142,   147,   152,
   155,   156,   159
};

static const short yyrhs[] = {    33,
    34,    35,    38,    39,     0,     0,    34,    36,     8,    37,
    12,     0,     0,     1,    12,     0,     5,     0,     6,     0,
     7,     0,    37,     8,     9,     0,     9,     0,     1,     0,
    38,    39,    40,    12,     0,     0,     0,    41,    13,    43,
     0,    41,    43,     0,    13,    43,     0,    43,     0,    41,
    11,     0,    11,     0,     1,     0,    14,    42,    15,     0,
    42,    16,     9,     0,     9,     0,     1,     0,    45,    44,
     0,    45,    44,    17,     0,    44,    17,     0,    44,     0,
    44,    18,    46,     0,    46,     0,    44,    19,     0,    46,
    47,     0,    47,     0,    47,    20,     0,    47,    21,     0,
    47,    22,     0,    47,    23,     4,    16,     4,    24,     0,
    47,    23,     4,    16,    24,     0,    47,    23,     4,    24,
     0,    25,     0,    48,     0,    10,     0,    26,    50,    26,
     0,    27,    44,    28,     0,     3,     0,    29,    49,    30,
     0,    29,    13,    49,    30,     0,    49,     3,    31,     3,
     0,    49,     3,     0,     0,    50,     3,     0,     0
};

#endif

#if YY_parse_DEBUG != 0
static const short yyrline[] = { 0,
    52,    76,    85,    86,    87,    91,    94,   104,   108,   111,
   114,   118,   119,   122,   133,   153,   164,   188,   199,   202,
   221,   225,   228,   238,   247,   251,   308,   311,   363,   379,
   385,   390,   415,   423,   427,   434,   441,   448,   474,   488,
   506,   528,   545,   552,   555,   558,   569,   572,   586,   614,
   626,   634,   645
};

static const char * const yytname[] = {   "$","error","$illegal.","CHAR","NUMBER",
"SECTEND","SCDECL","XSCDECL","WHITESPACE","NAME","PREVCCL","EOF_OP","'\\n'",
"'^'","'<'","'>'","','","'$'","'|'","'/'","'*'","'+'","'?'","'{'","'}'","'.'",
"'\"'","'('","')'","'['","']'","'-'","goal","initlex","sect1","sect1end","startconddecl",
"namelist1","sect2","initforrule","flexrule","scon","namelist2","rule","re",
"re2","series","singleton","fullccl","ccl","string",""
};
#endif

static const short yyr1[] = {     0,
    32,    33,    34,    34,    34,    35,    36,    36,    37,    37,
    37,    38,    38,    39,    40,    40,    40,    40,    40,    40,
    40,    41,    42,    42,    42,    43,    43,    43,    43,    44,
    44,    45,    46,    46,    47,    47,    47,    47,    47,    47,
    47,    47,    47,    47,    47,    47,    48,    48,    49,    49,
    49,    50,    50
};

static const short yyr2[] = {     0,
     5,     0,     5,     0,     2,     1,     1,     1,     3,     1,
     1,     4,     0,     0,     3,     2,     2,     1,     2,     1,
     1,     3,     3,     1,     1,     2,     3,     2,     1,     3,
     1,     2,     2,     1,     2,     2,     2,     6,     5,     4,
     1,     1,     1,     3,     3,     1,     3,     4,     4,     2,
     0,     2,     0
};

static const short yydefact[] = {     2,
     0,     0,     0,     5,     6,     7,     8,    13,     0,    14,
     0,     0,    11,    10,     0,    21,    46,    43,    20,     0,
     0,    41,    53,     0,    51,     0,     0,    18,    29,     0,
    31,    34,    42,     0,     3,    17,    25,    24,     0,     0,
     0,    51,     0,    12,    19,     0,    16,    28,     0,    32,
    26,    33,    35,    36,    37,     0,     9,    22,     0,    52,
    44,    45,     0,    50,    47,    15,    30,    27,     0,    23,
    48,     0,     0,    40,    49,     0,    39,    38,     0,     0,
     0
};

static const short yydefgoto[] = {    79,
     1,     3,     8,     9,    15,    10,    12,    26,    27,    39,
    28,    29,    30,    31,    32,    33,    43,    40
};

static const short yypact[] = {-32768,
    55,    -2,    63,-32768,-32768,-32768,-32768,-32768,    16,-32768,
    12,     1,-32768,-32768,    51,-32768,-32768,-32768,-32768,    19,
    33,-32768,-32768,    19,    -6,     8,    28,-32768,    54,    19,
    19,    44,-32768,    38,-32768,-32768,-32768,-32768,    34,    14,
   -10,-32768,     2,-32768,-32768,    19,-32768,-32768,    19,-32768,
    57,    44,-32768,-32768,-32768,    48,-32768,-32768,    49,-32768,
-32768,-32768,     3,     6,-32768,-32768,    19,-32768,    27,-32768,
-32768,    73,    -1,-32768,-32768,    53,-32768,-32768,    78,    79,
-32768
};

static const short yypgoto[] = {-32768,
-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
   -11,    -5,-32768,    31,   -31,-32768,    39,-32768
};


#define	YYLAST		81


static const short yytable[] = {    52,
    -1,    16,    76,    17,    64,    64,    42,    49,    36,     4,
    18,    19,    13,    20,    21,    47,    60,    62,    41,    44,
    14,    17,    77,    11,    51,    22,    23,    24,    18,    25,
    17,    65,    71,    37,    66,    52,    72,    18,    45,    61,
    46,    38,    73,    22,    23,    24,    57,    25,    58,    59,
    74,    69,    22,    23,    24,     2,    25,    70,    34,    -4,
    -4,    -4,    35,    53,    54,    55,    56,     5,     6,     7,
    48,    49,    50,    68,    49,    75,    78,    80,    81,    67,
    63
};

static const short yycheck[] = {    31,
     0,     1,     4,     3,     3,     3,    13,    18,    20,    12,
    10,    11,     1,    13,    14,    27,     3,    28,    24,    12,
     9,     3,    24,     8,    30,    25,    26,    27,    10,    29,
     3,    30,    30,     1,    46,    67,    31,    10,    11,    26,
    13,     9,    16,    25,    26,    27,     9,    29,    15,    16,
    24,     4,    25,    26,    27,     1,    29,     9,     8,     5,
     6,     7,    12,    20,    21,    22,    23,     5,     6,     7,
    17,    18,    19,    17,    18,     3,    24,     0,     0,    49,
    42
};

#line 329 "/u/icdc/rdt/tools/lib/bison.cc"
 /* fattrs + tables */

/* parser code folow  */


/* This is the parser code that is written into each bison parser
  when the %semantic_parser declaration is not specified in the grammar.
  It was written by Richard Stallman by simplifying the hairy parser
  used when %semantic_parser is specified.  */

/* Note: dollar marks section change
   the next  is replaced by the list of actions, each action
   as one case of the switch.  */ 

#if YY_parse_USE_GOTO != 0
/* 
 SUPRESSION OF GOTO : on some C++ compiler (sun c++)
  the goto is strictly forbidden if any constructor/destructor
  is used in the whole function (very stupid isn't it ?)
 so goto are to be replaced with a 'while/switch/case construct'
 here are the macro to keep some apparent compatibility
*/
#define YYGOTO(lb) {yy_gotostate=lb;continue;}
#define YYBEGINGOTO  enum yy_labels yy_gotostate=yygotostart; \
                     for(;;) switch(yy_gotostate) { case yygotostart: {
#define YYLABEL(lb) } case lb: {
#define YYENDGOTO } } 
#define YYBEGINDECLARELABEL enum yy_labels {yygotostart
#define YYDECLARELABEL(lb) ,lb
#define YYENDDECLARELABEL  };
#else
/* macro to keep goto */
#define YYGOTO(lb) goto lb
#define YYBEGINGOTO 
#define YYLABEL(lb) lb:
#define YYENDGOTO
#define YYBEGINDECLARELABEL 
#define YYDECLARELABEL(lb)
#define YYENDDECLARELABEL 
#endif
/* LABEL DECLARATION */
YYBEGINDECLARELABEL
  YYDECLARELABEL(yynewstate)
  YYDECLARELABEL(yybackup)
/* YYDECLARELABEL(yyresume) */
  YYDECLARELABEL(yydefault)
  YYDECLARELABEL(yyreduce)
  YYDECLARELABEL(yyerrlab)   /* here on detecting error */
  YYDECLARELABEL(yyerrlab1)   /* here on error raised explicitly by an action */
  YYDECLARELABEL(yyerrdefault)  /* current state does not do anything special for the error token. */
  YYDECLARELABEL(yyerrpop)   /* pop the current state because it cannot handle the error token */
  YYDECLARELABEL(yyerrhandle)  
YYENDDECLARELABEL

#define yyerrok         (yyerrstatus = 0)
#define yyclearin       (YY_parse_CHAR = YYEMPTY)
#define YYEMPTY         -2
#define YYEOF           0
#define YYACCEPT        return(0)
#define YYABORT         return(1)
#define YYERROR         YYGOTO(yyerrlab1)
/* Like YYERROR except do call yyerror.
   This remains here temporarily to ease the
   transition to the new meaning of YYERROR, for GCC.
   Once GCC version 2 has supplanted version 1, this can go.  */
#define YYFAIL          YYGOTO(yyerrlab)
#define YYRECOVERING()  (!!yyerrstatus)
#define YYBACKUP(token, value) \
do                                                              \
  if (YY_parse_CHAR == YYEMPTY && yylen == 1)                               \
    { YY_parse_CHAR = (token), YY_parse_LVAL = (value);                 \
      yychar1 = YYTRANSLATE (YY_parse_CHAR);                                \
      YYPOPSTACK;                                               \
      YYGOTO(yybackup);                                            \
    }                                                           \
  else                                                          \
    { YY_parse_ERROR ("syntax error: cannot back up"); YYERROR; }   \
while (0)

#define YYTERROR        1
#define YYERRCODE       256

#ifndef YY_parse_PURE
/* UNPURE */
#define YYLEX           YY_parse_LEX()
#ifndef YY_USE_CLASS
/* If nonreentrant, and not class , generate the variables here */
int     YY_parse_CHAR;                      /*  the lookahead symbol        */
YY_parse_STYPE      YY_parse_LVAL;              /*  the semantic value of the */
				/*  lookahead symbol    */
int YY_parse_NERRS;                 /*  number of parse errors so far */
#ifdef YY_parse_LSP_NEEDED
YY_parse_LTYPE YY_parse_LLOC;   /*  location data for the lookahead     */
			/*  symbol                              */
#endif
#endif


#else
/* PURE */
#ifdef YY_parse_LSP_NEEDED
#define YYLEX           YY_parse_LEX(&YY_parse_LVAL, &YY_parse_LLOC)
#else
#define YYLEX           YY_parse_LEX(&YY_parse_LVAL)
#endif
#endif
#ifndef YY_USE_CLASS
#if YY_parse_DEBUG != 0
int YY_parse_DEBUG_FLAG;                    /*  nonzero means print parse trace     */
/* Since this is uninitialized, it does not stop multiple parsers
   from coexisting.  */
#endif
#endif



/*  YYINITDEPTH indicates the initial size of the parser's stacks       */

#ifndef YYINITDEPTH
#define YYINITDEPTH 200
#endif

/*  YYMAXDEPTH is the maximum size the stacks can grow to
    (effective only if the built-in stack extension method is used).  */

#if YYMAXDEPTH == 0
#undef YYMAXDEPTH
#endif

#ifndef YYMAXDEPTH
#define YYMAXDEPTH 10000
#endif


#if __GNUC__ > 1                /* GNU C and GNU C++ define this.  */
#define __yy_bcopy(FROM,TO,COUNT)       __builtin_memcpy(TO,FROM,COUNT)
#else                           /* not GNU C or C++ */

/* This is the most reliable way to avoid incompatibilities
   in available built-in functions on various systems.  */

#ifdef __cplusplus
static void __yy_bcopy (char *from, char *to, int count)
#else
#ifdef __STDC__
static void __yy_bcopy (char *from, char *to, int count)
#else
static void __yy_bcopy (from, to, count)
     char *from;
     char *to;
     int count;
#endif
#endif
{
  register char *f = from;
  register char *t = to;
  register int i = count;

  while (i-- > 0)
    *t++ = *f++;
}
#endif

int
#ifdef YY_USE_CLASS
 YY_parse_CLASS::
#endif
     YY_parse_PARSE(YY_parse_PARSE_PARAM)
#ifndef __STDC__
#ifndef __cplusplus
#ifndef YY_USE_CLASS
/* parameter definition without protypes */
YY_parse_PARSE_PARAM_DEF
#endif
#endif
#endif
{
  register int yystate;
  register int yyn;
  register short *yyssp;
  register YY_parse_STYPE *yyvsp;
  int yyerrstatus;      /*  number of tokens to shift before error messages enabled */
  int yychar1=0;          /*  lookahead token as an internal (translated) token number */

  short yyssa[YYINITDEPTH];     /*  the state stack                     */
  YY_parse_STYPE yyvsa[YYINITDEPTH];        /*  the semantic value stack            */

  short *yyss = yyssa;          /*  refer to the stacks thru separate pointers */
  YY_parse_STYPE *yyvs = yyvsa;     /*  to allow yyoverflow to reallocate them elsewhere */

#ifdef YY_parse_LSP_NEEDED
  YY_parse_LTYPE yylsa[YYINITDEPTH];        /*  the location stack                  */
  YY_parse_LTYPE *yyls = yylsa;
  YY_parse_LTYPE *yylsp;

#define YYPOPSTACK   (yyvsp--, yyssp--, yylsp--)
#else
#define YYPOPSTACK   (yyvsp--, yyssp--)
#endif

  int yystacksize = YYINITDEPTH;

#ifdef YY_parse_PURE
  int YY_parse_CHAR;
  YY_parse_STYPE YY_parse_LVAL;
  int YY_parse_NERRS;
#ifdef YY_parse_LSP_NEEDED
  YY_parse_LTYPE YY_parse_LLOC;
#endif
#endif

  YY_parse_STYPE yyval;             /*  the variable used to return         */
				/*  semantic values from the action     */
				/*  routines                            */

  int yylen;
/* start loop, in which YYGOTO may be used. */
YYBEGINGOTO

#if YY_parse_DEBUG != 0
  if (YY_parse_DEBUG_FLAG)
    fprintf(stderr, "Starting parse\n");
#endif
  yystate = 0;
  yyerrstatus = 0;
  YY_parse_NERRS = 0;
  YY_parse_CHAR = YYEMPTY;          /* Cause a token to be read.  */

  /* Initialize stack pointers.
     Waste one element of value and location stack
     so that they stay on the same level as the state stack.
     The wasted elements are never initialized.  */

  yyssp = yyss - 1;
  yyvsp = yyvs;
#ifdef YY_parse_LSP_NEEDED
  yylsp = yyls;
#endif

/* Push a new state, which is found in  yystate  .  */
/* In all cases, when you get here, the value and location stacks
   have just been pushed. so pushing a state here evens the stacks.  */
YYLABEL(yynewstate)

  *++yyssp = yystate;

  if (yyssp >= yyss + yystacksize - 1)
    {
      /* Give user a chance to reallocate the stack */
      /* Use copies of these so that the &'s don't force the real ones into memory. */
      YY_parse_STYPE *yyvs1 = yyvs;
      short *yyss1 = yyss;
#ifdef YY_parse_LSP_NEEDED
      YY_parse_LTYPE *yyls1 = yyls;
#endif

      /* Get the current used size of the three stacks, in elements.  */
      int size = yyssp - yyss + 1;

#ifdef yyoverflow
      /* Each stack pointer address is followed by the size of
	 the data in use in that stack, in bytes.  */
#ifdef YY_parse_LSP_NEEDED
      /* This used to be a conditional around just the two extra args,
	 but that might be undefined if yyoverflow is a macro.  */
      yyoverflow("parser stack overflow",
		 &yyss1, size * sizeof (*yyssp),
		 &yyvs1, size * sizeof (*yyvsp),
		 &yyls1, size * sizeof (*yylsp),
		 &yystacksize);
#else
      yyoverflow("parser stack overflow",
		 &yyss1, size * sizeof (*yyssp),
		 &yyvs1, size * sizeof (*yyvsp),
		 &yystacksize);
#endif

      yyss = yyss1; yyvs = yyvs1;
#ifdef YY_parse_LSP_NEEDED
      yyls = yyls1;
#endif
#else /* no yyoverflow */
      /* Extend the stack our own way.  */
      if (yystacksize >= YYMAXDEPTH)
	{
	  YY_parse_ERROR("parser stack overflow");
	  return 2;
	}
      yystacksize *= 2;
      if (yystacksize > YYMAXDEPTH)
	yystacksize = YYMAXDEPTH;
      yyss = (short *) alloca (yystacksize * sizeof (*yyssp));
      __yy_bcopy ((char *)yyss1, (char *)yyss, size * sizeof (*yyssp));
      yyvs = (YY_parse_STYPE *) alloca (yystacksize * sizeof (*yyvsp));
      __yy_bcopy ((char *)yyvs1, (char *)yyvs, size * sizeof (*yyvsp));
#ifdef YY_parse_LSP_NEEDED
      yyls = (YY_parse_LTYPE *) alloca (yystacksize * sizeof (*yylsp));
      __yy_bcopy ((char *)yyls1, (char *)yyls, size * sizeof (*yylsp));
#endif
#endif /* no yyoverflow */

      yyssp = yyss + size - 1;
      yyvsp = yyvs + size - 1;
#ifdef YY_parse_LSP_NEEDED
      yylsp = yyls + size - 1;
#endif

#if YY_parse_DEBUG != 0
      if (YY_parse_DEBUG_FLAG)
	fprintf(stderr, "Stack size increased to %d\n", yystacksize);
#endif

      if (yyssp >= yyss + yystacksize - 1)
	YYABORT;
    }

#if YY_parse_DEBUG != 0
  if (YY_parse_DEBUG_FLAG)
    fprintf(stderr, "Entering state %d\n", yystate);
#endif

  YYGOTO(yybackup);
YYLABEL(yybackup)

/* Do appropriate processing given the current state.  */
/* Read a lookahead token if we need one and don't already have one.  */
/* YYLABEL(yyresume) */

  /* First try to decide what to do without reference to lookahead token.  */

  yyn = yypact[yystate];
  if (yyn == YYFLAG)
    YYGOTO(yydefault);

  /* Not known => get a lookahead token if don't already have one.  */

  /* yychar is either YYEMPTY or YYEOF
     or a valid token in external form.  */

  if (YY_parse_CHAR == YYEMPTY)
    {
#if YY_parse_DEBUG != 0
      if (YY_parse_DEBUG_FLAG)
	fprintf(stderr, "Reading a token: ");
#endif
      YY_parse_CHAR = YYLEX;
    }

  /* Convert token to internal form (in yychar1) for indexing tables with */

  if (YY_parse_CHAR <= 0)           /* This means end of input. */
    {
      yychar1 = 0;
      YY_parse_CHAR = YYEOF;                /* Don't call YYLEX any more */

#if YY_parse_DEBUG != 0
      if (YY_parse_DEBUG_FLAG)
	fprintf(stderr, "Now at end of input.\n");
#endif
    }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?