⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cyacc.y

📁 使用yacc和lex编写的cmm语言的词法分析和语法分析程序.
💻 Y
📖 第 1 页 / 共 5 页
字号:
		}	| enum_head identifier '{'		{ $<ttype>$ = start_enum ($2); }	  enumlist maybecomma_warn '}' maybe_attribute		{ $$.spec = finish_enum ($<ttype>4, nreverse ($5),					 chainon ($1, $8));		  $$.kind = ctsk_tagdef; }	| enum_head '{'		{ $<ttype>$ = start_enum (NULL_TREE); }	  enumlist maybecomma_warn '}' maybe_attribute		{ $$.spec = finish_enum ($<ttype>3, nreverse ($4),					 chainon ($1, $7));		  $$.kind = ctsk_tagdef; }	;structsp_nonattr:	  struct_head identifier		{ $$ = parser_xref_tag (RECORD_TYPE, $2); }	| union_head identifier		{ $$ = parser_xref_tag (UNION_TYPE, $2); }	| enum_head identifier		{ $$ = parser_xref_tag (ENUMERAL_TYPE, $2);		  /* In ISO C, enumerated types can be referred to		     only if already defined.  */		  if (pedantic && !COMPLETE_TYPE_P ($$.spec))		    pedwarn ("ISO C forbids forward references to %<enum%> types"); }	;maybecomma:	  /* empty */	| ','	;maybecomma_warn:	  /* empty */	| ','		{ if (pedantic && !flag_isoc99)		    pedwarn ("comma at end of enumerator list"); }	;/* We chain the components in reverse order.  They are put in forward   order in structsp_attr.   Note that component_declarator returns single decls, so components   and components_notype can use TREE_CHAIN directly, wheras components   and components_notype return lists (of comma separated decls), so   component_decl_list and component_decl_list2 must use chainon.   The theory behind all this is that there will be more semicolon   separated fields than comma separated fields, and so we'll be   minimizing the number of node traversals required by chainon.  */component_decl_list:	  component_decl_list2		{ $$ = $1; }	| component_decl_list2 component_decl		{ $$ = chainon ($2, $1);		  pedwarn ("no semicolon at end of struct or union"); }	;component_decl_list2:	/* empty */		{ $$ = NULL_TREE; }	| component_decl_list2 component_decl ';'		{ $$ = chainon ($2, $1); }	| component_decl_list2 ';'		{ if (pedantic)		    pedwarn ("extra semicolon in struct or union specified"); }	;component_decl:	  declspecs_nosc_ts setspecs components		{ $$ = $3;		  POP_DECLSPEC_STACK; }	| declspecs_nosc_ts setspecs		{		  /* Support for unnamed structs or unions as members of		     structs or unions (which is [a] useful and [b] supports		     MS P-SDK).  */		  $$ = grokfield (build_id_declarator (NULL_TREE),				  current_declspecs, NULL_TREE);		  POP_DECLSPEC_STACK; }	| declspecs_nosc_nots setspecs components_notype		{ $$ = $3;		  POP_DECLSPEC_STACK; }	| declspecs_nosc_nots		{ if (pedantic)		    pedwarn ("ISO C forbids member declarations with no members");		  shadow_tag_warned (finish_declspecs ($1), pedantic);		  $$ = NULL_TREE; }	| error		{ $$ = NULL_TREE; }	| extension component_decl		{ $$ = $2;		  RESTORE_EXT_FLAGS ($1); }	;components:	  component_declarator	| components ',' maybe_resetattrs component_declarator		{ TREE_CHAIN ($4) = $1; $$ = $4; }	;components_notype:	  component_notype_declarator	| components_notype ',' maybe_resetattrs component_notype_declarator		{ TREE_CHAIN ($4) = $1; $$ = $4; }	;component_declarator:	  declarator maybe_attribute		{ $$ = grokfield ($1, current_declspecs, NULL_TREE);		  decl_attributes (&$$,				   chainon ($2, all_prefix_attributes), 0); }	| declarator ':' expr_no_commas maybe_attribute		{ $$ = grokfield ($1, current_declspecs, $3.value);		  decl_attributes (&$$,				   chainon ($4, all_prefix_attributes), 0); }	| ':' expr_no_commas maybe_attribute		{ $$ = grokfield (build_id_declarator (NULL_TREE),				  current_declspecs, $2.value);		  decl_attributes (&$$,				   chainon ($3, all_prefix_attributes), 0); }	;component_notype_declarator:	  notype_declarator maybe_attribute		{ $$ = grokfield ($1, current_declspecs, NULL_TREE);		  decl_attributes (&$$,				   chainon ($2, all_prefix_attributes), 0); }	| notype_declarator ':' expr_no_commas maybe_attribute		{ $$ = grokfield ($1, current_declspecs, $3.value);		  decl_attributes (&$$,				   chainon ($4, all_prefix_attributes), 0); }	| ':' expr_no_commas maybe_attribute		{ $$ = grokfield (build_id_declarator (NULL_TREE),				  current_declspecs, $2.value);		  decl_attributes (&$$,				   chainon ($3, all_prefix_attributes), 0); }	;/* We chain the enumerators in reverse order.   They are put in forward order in structsp_attr.  */enumlist:	  enumerator	| enumlist ',' enumerator		{ if ($1 == error_mark_node)		    $$ = $1;		  else		    TREE_CHAIN ($3) = $1, $$ = $3; }	| error		{ $$ = error_mark_node; }	;enumerator:	  identifier		{ $$ = build_enumerator ($1, NULL_TREE); }	| identifier '=' expr_no_commas		{ $$ = build_enumerator ($1, $3.value); }	;typename:	  declspecs_nosc		{ pending_xref_error ();		  $<dsptype>$ = finish_declspecs ($1); }	  absdcl		{ $$ = XOBNEW (&parser_obstack, struct c_type_name);		  $$->specs = $<dsptype>2;		  $$->declarator = $3; }	;absdcl:   /* an absolute declarator */	/* empty */		{ $$ = build_id_declarator (NULL_TREE); }	| absdcl1	;absdcl_maybe_attribute:   /* absdcl maybe_attribute, but not just attributes */	/* empty */		{ $$ = build_c_parm (current_declspecs, all_prefix_attributes,				     build_id_declarator (NULL_TREE)); }	| absdcl1		{ $$ = build_c_parm (current_declspecs, all_prefix_attributes,				     $1); }	| absdcl1_noea attributes		{ $$ = build_c_parm (current_declspecs,				     chainon ($2, all_prefix_attributes),				     $1); }	;absdcl1:  /* a nonempty absolute declarator */	  absdcl1_ea	| absdcl1_noea	;absdcl1_noea:	  direct_absdcl1	| '*' maybe_type_quals_attrs absdcl1_noea		{ $$ = make_pointer_declarator ($2, $3); }	;absdcl1_ea:	  '*' maybe_type_quals_attrs		{ $$ = make_pointer_declarator		    ($2, build_id_declarator (NULL_TREE)); }	| '*' maybe_type_quals_attrs absdcl1_ea		{ $$ = make_pointer_declarator ($2, $3); }	;direct_absdcl1:	  '(' maybe_attribute absdcl1 ')'		{ $$ = $2 ? build_attrs_declarator ($2, $3) : $3; }	| direct_absdcl1 '(' parmlist		{ $$ = build_function_declarator ($3, $1); }	| direct_absdcl1 array_declarator		{ $$ = set_array_declarator_inner ($2, $1, true); }	| '(' parmlist		{ $$ = build_function_declarator		    ($2, build_id_declarator (NULL_TREE)); }	| array_declarator		{ $$ = set_array_declarator_inner		    ($1, build_id_declarator (NULL_TREE), true); }	;/* The [...] part of a declarator for an array type.  */array_declarator:	'[' maybe_type_quals_attrs expr_no_commas ']'		{ $$ = build_array_declarator ($3.value, $2, false, false); }	| '[' maybe_type_quals_attrs ']'		{ $$ = build_array_declarator (NULL_TREE, $2, false, false); }	| '[' maybe_type_quals_attrs '*' ']'		{ $$ = build_array_declarator (NULL_TREE, $2, false, true); }	| '[' STATIC maybe_type_quals_attrs expr_no_commas ']'		{ $$ = build_array_declarator ($4.value, $3, true, false); }	/* declspecs_nosc_nots is a synonym for type_quals_attrs.  */	| '[' declspecs_nosc_nots STATIC expr_no_commas ']'		{ $$ = build_array_declarator ($4.value, $2, true, false); }	;/* A nonempty series of declarations and statements (possibly followed by   some labels) that can form the body of a compound statement.   NOTE: we don't allow labels on declarations; this might seem like a   natural extension, but there would be a conflict between attributes   on the label and prefix attributes on the declaration.  */stmts_and_decls:	  lineno_stmt_decl_or_labels_ending_stmt	| lineno_stmt_decl_or_labels_ending_decl	| lineno_stmt_decl_or_labels_ending_label		{		  error ("label at end of compound statement");		}	| lineno_stmt_decl_or_labels_ending_error	;lineno_stmt_decl_or_labels_ending_stmt:	  lineno_stmt	| lineno_stmt_decl_or_labels_ending_stmt lineno_stmt	| lineno_stmt_decl_or_labels_ending_decl lineno_stmt	| lineno_stmt_decl_or_labels_ending_label lineno_stmt	| lineno_stmt_decl_or_labels_ending_error lineno_stmt	;lineno_stmt_decl_or_labels_ending_decl:	  lineno_decl	| lineno_stmt_decl_or_labels_ending_stmt lineno_decl		{		  if ((pedantic && !flag_isoc99)		      || warn_declaration_after_statement)		    pedwarn_c90 ("ISO C90 forbids mixed declarations and code");		}	| lineno_stmt_decl_or_labels_ending_decl lineno_decl	| lineno_stmt_decl_or_labels_ending_error lineno_decl	;lineno_stmt_decl_or_labels_ending_label:	  lineno_label	| lineno_stmt_decl_or_labels_ending_stmt lineno_label	| lineno_stmt_decl_or_labels_ending_decl lineno_label	| lineno_stmt_decl_or_labels_ending_label lineno_label	| lineno_stmt_decl_or_labels_ending_error lineno_label	;lineno_stmt_decl_or_labels_ending_error:	errstmt	| lineno_stmt_decl_or_labels errstmt	;lineno_stmt_decl_or_labels:	  lineno_stmt_decl_or_labels_ending_stmt	| lineno_stmt_decl_or_labels_ending_decl	| lineno_stmt_decl_or_labels_ending_label	| lineno_stmt_decl_or_labels_ending_error	;errstmt:  error ';'	;/* Start and end blocks created for the new scopes of C99.  */c99_block_start: /* empty */		{ $$ = c_begin_compound_stmt (flag_isoc99); }	;/* Read zero or more forward-declarations for labels   that nested functions can jump to.  */maybe_label_decls:	  /* empty */	| label_decls		{ if (pedantic)		    pedwarn ("ISO C forbids label declarations"); }	;label_decls:	  label_decl	| label_decls label_decl	;label_decl:	  LABEL identifiers_or_typenames ';'		{ tree link;		  for (link = $2; link; link = TREE_CHAIN (link))		    {		      tree label = declare_label (TREE_VALUE (link));		      C_DECLARED_LABEL_FLAG (label) = 1;		      add_stmt (build_stmt (DECL_EXPR, label));		    }		}	;/* This is the body of a function definition.   It causes syntax errors to ignore to the next openbrace.  */compstmt_or_error:	  compstmt		{ add_stmt ($1); }	| error compstmt	;compstmt_start: '{' { $$ = c_begin_compound_stmt (true); }        ;compstmt_nostart: '}'	| maybe_label_decls compstmt_contents_nonempty '}'	;compstmt_contents_nonempty:	  stmts_and_decls	| error	;compstmt_primary_start:	'(' '{'		{ if (cur_stmt_list == NULL)		    {		      error ("braced-group within expression allowed "			     "only inside a function");		      YYERROR;		    }		  $$ = c_begin_stmt_expr ();		}        ;compstmt: compstmt_start compstmt_nostart		{ $$ = c_end_compound_stmt ($1, true); }	;/* The forced readahead in here is because we might be at the end of a   line, and the line and file won't be bumped until yylex absorbs the   first token on the next line.  */save_location:		{ if (yychar == YYEMPTY)		    yychar = YYLEX;		  $$ = input_location; }	;lineno_labels:	  /* empty */	| lineno_labels lineno_label	;/* A labeled statement.  In C99 it also generates an implicit block.  */c99_block_lineno_labeled_stmt:	  c99_block_start lineno_labels lineno_stmt                { $$ = c_end_compound_stmt ($1, flag_isoc99); }	;lineno_stmt:	  save_location stmt		{		  /* Two cases cannot and do not have line numbers associated:		     If stmt is degenerate, such as "2;", then stmt is an		     INTEGER_CST, which cannot hold line numbers.  But that's		     ok because the statement will either be changed to a		     MODIFY_EXPR during gimplification of the statement expr,		     or discarded.  If stmt was compound, but without new		     variables, we will have skipped the creation of a BIND		     and will have a bare STATEMENT_LIST.  But that's ok		     because (recursively) all of the component statments		     should already have line numbers assigned.  */		  if ($2 && EXPR_P ($2))		    SET_EXPR_LOCATION ($2, $1);		}	;lineno_label:	  save_location label		{ if ($2) SET_EXPR_LOCATION ($2, $1); }	;condition: save_location expr		{ $$ = lang_hooks.truthvalue_conversion ($2.value);		  if (EXPR_P ($$))		    SET_EXPR_LOCATION ($$, $1); }	;/* Implement -Wparenthesis by special casing IF statement directly nested   within IF statement.  This requires some amount of duplication of the   productions under c99_block_lineno_labeled_stmt in order to work out.   But it's still likely more maintainable than lots of state outside the   parser...  */if_statement_1:	c99_block_start lineno_labels if_statement		{ $$ = c_end_compound_stmt ($1, flag_isoc99); }	;if_statement_2:	  c99_block_start lineno_labels ';'		{ if (extra_warnings)		    add_stmt (build (NOP_EXPR, NULL_TREE, NULL_TREE));		  $$ = c_end_compound_stmt ($1, flag_isoc99); }	| c99_block_lineno_labeled_stmt	;if_statement:	  IF c99_block_start save_location '(' condition ')'	    if_statement_1 ELSE if_statement_2		{ c_finish_if_stmt ($3, $5, $7, $9, true);		  add_stmt (c_end_compound_stmt ($2, flag_isoc99)); }	| IF c99_block_start save_location '(' condition ')'	    if_statement_2 ELSE if_statement_2

⌨️ 快捷键说明

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