📄 gcc2.9.txt
字号:
/* YACC parser for C++ syntax. Copyright (C) 1988, 89, 93-98, 1999 Free Software Foundation, Inc. Hacked by Michael Tiemann (tiemann@cygnus.com)This file is part of GNU CC.GNU CC is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU CC is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU CC; see the file COPYING. If not, write tothe Free Software Foundation, 59 Temple Place - Suite 330,Boston, MA 02111-1307, USA. *//* This grammar is based on the GNU CC grammar. *//* Note: Bison automatically applies a default action of "$$ = $1" for all derivations; this is applied before the explicit action, if one is given. Keep this in mind when reading the actions. */%{/* Cause the `yydebug' variable to be defined. */#define YYDEBUG 1#include "config.h"#include "system.h"#include "tree.h"#include "input.h"#include "flags.h"#include "lex.h"#include "cp-tree.h"#include "output.h"#include "except.h"#include "toplev.h"/* Since parsers are distinct for each language, put the language string definition here. (fnf) */char *language_string = "GNU C++";extern tree void_list_node;extern struct obstack permanent_obstack;extern int end_of_file;/* Like YYERROR but do call yyerror. */#define YYERROR1 { yyerror ("syntax error"); YYERROR; }#define OP0(NODE) (TREE_OPERAND (NODE, 0))#define OP1(NODE) (TREE_OPERAND (NODE, 1))/* Contains the statement keyword (if/while/do) to include in an error message if the user supplies an empty conditional expression. */static const char *cond_stmt_keyword;static tree empty_parms PROTO((void));static int parse_decl PROTO((tree, tree, tree, int, tree *));/* Nonzero if we have an `extern "C"' acting as an extern specifier. */int have_extern_spec;int used_extern_spec;/* Cons up an empty parameter list. */#ifdef __GNUC____inline#endifstatic treeempty_parms (){ tree parms; if (strict_prototype || current_class_type != NULL) parms = void_list_node; else parms = NULL_TREE; return parms;}%}%start program%union {long itype; tree ttype; char *strtype; enum tree_code code; flagged_type_tree ftype; }/* All identifiers that are not reserved words and are not declared typedefs in the current block */%token IDENTIFIER/* All identifiers that are declared typedefs in the current block. In some contexts, they are treated just like IDENTIFIER, but they can also serve as typespecs in declarations. */%token TYPENAME%token SELFNAME/* A template function. */%token PFUNCNAME/* Reserved words that specify storage class. yylval contains an IDENTIFIER_NODE which indicates which one. */%token SCSPEC/* Reserved words that specify type. yylval contains an IDENTIFIER_NODE which indicates which one. */%token TYPESPEC/* Reserved words that qualify type: "const" or "volatile". yylval contains an IDENTIFIER_NODE which indicates which one. */%token CV_QUALIFIER/* Character or numeric constants. yylval is the node for the constant. */%token CONSTANT/* String constants in raw form. yylval is a STRING_CST node. */%token STRING/* "...", used for functions with variable arglists. */%token ELLIPSIS/* the reserved words *//* SCO include files test "ASM", so use something else. */%token SIZEOF ENUM /* STRUCT UNION */ IF ELSE WHILE DO FOR SWITCH CASE DEFAULT%token BREAK CONTINUE RETURN_KEYWORD GOTO ASM_KEYWORD TYPEOF ALIGNOF%token SIGOF%token ATTRIBUTE EXTENSION LABEL%token REALPART IMAGPART/* the reserved words... C++ extensions */%token <ttype> AGGR%token <ttype> VISSPEC%token DELETE NEW THIS OPERATOR CXX_TRUE CXX_FALSE%token NAMESPACE TYPENAME_KEYWORD USING%token LEFT_RIGHT TEMPLATE%token TYPEID DYNAMIC_CAST STATIC_CAST REINTERPRET_CAST CONST_CAST%token <itype> SCOPE/* Define the operator tokens and their precedences. The value is an integer because, if used, it is the tree code to use in the expression made from the operator. */%left EMPTY /* used to resolve s/r with epsilon */%left error/* Add precedence rules to solve dangling else s/r conflict */%nonassoc IF%nonassoc ELSE%left IDENTIFIER PFUNCNAME TYPENAME SELFNAME PTYPENAME SCSPEC TYPESPEC CV_QUALIFIER ENUM AGGR ELLIPSIS TYPEOF SIGOF OPERATOR NSNAME TYPENAME_KEYWORD%left '{' ',' ';'%nonassoc THROW%right <code> ':'%right <code> ASSIGN '='%right <code> '?'%left <code> OROR%left <code> ANDAND%left <code> '|'%left <code> '^'%left <code> '&'%left <code> MIN_MAX%left <code> EQCOMPARE%left <code> ARITHCOMPARE '<' '>'%left <code> LSHIFT RSHIFT%left <code> '+' '-'%left <code> '*' '/' '%'%left <code> POINTSAT_STAR DOT_STAR%right <code> UNARY PLUSPLUS MINUSMINUS '~'%left HYPERUNARY%left <ttype> PAREN_STAR_PAREN LEFT_RIGHT%left <code> POINTSAT '.' '(' '['%right SCOPE /* C++ extension */%nonassoc NEW DELETE TRY CATCH%type <code> unop%type <ttype> identifier IDENTIFIER TYPENAME CONSTANT expr nonnull_exprlist%type <ttype> PFUNCNAME maybe_identifier%type <ttype> paren_expr_or_null nontrivial_exprlist SELFNAME%type <ttype> expr_no_commas cast_expr unary_expr primary string STRING%type <ttype> reserved_declspecs boolean.literal%type <ttype> reserved_typespecquals%type <ttype> declmods %type <ttype> SCSPEC TYPESPEC CV_QUALIFIER maybe_cv_qualifier%type <itype> initdecls notype_initdecls initdcl /* C++ modification */%type <ttype> init initlist maybeasm maybe_init defarg defarg1%type <ttype> asm_operands nonnull_asm_operands asm_operand asm_clobbers%type <ttype> maybe_attribute attributes attribute attribute_list attrib%type <ttype> any_word%type <ttype> compstmt implicitly_scoped_stmt%type <ttype> declarator notype_declarator after_type_declarator%type <ttype> notype_declarator_intern absdcl_intern%type <ttype> after_type_declarator_intern%type <ttype> direct_notype_declarator direct_after_type_declarator%type <itype> components notype_components%type <ttype> component_decl component_decl_1 %type <ttype> component_declarator component_declarator0%type <ttype> notype_component_declarator notype_component_declarator0%type <ttype> after_type_component_declarator after_type_component_declarator0%type <ttype> enumlist enumerator%type <ttype> absdcl cv_qualifiers%type <ttype> direct_abstract_declarator conversion_declarator%type <ttype> new_declarator direct_new_declarator%type <ttype> xexpr parmlist parms bad_parm %type <ttype> identifiers_or_typenames%type <ttype> fcast_or_absdcl regcast_or_absdcl%type <ttype> expr_or_declarator expr_or_declarator_intern%type <ttype> complex_notype_declarator%type <ttype> notype_unqualified_id unqualified_id qualified_id%type <ttype> template_id do_id object_template_id notype_template_declarator%type <ttype> overqualified_id notype_qualified_id any_id%type <ttype> complex_direct_notype_declarator functional_cast%type <ttype> complex_parmlist parms_comma %type <ttype> namespace_qualifier namespace_using_decl%type <ftype> type_id new_type_id typed_typespecs typespec typed_declspecs%type <ftype> typed_declspecs1 type_specifier_seq nonempty_cv_qualifiers%type <ftype> structsp typespecqual_reserved parm named_parm full_parm/* C++ extensions */%token <ttype> PTYPENAME%token <ttype> PRE_PARSED_FUNCTION_DECL EXTERN_LANG_STRING ALL%token <ttype> PRE_PARSED_CLASS_DECL DEFARG DEFARG_MARKER%type <ttype> component_constructor_declarator%type <ttype> fn.def2 return_id fn.defpen constructor_declarator%type <itype> ctor_initializer_opt function_try_block%type <ttype> named_class_head_sans_basetype%type <ftype> class_head named_class_head %type <ftype> named_complex_class_head_sans_basetype %type <ttype> unnamed_class_head%type <ttype> base_class_list%type <ttype> base_class_access_list%type <ttype> base_class maybe_base_class_list base_class.1%type <ttype> exception_specification_opt ansi_raise_identifier ansi_raise_identifiers%type <ttype> operator_name%type <ttype> object aggr%type <itype> new delete .begin_new_placement/* %type <ttype> primary_no_id */%type <ttype> nonmomentary_expr maybe_parmlist%type <itype> initdcl0 notype_initdcl0 member_init_list initdcl0_innards%type <ttype> template_header template_parm_list template_parm%type <ttype> template_type_parm template_template_parm%type <code> template_close_bracket%type <ttype> apparent_template_type%type <ttype> template_type template_arg_list template_arg_list_opt%type <ttype> template_arg%type <ttype> condition xcond paren_cond_or_null%type <ttype> type_name nested_name_specifier nested_type ptr_to_mem%type <ttype> complete_type_name notype_identifier nonnested_type%type <ttype> complex_type_name nested_name_specifier_1%type <ttype> new_initializer new_placement%type <ttype> using_decl%type <ttype> typename_sub typename_sub0 typename_sub1 typename_sub2%type <ttype> explicit_template_type/* in order to recognize aggr tags as defining and thus shadowing. */%token TYPENAME_DEFN IDENTIFIER_DEFN PTYPENAME_DEFN%type <ttype> named_class_head_sans_basetype_defn%type <ttype> identifier_defn IDENTIFIER_DEFN TYPENAME_DEFN PTYPENAME_DEFN%type <ttype> self_template_type .finish_template_type%token NSNAME%type <ttype> NSNAME/* Used in lex.c for parsing pragmas. */%token END_OF_LINE/* lex.c and pt.c depend on this being the last token. Define any new tokens before this one! */%token END_OF_SAVED_INPUT%{/* List of types and structure classes of the current declaration. */static tree current_declspecs;/* List of prefix attributes in effect. Prefix attributes are parsed by the reserved_declspecs and declmods rules. They create a list that contains *both* declspecs and attrs. *//* ??? It is not clear yet that all cases where an attribute can now appear in a declspec list have been updated. */static tree prefix_attributes;/* When defining an aggregate, this is the kind of the most recent one being defined. (For example, this might be class_type_node.) */static tree current_aggr;/* When defining an enumeration, this is the type of the enumeration. */static tree current_enum_type;/* Tell yyparse how to print a token's value, if yydebug is set. */#define YYPRINT(FILE,YYCHAR,YYLVAL) yyprint(FILE,YYCHAR,YYLVAL)extern void yyprint PROTO((FILE *, int, YYSTYPE));extern tree combine_strings PROTO((tree));static intparse_decl(declarator, specs_attrs, attributes, initialized, decl) tree declarator; tree specs_attrs; tree attributes; int initialized; tree* decl;{ int sm; split_specs_attrs (specs_attrs, ¤t_declspecs, &prefix_attributes); if (current_declspecs && TREE_CODE (current_declspecs) != TREE_LIST) current_declspecs = build_decl_list (NULL_TREE, current_declspecs); if (have_extern_spec && !used_extern_spec) { current_declspecs = decl_tree_cons (NULL_TREE, get_identifier ("extern"), current_declspecs); used_extern_spec = 1; } sm = suspend_momentary (); *decl = start_decl (declarator, current_declspecs, initialized, attributes, prefix_attributes); return sm;}%}%%/*program: | extdefs { finish_translation_unit (); } ;*/program: ;/* the reason for the strange actions in this rule is so that notype_initdecls when reached via datadef can find a valid list of type and sc specs in $0. */extdefs: { $<ttype>$ = NULL_TREE; } lang_extdef { $<ttype>$ = NULL_TREE; } | extdefs lang_extdef { $<ttype>$ = NULL_TREE; } ;extdefs_opt: extdefs | /* empty */ ;program: extdefs { finish_translation_unit (); } ;.hush_warning: { have_extern_spec = 1; used_extern_spec = 0; $<ttype>$ = NULL_TREE; } ;.warning_ok: { have_extern_spec = 0; } ;extension: EXTENSION { $<itype>$ = pedantic; pedantic = 0; } ;asm_keyword: ASM_KEYWORD ;lang_extdef: { if (pending_lang_change) do_pending_lang_change(); } extdef { if (! toplevel_bindings_p () && ! pseudo_global_level_p()) pop_everything (); } ;extdef: fndef eat_saved_input { if (pending_inlines) do_pending_inlines (); } | datadef { if (pending_inlines) do_pending_inlines (); } | template_def { if (pending_inlines) do_pending_inlines (); } | asm_keyword '(' string ')' ';' { if (TREE_CHAIN ($3)) $3 = combine_strings ($3); assemble_asm ($3); } | extern_lang_string '{' extdefs_opt '}' { pop_lang_context (); } | extern_lang_string .hush_warning fndef .warning_ok eat_saved_input { if (pending_inlines) do_pending_inlines (); pop_lang_context (); } | extern_lang_string .hush_warning datadef .warning_ok { if (pending_inlines) do_pending_inlines (); pop_lang_context (); } | NAMESPACE identifier '{' { push_namespace ($2); } extdefs_opt '}' { pop_namespace (); } | NAMESPACE '{' { push_namespace (NULL_TREE); } extdefs_opt '}' { pop_namespace (); } | namespace_alias | using_decl ';' { do_toplevel_using_decl ($1); } | using_directive | extension extdef { pedantic = $<itype>1; } ;namespace_alias: NAMESPACE identifier '=' { begin_only_namespace_names (); } any_id ';'
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -