📄 cyacc.y
字号:
%expect 13 /* shift/reduce conflicts, and no reduce/reduce conflicts. */%start program%union {long itype; tree ttype; void *otype; struct c_expr exprtype; struct c_arg_info *arginfotype; struct c_declarator *dtrtype; struct c_type_name *typenametype; struct c_parm *parmtype; struct c_declspecs *dsptype; struct c_typespec tstype; enum tree_code code; location_t location; }%token IDENTIFIER%token TYPENAME%token SCSPEC /* Storage class other than static. */%token STATIC /* Static storage class. */%token TYPESPEC%token TYPE_QUAL%token OBJC_TYPE_QUAL%token CONSTANT%token STRING%token ELLIPSIS%token SIZEOF ENUM STRUCT UNION IF ELSE WHILE DO FOR SWITCH CASE DEFAULT%token BREAK CONTINUE RETURN GOTO ASM_KEYWORD TYPEOF ALIGNOF%token ATTRIBUTE EXTENSION LABEL%token REALPART IMAGPART VA_ARG CHOOSE_EXPR TYPES_COMPATIBLE_P%token FUNC_NAME OFFSETOF%nonassoc IF%nonassoc ELSE%right <code> ASSIGN '='%right <code> '?' ':'%left <code> OROR%left <code> ANDAND%left <code> '|'%left <code> '^'%left <code> '&'%left <code> EQCOMPARE%left <code> ARITHCOMPARE%left <code> LSHIFT RSHIFT%left <code> '+' '-'%left <code> '*' '/' '%'%right <code> UNARY PLUSPLUS MINUSMINUS%left HYPERUNARY%left <code> POINTSAT '.' '(' '['%token AT_INTERFACE AT_IMPLEMENTATION AT_END AT_SELECTOR AT_DEFS AT_ENCODE%token CLASSNAME AT_PUBLIC AT_PRIVATE AT_PROTECTED AT_PROTOCOL%token AT_CLASS AT_ALIAS%token AT_THROW AT_TRY AT_CATCH AT_FINALLY AT_SYNCHRONIZED%token OBJC_STRING%type <code> unop%type <ttype> ENUM STRUCT UNION IF ELSE WHILE DO FOR SWITCH CASE DEFAULT%type <ttype> BREAK CONTINUE RETURN GOTO ASM_KEYWORD SIZEOF TYPEOF ALIGNOF%type <ttype> identifier IDENTIFIER TYPENAME CONSTANT STRING FUNC_NAME%type <ttype> nonnull_exprlist exprlist%type <exprtype> expr expr_no_commas cast_expr unary_expr primary%type <dsptype> declspecs_nosc_nots_nosa_noea declspecs_nosc_nots_nosa_ea%type <dsptype> declspecs_nosc_nots_sa_noea declspecs_nosc_nots_sa_ea%type <dsptype> declspecs_nosc_ts_nosa_noea declspecs_nosc_ts_nosa_ea%type <dsptype> declspecs_nosc_ts_sa_noea declspecs_nosc_ts_sa_ea%type <dsptype> declspecs_sc_nots_nosa_noea declspecs_sc_nots_nosa_ea%type <dsptype> declspecs_sc_nots_sa_noea declspecs_sc_nots_sa_ea%type <dsptype> declspecs_sc_ts_nosa_noea declspecs_sc_ts_nosa_ea%type <dsptype> declspecs_sc_ts_sa_noea declspecs_sc_ts_sa_ea%type <dsptype> declspecs_ts declspecs_nots%type <dsptype> declspecs_ts_nosa declspecs_nots_nosa%type <dsptype> declspecs_nosc_ts declspecs_nosc_nots declspecs_nosc declspecs%type <dsptype> maybe_type_quals_attrs%type <tstype> typespec_nonattr typespec_attr%type <tstype> typespec_reserved_nonattr typespec_reserved_attr%type <tstype> typespec_nonreserved_nonattr%type <ttype> offsetof_member_designator%type <ttype> scspec SCSPEC STATIC TYPESPEC TYPE_QUAL maybe_volatile%type <ttype> initdecls notype_initdecls initdcl notype_initdcl%type <exprtype> init%type <ttype> simple_asm_expr maybeasm asm_stmt asm_argument asm_string%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 compstmt_start compstmt_primary_start%type <ttype> stmt label stmt_nocomp start_break start_continue%type <ttype> c99_block_start c99_block_lineno_labeled_stmt%type <ttype> if_statement_1 if_statement_2%type <dtrtype> declarator%type <dtrtype> notype_declarator after_type_declarator%type <dtrtype> parm_declarator%type <dtrtype> parm_declarator_starttypename parm_declarator_nostarttypename%type <dtrtype> array_declarator%type <tstype> structsp_attr structsp_nonattr%type <ttype> component_decl_list component_decl_list2%type <ttype> component_decl components components_notype component_declarator%type <ttype> component_notype_declarator%type <ttype> enumlist enumerator%type <ttype> struct_head union_head enum_head%type <typenametype> typename%type <dtrtype> absdcl absdcl1 absdcl1_ea absdcl1_noea direct_absdcl1%type <parmtype> absdcl_maybe_attribute%type <ttype> condition xexpr for_cond_expr for_incr_expr%type <parmtype> parm firstparm%type <ttype> identifiers%type <arginfotype> parms parmlist parmlist_1 parmlist_2%type <arginfotype> parmlist_or_identifiers parmlist_or_identifiers_1%type <ttype> identifiers_or_typenames%type <itype> setspecs setspecs_fp extension%type <location> save_location%type <otype> save_obstack_position%{%}%%program: | extdefs ;extdefs: save_obstack_position extdef | extdefs save_obstack_position extdef ;extdef: fndef | datadef | asmdef | extension extdef ;save_obstack_position: ;datadef: setspecs notype_initdecls ';' | declspecs_nots setspecs notype_initdecls ';' | declspecs_ts setspecs initdecls ';' | declspecs ';' | error ';' | error '}' | ';' ;fndef: declspecs_ts setspecs declarator old_style_parm_decls save_location compstmt_or_error | declspecs_ts setspecs declarator error | declspecs_nots setspecs notype_declarator old_style_parm_decls save_location compstmt_or_error | declspecs_nots setspecs notype_declarator error | setspecs notype_declarator old_style_parm_decls save_location compstmt_or_error | setspecs notype_declarator error ;identifier: IDENTIFIER | TYPENAME ;unop: '&' { $$ = ADDR_EXPR; } | '-' { $$ = NEGATE_EXPR; } | '+' { $$ = CONVERT_EXPR; if (warn_traditional && !in_system_header) warning ("traditional C rejects the unary plus operator"); } | PLUSPLUS | MINUSMINUS | '~' | '!' ;expr: expr_no_commas | expr ',' expr_no_commas { $$.value = build_compound_expr ($1.value, $3.value); $$.original_code = COMPOUND_EXPR; } ;exprlist: /* empty */ { $$ = NULL_TREE; } | nonnull_exprlist ;nonnull_exprlist: expr_no_commas { $$ = build_tree_list (NULL_TREE, $1.value); } | nonnull_exprlist ',' expr_no_commas { chainon ($1, build_tree_list (NULL_TREE, $3.value)); } ;unary_expr: primary | '*' cast_expr %prec UNARY { $$.value = build_indirect_ref ($2.value, "unary *"); $$.original_code = ERROR_MARK; } /* __extension__ turns off -pedantic for following primary. */ | extension cast_expr %prec UNARY { $$ = $2; RESTORE_EXT_FLAGS ($1); } | unop cast_expr %prec UNARY { $$.value = build_unary_op ($1, $2.value, 0); overflow_warning ($$.value); $$.original_code = ERROR_MARK; } /* Refer to the address of a label as a pointer. */ | ANDAND identifier { $$.value = finish_label_address_expr ($2); $$.original_code = ERROR_MARK; } | sizeof unary_expr %prec UNARY { skip_evaluation--; in_sizeof--; if (TREE_CODE ($2.value) == COMPONENT_REF && DECL_C_BIT_FIELD (TREE_OPERAND ($2.value, 1))) error ("%<sizeof%> applied to a bit-field"); $$ = c_expr_sizeof_expr ($2); } | sizeof '(' typename ')' %prec HYPERUNARY { skip_evaluation--; in_sizeof--; $$ = c_expr_sizeof_type ($3); } | alignof unary_expr %prec UNARY { skip_evaluation--; in_alignof--; $$.value = c_alignof_expr ($2.value); $$.original_code = ERROR_MARK; } | alignof '(' typename ')' %prec HYPERUNARY { skip_evaluation--; in_alignof--; $$.value = c_alignof (groktypename ($3)); $$.original_code = ERROR_MARK; } | REALPART cast_expr %prec UNARY { $$.value = build_unary_op (REALPART_EXPR, $2.value, 0); $$.original_code = ERROR_MARK; } | IMAGPART cast_expr %prec UNARY { $$.value = build_unary_op (IMAGPART_EXPR, $2.value, 0); $$.original_code = ERROR_MARK; } ;sizeof: SIZEOF { skip_evaluation++; in_sizeof++; } ;alignof: ALIGNOF { skip_evaluation++; in_alignof++; } ;typeof: TYPEOF { skip_evaluation++; in_typeof++; } ;cast_expr: unary_expr | '(' typename ')' cast_expr %prec UNARY { $$.value = c_cast_expr ($2, $4.value); $$.original_code = ERROR_MARK; } ;expr_no_commas: cast_expr | expr_no_commas '+' expr_no_commas { $$ = parser_build_binary_op ($2, $1, $3); } | expr_no_commas '-' expr_no_commas { $$ = parser_build_binary_op ($2, $1, $3); } | expr_no_commas '*' expr_no_commas { $$ = parser_build_binary_op ($2, $1, $3); } | expr_no_commas '/' expr_no_commas { $$ = parser_build_binary_op ($2, $1, $3); } | expr_no_commas '%' expr_no_commas { $$ = parser_build_binary_op ($2, $1, $3); } | expr_no_commas LSHIFT expr_no_commas { $$ = parser_build_binary_op ($2, $1, $3); } | expr_no_commas RSHIFT expr_no_commas { $$ = parser_build_binary_op ($2, $1, $3); } | expr_no_commas ARITHCOMPARE expr_no_commas { $$ = parser_build_binary_op ($2, $1, $3); } | expr_no_commas EQCOMPARE expr_no_commas { $$ = parser_build_binary_op ($2, $1, $3); } | expr_no_commas '&' expr_no_commas { $$ = parser_build_binary_op ($2, $1, $3); } | expr_no_commas '|' expr_no_commas { $$ = parser_build_binary_op ($2, $1, $3); } | expr_no_commas '^' expr_no_commas { $$ = parser_build_binary_op ($2, $1, $3); } | expr_no_commas ANDAND { $1.value = lang_hooks.truthvalue_conversion (default_conversion ($1.value)); skip_evaluation += $1.value == truthvalue_false_node; } expr_no_commas { skip_evaluation -= $1.value == truthvalue_false_node; $$ = parser_build_binary_op (TRUTH_ANDIF_EXPR, $1, $4); } | expr_no_commas OROR { $1.value = lang_hooks.truthvalue_conversion (default_conversion ($1.value)); skip_evaluation += $1.value == truthvalue_true_node; } expr_no_commas { skip_evaluation -= $1.value == truthvalue_true_node; $$ = parser_build_binary_op (TRUTH_ORIF_EXPR, $1, $4); } | expr_no_commas '?' { $1.value = lang_hooks.truthvalue_conversion (default_conversion ($1.value)); skip_evaluation += $1.value == truthvalue_false_node; } expr ':' { skip_evaluation += (($1.value == truthvalue_true_node) - ($1.value == truthvalue_false_node)); } expr_no_commas { skip_evaluation -= $1.value == truthvalue_true_node; $$.value = build_conditional_expr ($1.value, $4.value, $7.value); $$.original_code = ERROR_MARK; } | expr_no_commas '?' { if (pedantic) pedwarn ("ISO C forbids omitting the middle term of a ?: expression"); /* Make sure first operand is calculated only once. */ $<ttype>2 = save_expr (default_conversion ($1.value)); $1.value = lang_hooks.truthvalue_conversion ($<ttype>2); skip_evaluation += $1.value == truthvalue_true_node; } ':' expr_no_commas { skip_evaluation -= $1.value == truthvalue_true_node; $$.value = build_conditional_expr ($1.value, $<ttype>2, $5.value); $$.original_code = ERROR_MARK; } | expr_no_commas '=' expr_no_commas { $$.value = build_modify_expr ($1.value, NOP_EXPR, $3.value); $$.original_code = MODIFY_EXPR; } | expr_no_commas ASSIGN expr_no_commas { $$.value = build_modify_expr ($1.value, $2, $3.value); TREE_NO_WARNING ($$.value) = 1; $$.original_code = ERROR_MARK; } ;primary: IDENTIFIER { if (yychar == YYEMPTY) yychar = YYLEX; $$.value = build_external_ref ($1, yychar == '('); $$.original_code = ERROR_MARK; } | CONSTANT { $$.value = $1; $$.original_code = ERROR_MARK; } | STRING { $$.value = $1; $$.original_code = STRING_CST; } | FUNC_NAME { $$.value = fname_decl (C_RID_CODE ($1), $1); $$.original_code = ERROR_MARK; } | '(' typename ')' '{' { start_init (NULL_TREE, NULL, 0); $<ttype>$ = groktypename ($2); if (C_TYPE_VARIABLE_SIZE ($<ttype>$)) { error ("compound literal has variable size"); $<ttype>$ = error_mark_node; } really_start_incremental_init ($<ttype>$); } initlist_maybe_comma '}' %prec UNARY { struct c_expr init = pop_init_level (0); tree constructor = init.value; tree type = $<ttype>5; finish_init (); maybe_warn_string_init (type, init); if (pedantic && !flag_isoc99) pedwarn ("ISO C90 forbids compound literals"); $$.value = build_compound_literal (type, constructor); $$.original_code = ERROR_MARK; } | '(' expr ')' { $$.value = $2.value; if (TREE_CODE ($$.value) == MODIFY_EXPR) TREE_NO_WARNING ($$.value) = 1; $$.original_code = ERROR_MARK; } | '(' error ')' { $$.value = error_mark_node; $$.original_code = ERROR_MARK; } | compstmt_primary_start compstmt_nostart ')' { if (pedantic) pedwarn ("ISO C forbids braced-groups within expressions"); $$.value = c_finish_stmt_expr ($1); $$.original_code = ERROR_MARK; } | compstmt_primary_start error ')' { c_finish_stmt_expr ($1); $$.value = error_mark_node; $$.original_code = ERROR_MARK; } | primary '(' exprlist ')' %prec '.' { $$.value = build_function_call ($1.value, $3); $$.original_code = ERROR_MARK; } | VA_ARG '(' expr_no_commas ',' typename ')' { $$.value = build_va_arg ($3.value, groktypename ($5)); $$.original_code = ERROR_MARK; } | OFFSETOF '(' typename ',' { tree type = groktypename ($3); if (type == error_mark_node) offsetof_base = error_mark_node; else offsetof_base = build1 (INDIRECT_REF, type, NULL); } offsetof_member_designator ')' { $$.value = fold_offsetof ($6); $$.original_code = ERROR_MARK; } | OFFSETOF '(' error ')' { $$.value = error_mark_node; $$.original_code = ERROR_MARK; } | CHOOSE_EXPR '(' expr_no_commas ',' expr_no_commas ',' expr_no_commas ')' { tree c; c = fold ($3.value); STRIP_NOPS (c); if (TREE_CODE (c) != INTEGER_CST) error ("first argument to %<__builtin_choose_expr%> not" " a constant"); $$ = integer_zerop (c) ? $7 : $5; } | CHOOSE_EXPR '(' error ')' { $$.value = error_mark_node; $$.original_code = ERROR_MARK; } | TYPES_COMPATIBLE_P '(' typename ',' typename ')' { tree e1, e2; e1 = TYPE_MAIN_VARIANT (groktypename ($3)); e2 = TYPE_MAIN_VARIANT (groktypename ($5)); $$.value = comptypes (e1, e2) ? build_int_cst (NULL_TREE, 1) : build_int_cst (NULL_TREE, 0); $$.original_code = ERROR_MARK; } | TYPES_COMPATIBLE_P '(' error ')' { $$.value = error_mark_node; $$.original_code = ERROR_MARK; } | primary '[' expr ']' %prec '.' { $$.value = build_array_ref ($1.value, $3.value); $$.original_code = ERROR_MARK; } | primary '.' identifier { $$.value = build_component_ref ($1.value, $3); $$.original_code = ERROR_MARK; } | primary POINTSAT identifier { tree expr = build_indirect_ref ($1.value, "->");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -