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

📄 ytab.c

📁 一个小型的c语言编译器,做的非常好,不过不是我做的.
💻 C
📖 第 1 页 / 共 5 页
字号:
				yyerror("more arguments not support now");
				user_exit(1);
			} break;
case 49:
# line 806 "c.y"
{
				PARSE_INFO("parameter_list :parameter_declaration")
			} break;
case 50:
# line 810 "c.y"
{
				PARSE_INFO("parameter_list :parameter_list oCOMMA parameter_declaration")
				// if in this state, parameter is void, it must be 
				// in declaration_specifiers
				// so it must has (..., void,..) or (void, ...)
				// error
				if (yypvt[-0].p_symbol->NOUN == SPEC_VOID || yypvt[-2].p_symbol->NOUN == SPEC_VOID)
				{
					yyerror("'void' cannot be an argument type, except for '(void)'");
					user_exit(1);
				}
				link_symbol_list(yypvt[-2].p_symbol, yypvt[-0].p_symbol);
			} break;
case 51:
# line 827 "c.y"
{
				PARSE_INFO("parameter_declaration :declaration_specifiers declarator")
				unoin_specifier_to_declarator(yypvt[-1].p_symbol, yypvt[-0].p_symbol);
				del_symbol( yypvt[-1].p_symbol );
				// set argument flag
				yypvt[-0].p_symbol->is_argument = 1;
				if ( !IS_VAR(yypvt[-0].p_symbol) )
				{
					yyerror("function has bad storage class");
					user_exit(1);
				}
				check_var_declarator(yypvt[-0].p_symbol);
				yyval.p_symbol = yypvt[-0].p_symbol;
			} break;
case 52:
# line 842 "c.y"
{
				PARSE_INFO("parameter_declaration :declaration_specifiers abstract_declarator")
				unoin_specifier_to_declarator(yypvt[-1].p_symbol, yypvt[-0].p_symbol);
				del_symbol( yypvt[-1].p_symbol );
				// set argument flag
				yypvt[-1].p_symbol->is_argument = 1;
				if ( !IS_VAR(yypvt[-0].p_symbol) )
				{
					yyerror("function has bad storage class");
					user_exit(1);
				}
				check_var_declarator(yypvt[-0].p_symbol);
				yyval.p_symbol = yypvt[-0].p_symbol;
			} break;
case 53:
# line 857 "c.y"
{
				PARSE_INFO("parameter_declaration :declaration_specifiers")
				// it means in declaration is not use, and 
				// in definition is can not use the parameter
				// so assign the args a unmeeted name, such as number, xixi....
				// just use specifier symbol as var
				
				// set argument flag
				yypvt[-0].p_symbol->is_argument = 1;
				if ( !IS_VAR(yypvt[-0].p_symbol) )
				{
					yyerror("function has bad storage class");
					user_exit(1);
				}
				// assign symbol a unused name
				assign_symbol_unusedname(yypvt[-0].p_symbol);
			} break;
case 54:
# line 891 "c.y"
{
				PARSE_INFO("initializer :assignment_expression")
			} break;
case 55:
# line 895 "c.y"
{
				PARSE_INFO("initializer :oLC initializer_list oRC")
				yyerror("initialize = {....} not support");
				user_exit(1);
			} break;
case 56:
# line 901 "c.y"
{
				PARSE_INFO("initializer :oLC initializer_list oCOMMA oRC")
				yyerror("initialize = {...., } not support");
				user_exit(1);
			} break;
case 57:
# line 910 "c.y"
{
				PARSE_INFO("initializer_list :initializer")
			} break;
case 58:
# line 914 "c.y"
{
				PARSE_INFO("initializer_list :initializer_list oCOMMA initializer")
			} break;
case 59:
# line 946 "c.y"
{
				PARSE_INFO("abstract_declarator :direct_abstract_declarator")
			} break;
case 60:
# line 968 "c.y"
{
				PARSE_INFO("direct_abstract_declarator :oLB constant_expression oRB")
				// array declaration
				// check constant_expression
				if ( !IS_CL(yypvt[-1].p_symbol) )
				{
					yyerror("array unknown size");
					user_exit(1);
				}
				if ( !get_sym_value(yypvt[-1].p_symbol) )
				{
					yyerror("cannot allocate an array of constant size 0");
					user_exit(1);
				}
				if (get_sym_value(yypvt[-1].p_symbol) < 0)
				{
					yyerror("negative subscript or subscript is too large");
					user_exit(1);
				}
				yyval.p_symbol = new_symbol();
				// assign symbol a unused name
				assign_symbol_unusedname(yyval.p_symbol);
				// set array flag
				yyval.p_symbol->is_array = 1;
				yyval.p_symbol->num_ele = get_sym_value(yypvt[-1].p_symbol);
				del_symbol(yypvt[-1].p_symbol);
			} break;
case 61:
# line 1009 "c.y"
{
				PARSE_INFO("identifier :yNAME")
				PARSE_INFO("======= FOLLOW BY =======")
				PARSE_INFO(yypvt[-0].p_char)
			} break;
case 62:
# line 1018 "c.y"
{
				PARSE_INFO("statement :labeled_statement")
			} break;
case 63:
# line 1022 "c.y"
{
				PARSE_INFO("statement :expression_statement")
			} break;
case 64:
# line 1026 "c.y"
{
				PARSE_INFO("statement :compound_statement")
			} break;
case 65:
# line 1030 "c.y"
{
				PARSE_INFO("statement :selection_statement")
			} break;
case 66:
# line 1034 "c.y"
{
				PARSE_INFO("statement :iteration_statement")
			} break;
case 67:
# line 1038 "c.y"
{
				PARSE_INFO("statement :jump_statement")
			} break;
case 68:
# line 1045 "c.y"
{
				symbol	*lb;

				PARSE_INFO("labeled_statement :identifier oCOLON ")
				lb = search_goto_label(yypvt[-1].p_char);
				if ( !lb )
				{
					// the label has not be reference
					// so, new symbol and add it to goto label symtab
					lb = new_symbol();
					lb->NOUN = SPEC_LABEL;
					strcpy(lb->name, yypvt[-1].p_char);
					strcpy(lb->rname, get_a_label());
					add_goto_label(lb);
				}
				else if ( !IS_LAB_DECL(lb) )
				{
					// the label has been used
					parse_error(yypvt[-1].p_char, " : redefine label");
					user_exit(1);
				}
				else
				{
					// the label only be reference
					// so, change the decl flag
					lb->is_declaration = 0;
				}
				// label:
				gen_label(lb->rname);
			} break;
case 69:
# line 1076 "c.y"
{
				PARSE_INFO("statement")
			} break;
case 70:
# line 1080 "c.y"
{
				symbol	*cs;

				PARSE_INFO("labeled_statement :kCASE constant_expression oCOLON ")
				if ( !IS_CL(yypvt[-1].p_symbol) )
				{
					yyerror("case expression not constant");
					user_exit(1);
				}
				cs = new_symbol();

				strcpy(cs->name, _CASE_NAME);
				// get a label
				strcpy(cs->rname, get_a_label());
				cs->V_I = get_sym_value(yypvt[-1].p_symbol);
				add_case_to_switch(cs);
				// label:
				gen_label(cs->rname);
			} break;
case 71:
# line 1100 "c.y"
{
				PARSE_INFO("statement")
			} break;
case 72:
# line 1104 "c.y"
{
				symbol	*cs;

				PARSE_INFO("labeled_statement :kDEFAULT oCOLON ")
				cs = new_symbol();

				strcpy(cs->name, _DEFAULT_NAME);
				// get a label
				strcpy(cs->rname, get_a_label());
				add_case_to_switch(cs);
				// label:
				gen_label(cs->rname);
			} break;
case 73:
# line 1118 "c.y"
{
				PARSE_INFO("statement")
			} break;
case 74:
# line 1125 "c.y"
{
				PARSE_INFO("expression_statement :expression oSEMI")

				GEN_END_EXPRESS(yypvt[-1].p_symbol)
				
				if (yypvt[-1].p_symbol)
					del_symbol(yypvt[-1].p_symbol);
			} break;
case 75:
# line 1136 "c.y"
{
				PARSE_INFO("compound_statement :oLC declaration_list ");

				if ( sg_parameter_list )
				// means this compound statement belong to a function, so...
				// of course, if sg_parameter_list is NULL it also maybe a
				// compound statement belong to a function because the parameters
				// is void , heihei....
				{
					add_symbol_list_to_current_symtab(sg_parameter_list);
					sg_parameter_list = NULL;
				}
					
				gen_var_assign_init(yypvt[-0].p_symbol);
			} break;
case 76:
# line 1152 "c.y"
{
				PARSE_INFO("statement_list oRC");
				del_compound_symtab();
			} break;
case 77:
# line 1157 "c.y"
{
				PARSE_INFO("compound_statement :oLC ")

				if ( sg_parameter_list )
				// means this compound statement belong to a function, so...
				// of course, if sg_parameter_list is NULL it also maybe a
				// compound statement belong to a function because the parameters
				// is void , heihei....
				{
					add_symbol_list_to_current_symtab(sg_parameter_list);
					sg_parameter_list = NULL;
				}
			} break;
case 78:
# line 1171 "c.y"
{
				PARSE_INFO("statement_list oRC");
				del_compound_symtab();
			} break;
case 79:
# line 1176 "c.y"
{
				PARSE_INFO("compound_statement :oLC declaration_list ")

				if ( sg_parameter_list )
				// means this compound statement belong to a function, so...
				// of course, if sg_parameter_list is NULL it also maybe a
				// compound statement belong to a function because the parameters
				// is void , heihei....
				{
					add_symbol_list_to_current_symtab( sg_parameter_list );
					sg_parameter_list = NULL;
				}

				gen_var_assign_init(yypvt[-0].p_symbol);
			} break;
case 80:
# line 1192 "c.y"
{
				PARSE_INFO("oRC");
				yyerror("waring : compound statement has only declaration, no statements");
				del_compound_symtab();
			} break;
case 81:
# line 1198 "c.y"
{
				PARSE_INFO("compound_statement :oLC oRC")

				if ( sg_parameter_list )
				// means this compound statement belong to a function, so...
				// of course, if sg_parameter_list is NULL it also maybe a
				// compound statement belong to a function because the parameters
				// is void , heihei....
				{
					add_symbol_list_to_current_symtab( sg_parameter_list );
					sg_parameter_list = NULL;
				}

				yyerror("waring : compound statement is empty");
				del_compound_symtab();
			} break;
case 82:
# line 1218 "c.y"
{
				PARSE_INFO("statement_list :statement")
			} break;
case 83:
# line 1222 "c.y"
{
				PARSE_INFO("statement_list :statement_list statement")
			} break;
case 84:
# line 1229 "c.y"
{
				char	lb_else[LABEL_LEN];

				PARSE_INFO("selection_statement :kIF oLP expression ")
				if ( !yypvt[-1].p_symbol )
				{
					yyerror("'if' expression can't be empty");
					user_exit(1);
				}
				// mov	ax,	expression
				gen_mov_value_to_reg(yypvt[-1].p_symbol, "ax");
				// or	ax,	ax
				gen_or("ax", "ax");

				strcpy(lb_else, get_a_label());
				// jz	lab_else
				gen_jump("jz", lb_else);
				push_label(lb_else);
			} break;
case 85:
# line 1249 "c.y"
{
				char	lb_end[LABEL_LEN];

				PARSE_INFO("oRP statement ")
				strcpy(lb_end, get_a_label());
				// jmp lab_end
				gen_jump("jmp", lb_end);
				// lab_else:
				gen_label(pop_label());
				push_label(lb_end);
			} break;
case 86:
# line 1261 "c.y"
{
				PARSE_INFO("else_clause")
				// lab_end:
				gen_label(pop_label());
			} break;
case 87:
# line 1267 "c.y"
{
				symbol	*sw;
				char	lab_start[LABEL_LEN];

				PARSE_INFO("selection_s

⌨️ 快捷键说明

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