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

📄 grammar.tab.c

📁 一个编译器修改的例子
💻 C
📖 第 1 页 / 共 5 页
字号:
    {      if (yyn == 0 || yyn == YYTABLE_NINF)	goto yyerrlab;      yyn = -yyn;      goto yyreduce;    }  if (yyn == YYFINAL)    YYACCEPT;  /* Count tokens shifted since error; after three, turn off error     status.  */  if (yyerrstatus)    yyerrstatus--;  /* Shift the look-ahead token.  */  YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);  /* Discard the shifted token unless it is eof.  */  if (yychar != YYEOF)    yychar = YYEMPTY;  yystate = yyn;  *++yyvsp = yylval;  goto yynewstate;/*-----------------------------------------------------------.| yydefault -- do the default action for the current state.  |`-----------------------------------------------------------*/yydefault:  yyn = yydefact[yystate];  if (yyn == 0)    goto yyerrlab;  goto yyreduce;/*-----------------------------.| yyreduce -- Do a reduction.  |`-----------------------------*/yyreduce:  /* yyn is the number of a rule to reduce with.  */  yylen = yyr2[yyn];  /* If YYLEN is nonzero, implement the default value of the action:     `$$ = $1'.     Otherwise, the following line sets YYVAL to garbage.     This behavior is undocumented and Bison     users should not rely upon it.  Assigning to YYVAL     unconditionally makes the parser a bit smaller, and it avoids a     GCC warning that YYVAL may be used uninitialized.  */  yyval = yyvsp[1-yylen];  YY_REDUCE_PRINT (yyn);  switch (yyn)    {        case 2:#line 128 "grammar.y"    {        /* Initialise the global scope before doing anything else. */	global_scope = new_scope();    ;}    break;  case 3:#line 133 "grammar.y"    {        /* The AST is just a list of declarations, stored in	 * global_declarations. The actual list is created a few rules down,	 * in name_and_argument_list.	 */	global_declarations = (yyvsp[(2) - (2)].list);	/* Finally, leave the global scope when all is done.	 */	leave_scope();    ;}    break;  case 5:#line 153 "grammar.y"    {	(yyval.list) = (yyvsp[(1) - (2)].list);	list_merge((yyval.list), (yyvsp[(2) - (2)].list));    ;}    break;  case 9:#line 177 "grammar.y"    {     leave_scope();     RECORD_DECL((yyvsp[(2) - (5)].decl)).formal_var= (yyvsp[(4) - (5)].list);     (yyval.list)= new_list();     list_append((yyval.list),(yyvsp[(2) - (5)].decl));   ;}    break;  case 10:#line 187 "grammar.y"    {    (yyval.decl)=new_record_declaration((yyvsp[(1) - (1)].token));    if(lookup_in_this_scope(current_scope,(yyvsp[(1) - (1)].token)->name)==0) /*check if record has been declared*/       declare((yyvsp[(1) - (1)].token)->name, (yyval.decl));    else       error((yyvsp[(1) - (1)].token),"%s has been declared", (yyvsp[(1) - (1)].token)->name);    RECORD_DECL((yyval.decl)).formal_var_scope = new_scope(); /* add : create new_scope() for members of record */   ;}    break;  case 11:#line 200 "grammar.y"    {	leave_scope();	/* scope introduced by arguments in			 * name_and_argument_list (through subprogram_header)			 */	(yyval.list) = new_list();	list_append((yyval.list), (yyvsp[(1) - (2)].decl));    ;}    break;  case 12:#line 211 "grammar.y"    {	leave_scope();	/* scope introduced by arguments in			 * name_and_argument_list (through subprogram_header)			 */	SUBPROG_DECL((yyvsp[(1) - (3)].decl)).body = (yyvsp[(3) - (3)].stat);	SUBPROG_DECL((yyvsp[(1) - (3)].decl)).has_been_defined = true;	(yyval.list) = new_list();	list_append((yyval.list), (yyvsp[(1) - (3)].decl));    ;}    break;  case 15:#line 237 "grammar.y"    {	(yyval.decl)			   = (yyvsp[(2) - (4)].decl);	SUBPROG_DECL((yyval.decl)).return_type = (yyvsp[(4) - (4)].type);    ;}    break;  case 16:#line 248 "grammar.y"    {	(yyval.decl) = (yyvsp[(2) - (2)].decl);	SUBPROG_DECL((yyval.decl)).return_type = new_simple_type(void_type);    ;}    break;  case 17:#line 258 "grammar.y"    {	(yyval.decl) = new_subprogram_declaration((yyvsp[(1) - (1)].token));	if ((SUBPROG_DECL((yyval.decl)).redeclaration = lookup_in_this_scope(		current_scope, (yyvsp[(1) - (1)].token)->name)) == 0)	    declare((yyvsp[(1) - (1)].token)->name, (yyval.decl));	SUBPROG_DECL((yyval.decl)).formal_args_scope = new_scope();    ;}    break;  case 18:#line 268 "grammar.y"    {	(yyval.decl)			   = (yyvsp[(2) - (3)].decl);	SUBPROG_DECL((yyval.decl)).formal_args = (yyvsp[(3) - (3)].list);	SUBPROG_DECL((yyval.decl)).type	   = new_subprog_type((yyval.decl));    ;}    break;  case 19:#line 280 "grammar.y"    {	(yyval.list) = new_list();    ;}    break;  case 20:#line 287 "grammar.y"    {	(yyval.list) = (yyvsp[(2) - (3)].list);    ;}    break;  case 22:#line 300 "grammar.y"    {	(yyval.list) = (yyvsp[(1) - (3)].list);	list_merge((yyval.list), (yyvsp[(3) - (3)].list));    ;}    break;  case 24:#line 313 "grammar.y"    {	Declaration *first_var_decl = list_index((yyvsp[(2) - (2)].list), 0);	VAR_DECL(first_var_decl).type->call_by_ref = true; /* ??????*/	(yyval.list) = (yyvsp[(2) - (2)].list);    ;}    break;  case 25:#line 326 "grammar.y"    {	(yyval.list) = (yyvsp[(2) - (2)].list);    ;}    break;  case 27:#line 340 "grammar.y"    {	(yyval.list) = (yyvsp[(1) - (3)].list);	list_merge((yyval.list), (yyvsp[(2) - (3)].list));    ;}    break;  case 28:#line 352 "grammar.y"    {	unsigned i;	for (i = 0; i < list_size((yyvsp[(1) - (3)].list)); i ++)	    VAR_DECL((Declaration *) list_index((yyvsp[(1) - (3)].list), i)).type = (yyvsp[(3) - (3)].type);	inc_ref_count((yyvsp[(3) - (3)].type), i - 1);	(yyval.list) = (yyvsp[(1) - (3)].list);    ;}    break;  case 29:#line 367 "grammar.y"    {	Declaration *decl = new_var_declaration((yyvsp[(1) - (1)].token));	(yyval.list) = new_list();	list_append((yyval.list), decl);	declare((yyvsp[(1) - (1)].token)->name, decl);    ;}    break;  case 30:#line 378 "grammar.y"    {	Declaration *decl = new_var_declaration((yyvsp[(3) - (3)].token));	(yyval.list) = (yyvsp[(1) - (3)].list);	list_append((yyval.list), decl);	declare((yyvsp[(3) - (3)].token)->name, decl);    ;}    break;  case 31:#line 391 "grammar.y"    {	(yyval.type) = new_simple_type(bool_type);    ;}    break;  case 32:#line 396 "grammar.y"    {	(yyval.type) = new_simple_type(char_type);    ;}    break;  case 33:#line 401 "grammar.y"    {	(yyval.type) = new_simple_type(int_type);    ;}    break;  case 34:#line 406 "grammar.y"    {	(yyval.type) = new_simple_type(real_type);    ;}    break;  case 35:#line 411 "grammar.y"    {	(yyval.type) = new_array_type(new_simple_type(char_type));    ;}    break;  case 37:#line 418 "grammar.y"    {      if(lookup_in_this_scope(global_scope,(yyvsp[(1) - (1)].token)->name)==0)        {         error((yyvsp[(1) - (1)].token), "%s hasn't been declared ",(yyvsp[(1) - (1)].token)->name);        }      else         (yyval.type)= new_record_type(lookup_in_this_scope(global_scope,(yyvsp[(1) - (1)].token)->name));    ;}    break;  case 38:#line 434 "grammar.y"    {	(yyval.type) = new_array_type((yyvsp[(3) - (3)].type));    ;}    break;  case 48:#line 468 "grammar.y"    {	(yyval.stat) = new_assignment_statement((yyvsp[(1) - (4)].expr), (yyvsp[(3) - (4)].expr));    ;}    break;  case 49:#line 476 "grammar.y"    {	(yyval.scope) = new_scope();    ;}    break;  case 50:#line 483 "grammar.y"    {	(yyval.stat) = new_compound_statement((yyvsp[(2) - (5)].list), (yyvsp[(4) - (5)].list), (yyvsp[(1) - (5)].scope));	leave_scope();    ;}    break;  case 51:#line 491 "grammar.y"    {	(yyval.stat) = new_compound_statement(new_list(), (yyvsp[(2) - (3)].list), 0);    ;}    break;  case 52:#line 500 "grammar.y"    {	(yyval.list) = new_list();    ;}    break;  case 53:#line 506 "grammar.y"    {	(yyval.list) = (yyvsp[(1) - (2)].list);	list_append((yyval.list), (yyvsp[(2) - (2)].stat));    ;}    break;  case 54:#line 518 "grammar.y"    {	(yyval.stat) = new_delete_statement((yyvsp[(2) - (3)].expr));    ;}    break;  case 55:#line 528 "grammar.y"    {	(yyval.stat) = new_expression_statement((yyvsp[(1) - (2)].expr));    ;}    break;  case 56:#line 545 "grammar.y"    {	(yyval.stat) = new_for_statement((yyvsp[(2) - (9)].expr), (yyvsp[(4) - (9)].expr), (yyvsp[(6) - (9)].expr), (yyvsp[(7) - (9)].expr),				     (yyvsp[(9) - (9)].stat));    ;}    break;  case 57:#line 555 "grammar.y"    {	(yyval.expr) = 0;    ;}    break;  case 58:#line 561 "grammar.y"    {	(yyval.expr) = (yyvsp[(2) - (2)].expr);    ;}    break;  case 59:#line 573 "grammar.y"    {	(yyval.stat) = new_if_statement((yyvsp[(2) - (4)].expr), (yyvsp[(4) - (4)].stat), 0);    ;}    break;  case 60:#line 583 "grammar.y"    {	(yyval.stat) = new_if_statement((yyvsp[(2) - (6)].expr), (yyvsp[(4) - (6)].stat), (yyvsp[(6) - (6)].stat));    ;}    break;  case 61:#line 596 "grammar.y"    {	(yyval.stat) = new_

⌨️ 快捷键说明

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