📄 glr.c
字号:
m4_divert(-1) -*- C -*-# GLR skeleton for Bison# Copyright (C) 2002, 2003, 2004 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 of the License, 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## ---------------- #### Default values. #### ---------------- ### Stack parameters.m4_define_default([b4_stack_depth_max], [10000])m4_define_default([b4_stack_depth_init], [200])## ------------------------ #### Pure/impure interfaces. #### ------------------------ ### b4_lex_param# ------------# Accumule in b4_lex_param all the yylex arguments.# Yes, this is quite ugly...m4_define([b4_lex_param],m4_dquote(b4_pure_if([[[[YYSTYPE *]], [[yylvalp]]][]dnlb4_location_if([, [[YYLTYPE *], [yyllocp]]])])dnlm4_ifdef([b4_lex_param], [, ]b4_lex_param)))# b4_user_formals# ---------------m4_define([b4_user_formals],[m4_ifset([b4_parse_param], [, b4_c_ansi_formals(b4_parse_param)])])# b4_yyerror_args# ---------------# Arguments passed to yyerror: user args plus yylloc.m4_define([b4_yyerror_args],[b4_pure_if([b4_location_if([yylocp, ])])dnlm4_ifset([b4_parse_param], [b4_c_args(b4_parse_param), ])])# b4_lyyerror_args# ----------------# Same as above, but on the look-ahead, hence yyllocp instead of yylocp.m4_define([b4_lyyerror_args],[b4_pure_if([b4_location_if([yyllocp, ])])dnlm4_ifset([b4_parse_param], [b4_c_args(b4_parse_param), ])])# b4_pure_args# ------------# Arguments needed by yyerror: user args plus yylloc.m4_define([b4_pure_args],[b4_pure_if([b4_location_if([, yylocp])])[]b4_user_args])# b4_pure_formals# ---------------# Arguments passed to yyerror: user formals plus yyllocp.m4_define([b4_pure_formals],[b4_pure_if([b4_location_if([, YYLTYPE *yylocp])])[]b4_user_formals])# b4_lpure_args# -------------# Same as above, but on the look-ahead, hence yyllocp instead of yylocp.m4_define([b4_lpure_args],[b4_pure_if([b4_location_if([, yyllocp])])[]b4_user_args])# b4_lpure_formals# ----------------# Same as above, but on the look-ahead, hence yyllocp instead of yylocp.m4_define([b4_lpure_formals],[b4_pure_if([b4_location_if([YYLTYPE *yyllocp])])[]b4_user_formals])## ----------------- #### Semantic Values. #### ----------------- ### b4_lhs_value([TYPE])# --------------------# Expansion of $<TYPE>$.m4_define([b4_lhs_value],[((*yyvalp)[]m4_ifval([$1], [.$1]))])# b4_rhs_value(RULE-LENGTH, NUM, [TYPE])# --------------------------------------# Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH# symbols on RHS.m4_define([b4_rhs_value],[(((yyGLRStackItem const *)yyvsp)@{YYFILL (m4_eval([$2 - $1]))@}.yystate.yysemantics.yysval[]m4_ifval([$3], [.$3]))])## ----------- #### Locations. #### ----------- ### b4_lhs_location()# -----------------# Expansion of @$.m4_define([b4_lhs_location],[(*yylocp)])# b4_rhs_location(RULE-LENGTH, NUM)# ---------------------------------# Expansion of @NUM, where the current rule has RULE-LENGTH symbols# on RHS.m4_define([b4_rhs_location],[(((yyGLRStackItem const *)yyvsp)@{YYFILL (m4_eval([$2 - $1]))@}.yystate.yyloc)])# We do want M4 expansion after # for CPP macros.m4_changecom()m4_divert(0)dnl@output @output_parser_name@b4_copyright([Skeleton parser for GLR parsing with Bison], [2002, 2003, 2004])[/* This is the parser code for GLR (Generalized LR) parser. */#include <stdio.h>#include <stdlib.h>#include <string.h>#include <stdarg.h>#include <setjmp.h>]b4_identificationm4_if(b4_prefix[], [yy], [],[/* Substitute the variable and function names. */#define yyparse b4_prefix[]parse#define yylex b4_prefix[]lex#define yyerror b4_prefix[]error#define yylval b4_prefix[]lval#define yychar b4_prefix[]char#define yydebug b4_prefix[]debug#define yynerrs b4_prefix[]nerrs#define yylloc b4_prefix[]lloc])b4_token_defines(b4_tokens)/* Copy the first part of user declarations. */b4_pre_prologue[/* Enabling traces. */#ifndef YYDEBUG# define YYDEBUG ]b4_debug[#endif/* Enabling verbose error messages. */#ifdef YYERROR_VERBOSE# undef YYERROR_VERBOSE# define YYERROR_VERBOSE 1#else# define YYERROR_VERBOSE ]b4_error_verbose[#endif#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)]m4_ifdef([b4_stype],[b4_syncline([b4_stype_line], [b4_filename])typedef union m4_bregexp(b4_stype, [^{], [YYSTYPE ])b4_stype YYSTYPE;/* Line __line__ of glr.c. */b4_syncline([@oline@], [@ofile@])],[typedef int YYSTYPE;])[# define YYSTYPE_IS_DECLARED 1# define YYSTYPE_IS_TRIVIAL 1#endif#if ! defined (YYLTYPE) && ! defined (YYLTYPE_IS_DECLARED)typedef struct YYLTYPE{]b4_location_if([ int first_line; int first_column; int last_line; int last_column;],[ char yydummy;])[} YYLTYPE;# define YYLTYPE_IS_DECLARED 1# define YYLTYPE_IS_TRIVIAL 1#endif/* Default (constant) value used for initialization for null right-hand sides. Unlike the standard yacc.c template, here we set the default value of $$ to a zeroed-out value. Since the default value is undefined, this behavior is technically correct. */static YYSTYPE yyval_default;/* Copy the second part of user declarations. */]b4_post_prologue[]/* Line __line__ of glr.c. */b4_syncline([@oline@], [@ofile@])[#ifndef YYFREE# define YYFREE free#endif#ifndef YYMALLOC# define YYMALLOC malloc#endif#ifndef YYREALLOC# define YYREALLOC realloc#endif#ifdef __cplusplus typedef bool yybool;#else typedef unsigned char yybool;#endif#define yytrue 1#define yyfalse 0/*-----------------.| GCC extensions. |`-----------------*/#ifndef __attribute__/* This feature is available in gcc versions 2.5 and later. */# if !defined (__GNUC__) || __GNUC__ < 2 || \(__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__# define __attribute__(Spec) /* empty */# endif#endif#ifndef YYASSERT# define YYASSERT(condition) ((void) ((condition) || (abort (), 0)))#endif#ifndef ATTRIBUTE_UNUSED# define ATTRIBUTE_UNUSED __attribute__ ((__unused__))#endif/* YYFINAL -- State number of the termination state. */#define YYFINAL ]b4_final_state_number[/* YYLAST -- Last index in YYTABLE. */#define YYLAST ]b4_last[/* YYNTOKENS -- Number of terminals. */#define YYNTOKENS ]b4_tokens_number[/* YYNNTS -- Number of nonterminals. */#define YYNNTS ]b4_nterms_number[/* YYNRULES -- Number of rules. */#define YYNRULES ]b4_rules_number[/* YYNRULES -- Number of states. */#define YYNSTATES ]b4_states_number[/* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */#define YYMAXRHS ]b4_r2_max[/* YYMAXLEFT -- Maximum number of symbols to the left of a handle accessed by $0, $-1, etc., in any rule. */#define YYMAXLEFT ]b4_max_left_semantic_context[/* YYTRANSLATE(X) -- Bison symbol number corresponding to X. */#define YYUNDEFTOK ]b4_undef_token_number[#define YYMAXUTOK ]b4_user_token_number_max[#define YYTRANSLATE(YYX) \ ((YYX <= 0) ? YYEOF : \ (unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */static const ]b4_int_type_for([b4_translate])[ yytranslate[] ={ ]b4_translate[};#if YYDEBUG/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in YYRHS. */static const ]b4_int_type_for([b4_prhs])[ yyprhs[] ={ ]b4_prhs[};/* YYRHS -- A `-1'-separated list of the rules' RHS. */static const ]b4_int_type_for([b4_rhs])[ yyrhs[] ={ ]b4_rhs[};/* YYRLINE[YYN] -- source line where rule number YYN was defined. */static const ]b4_int_type_for([b4_rline])[ yyrline[] ={ ]b4_rline[};#endif#if (YYDEBUG) || YYERROR_VERBOSE/* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. First, the terminals, then, starting at YYNTOKENS, nonterminals. */static const char *const yytname[] ={ ]b4_tname[};#endif/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */static const ]b4_int_type_for([b4_r1])[ yyr1[] ={ ]b4_r1[};/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */static const ]b4_int_type_for([b4_r2])[ yyr2[] ={ ]b4_r2[};/* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */static const ]b4_int_type_for([b4_dprec])[ yydprec[] ={ ]b4_dprec[};/* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */static const ]b4_int_type_for([b4_merger])[ yymerger[] ={ ]b4_merger[};/* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE doesn't specify something else to do. Zero means the default is an error. */static const ]b4_int_type_for([b4_defact])[ yydefact[] ={ ]b4_defact[};/* YYPDEFGOTO[NTERM-NUM]. */static const ]b4_int_type_for([b4_defgoto])[ yydefgoto[] ={ ]b4_defgoto[};/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing STATE-NUM. */#define YYPACT_NINF ]b4_pact_ninf[static const ]b4_int_type_for([b4_pact])[ yypact[] ={ ]b4_pact[};/* YYPGOTO[NTERM-NUM]. */static const ]b4_int_type_for([b4_pgoto])[ yypgoto[] ={ ]b4_pgoto[};/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If positive, shift that token. If negative, reduce the rule which number is the opposite. If zero, do what YYDEFACT says. If YYTABLE_NINF, syntax error. */#define YYTABLE_NINF ]b4_table_ninf[static const ]b4_int_type_for([b4_table])[ yytable[] ={ ]b4_table[};/* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of list of conflicting reductions corresponding to action entry for state STATE-NUM in yytable. 0 means no conflicts. The list in yyconfl is terminated by a rule number of 0. */static const ]b4_int_type_for([b4_conflict_list_heads])[ yyconflp[] ={ ]b4_conflict_list_heads[};/* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by 0, pointed into by YYCONFLP. */]dnl Do not use b4_int_type_for here, since there are places wherednl pointers onto yyconfl are taken, which type is "short int *".dnl We probably ought to introduce a type for confl.[static const short int yyconfl[] ={ ]b4_conflicting_rules[};static const ]b4_int_type_for([b4_check])[ yycheck[] ={ ]b4_check[};/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing symbol of state STATE-NUM. */static const ]b4_int_type_for([b4_stos])[ yystos[] ={ ]b4_stos[};/* Prevent warning if -Wmissing-prototypes. */]b4_c_ansi_function_decl([yyparse], [int], b4_parse_param)[/* Error token number */#define YYTERROR 1/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. If N is 0, then set CURRENT to the empty location which ends the previous symbol: RHS[0] (always defined). */]b4_location_if([[#define YYRHSLOC(Rhs, K) ((Rhs)[K].yystate.yyloc)#ifndef YYLLOC_DEFAULT# define YYLLOC_DEFAULT(Current, Rhs, N) \ do \ if (N) \ { \ (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ } \ else \ { \ (Current).first_line = (Current).last_line = \ YYRHSLOC (Rhs, 0).last_line; \ (Current).first_column = (Current).last_column = \ YYRHSLOC (Rhs, 0).last_column; \ } \ while (0)/* YY_LOCATION_PRINT -- Print the location on the stream. This macro was not mandated originally: define only if we know we won't break user code: when these are the locations we know. */# define YY_LOCATION_PRINT(File, Loc) \ fprintf (File, "%d.%d-%d.%d", \ (Loc).first_line, (Loc).first_column, \ (Loc).last_line, (Loc).last_column)#endif]],[#ifndef YYLLOC_DEFAULT# define YYLLOC_DEFAULT(Current, Rhs, N) ((void) 0)#endif])[#ifndef YY_LOCATION_PRINT# define YY_LOCATION_PRINT(File, Loc) ((void) 0)#endif/* YYLEX -- calling `yylex' with the right arguments. */#define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[]b4_pure_if([#undef yynerrs#define yynerrs (yystack->yyerrcnt)#undef yychar#define yychar (yystack->yyrawchar)],[YYSTYPE yylval;YYLTYPE yylloc;int yynerrs;int yychar;])[static const int YYEOF = 0;static const int YYEMPTY = -2;typedef enum { yyok, yyaccept, yyabort, yyerr } YYRESULTTAG;#define YYCHK(YYE) \ do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \ while (0)#if YYDEBUG#if ! defined (YYFPRINTF)# define YYFPRINTF fprintf#endif# define YYDPRINTF(Args) \do { \ if (yydebug) \ YYFPRINTF Args; \} while (0)]b4_yysymprint_generate([b4_c_ansi_function_def])[# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \do { \ if (yydebug) \ { \ YYFPRINTF (stderr, "%s ", Title); \ yysymprint (stderr, \ Type, Value]b4_location_if([, Location])[); \ YYFPRINTF (stderr, "\n"); \ } \} while (0)/* Nonzero means print parse trace. It is left uninitialized so that multiple parsers can coexist. */int yydebug;#else /* !YYDEBUG */# define YYDPRINTF(Args)# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -