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

📄 parse.cpp.bak

📁 完成一个简化的C语言编译程序
💻 BAK
📖 第 1 页 / 共 4 页
字号:
#include <yacc.h>

#line 1 "E:\\MyVC\\compiler\\cscript1\\parse.y"

#include "stdlib.h"
#include "globals.h"
#include "util.h"
#include "scaner.h"
#include "parser.h"   
#define YYSTYPE TreeNode* 
static char* savedName;
static int savedLineNo;
static TreeNode* savedTree; 
int   array_size;
char* current_name;

#line 18 "E:\\MyVC\\compiler\\cscript1\\parse.c"
/* repeated because of possible precompiled header */
#include <yacc.h>

#include "parse.h"

#ifndef YYSTYPE
#define YYSTYPE int
#endif
#ifndef YYSTACK_SIZE
#define YYSTACK_SIZE 100
#endif

/* (state) stack */
#if (YYSTACK_SIZE) != 0
static yystack_t YYNEAR yystack[(YYSTACK_SIZE)];
yystack_t *YYNEAR YYDCDECL yysstackptr = yystack;
yystack_t *YYNEAR YYDCDECL yystackptr = yystack;
#else
yystack_t *YYNEAR YYDCDECL yysstackptr = NULL;
yystack_t *YYNEAR YYDCDECL yystackptr = NULL;
#endif

/* attribute stack */
#if (YYSTACK_SIZE) != 0
static YYSTYPE YYNEAR yyattributestack[(YYSTACK_SIZE)];
#ifdef YYPROTOTYPE
void *YYNEAR YYDCDECL yysattributestackptr = yyattributestack;
void *YYNEAR YYDCDECL yyattributestackptr = yyattributestack;
#else
char *YYNEAR YYDCDECL yysattributestackptr = (char *) yyattributestack;
char *YYNEAR YYDCDECL yyattributestackptr = (char *) yyattributestack;
#endif
#else
#ifdef YYPROTOTYPE
void *YYNEAR YYDCDECL yysattributestackptr = NULL;
void *YYNEAR YYDCDECL yyattributestackptr = NULL;
#else
char *YYNEAR YYDCDECL yysattributestackptr = NULL;
char *YYNEAR YYDCDECL yyattributestackptr = NULL;
#endif
#endif

int YYNEAR YYDCDECL yysstack_size = (YYSTACK_SIZE);
int YYNEAR YYDCDECL yystack_size = (YYSTACK_SIZE);

/* attributes */
YYSTYPE YYNEAR yyval;
YYSTYPE YYNEAR yylval;
#ifdef YYPROTOTYPE
void *YYNEAR YYDCDECL yyvalptr = &yyval;
void *YYNEAR YYDCDECL yylvalptr = &yylval;
#else
char *YYNEAR YYDCDECL yyvalptr = (char *) &yyval;
char *YYNEAR YYDCDECL yylvalptr = (char *) &yylval;
#endif

size_t YYNEAR YYDCDECL yyattribute_size = sizeof(YYSTYPE);

/* yyattribute */
#ifdef YYDEBUG
#ifdef YYPROTOTYPE
static YYSTYPE *yyattribute1(int index)
#else
static YYSTYPE *yyattribute1(index)
int index;
#endif
{
	YYSTYPE *p = &((YYSTYPE *) yyattributestackptr)[yytop + index];
	return p;
}
#define yyattribute(index) (*yyattribute1(index))
#else
#define yyattribute(index) (((YYSTYPE *) yyattributestackptr)[yytop + (index)])
#endif

#ifdef YYDEBUG
#ifdef YYPROTOTYPE
static void yyinitdebug(YYSTYPE **p, int count)
#else
static void yyinitdebug(p, count)
YYSTYPE **p;
int count;
#endif
{
	int i;
	yyassert(p != NULL);
	yyassert(count >= 1);

	for (i = 0; i < count; i++) {
		p[i] = &((YYSTYPE *) yyattributestackptr)[yytop + i - (count - 1)];
	}
}
#endif

#ifdef YYPROTOTYPE
void YYCDECL yyparseaction(int action)
#else
void YYCDECL yyparseaction(action)
int action;
#endif
{
	switch (action) {
	case 0:
		{
#ifdef YYDEBUG
			YYSTYPE *yya[2];
			yyinitdebug(yya, 2);
#endif
			{
#line 29 "E:\\MyVC\\compiler\\cscript1\\parse.y"
 savedTree=yyattribute(1 - 1);
#line 130 "E:\\MyVC\\compiler\\cscript1\\parse.c"
			}
		}
		break;
	case 1:
		{
#ifdef YYDEBUG
			YYSTYPE *yya[3];
			yyinitdebug(yya, 3);
#endif
			{
#line 33 "E:\\MyVC\\compiler\\cscript1\\parse.y"

                      YYSTYPE t=yyattribute(1 - 2);
                      if(t!=NULL)
                      {
                         while(t->sibling!=NULL)
                               t=t->sibling;
                         t->sibling=yyattribute(2 - 2);
                         yyval=yyattribute(1 - 2);      
                      }
                      else 
                          yyval=yyattribute(2 - 2);                  
                    
#line 154 "E:\\MyVC\\compiler\\cscript1\\parse.c"
			}
		}
		break;
	case 2:
		{
#ifdef YYDEBUG
			YYSTYPE *yya[2];
			yyinitdebug(yya, 2);
#endif
			{
#line 45 "E:\\MyVC\\compiler\\cscript1\\parse.y"
yyval=yyattribute(1 - 1);
#line 167 "E:\\MyVC\\compiler\\cscript1\\parse.c"
			}
		}
		break;
	case 3:
		{
#ifdef YYDEBUG
			YYSTYPE *yya[2];
			yyinitdebug(yya, 2);
#endif
			{
#line 49 "E:\\MyVC\\compiler\\cscript1\\parse.y"
yyval=yyattribute(1 - 1);
#line 180 "E:\\MyVC\\compiler\\cscript1\\parse.c"
			}
		}
		break;
	case 4:
		{
#ifdef YYDEBUG
			YYSTYPE *yya[2];
			yyinitdebug(yya, 2);
#endif
			{
#line 51 "E:\\MyVC\\compiler\\cscript1\\parse.y"
yyval=yyattribute(1 - 1);
#line 193 "E:\\MyVC\\compiler\\cscript1\\parse.c"
			}
		}
		break;
	case 5:
		{
#ifdef YYDEBUG
			YYSTYPE *yya[4];
			yyinitdebug(yya, 4);
#endif
			{
#line 55 "E:\\MyVC\\compiler\\cscript1\\parse.y"

                 yyval=newDeclNode(SingleVarK);
                 yyval->type=yyval->type;
                 yyval->attr.name=yyattribute(2 - 3)->attr.name;
                
#line 210 "E:\\MyVC\\compiler\\cscript1\\parse.c"
			}
		}
		break;
	case 6:
		{
#ifdef YYDEBUG
			YYSTYPE *yya[5];
			yyinitdebug(yya, 5);
#endif
			{
#line 61 "E:\\MyVC\\compiler\\cscript1\\parse.y"
array_size=atoi(tokenString);
#line 223 "E:\\MyVC\\compiler\\cscript1\\parse.c"
			}
		}
		break;
	case 7:
		{
#ifdef YYDEBUG
			YYSTYPE *yya[8];
			yyinitdebug(yya, 8);
#endif
			{
#line 62 "E:\\MyVC\\compiler\\cscript1\\parse.y"

                 yyval = newDeclNode(ArrayVarK);
                 yyval->type=yyval->type;
                 yyval->attr.name=yyattribute(2 - 7)->attr.name;
                 yyval->array_size=array_size;
                
#line 241 "E:\\MyVC\\compiler\\cscript1\\parse.c"
			}
		}
		break;
	case 8:
		{
#ifdef YYDEBUG
			YYSTYPE *yya[2];
			yyinitdebug(yya, 2);
#endif
			{
#line 71 "E:\\MyVC\\compiler\\cscript1\\parse.y"

				 yyval=newExpNode(IdK);
				 yyval->type=Integer;
				 
#line 257 "E:\\MyVC\\compiler\\cscript1\\parse.c"
			}
		}
		break;
	case 9:
		{
#ifdef YYDEBUG
			YYSTYPE *yya[2];
			yyinitdebug(yya, 2);
#endif
			{
#line 76 "E:\\MyVC\\compiler\\cscript1\\parse.y"

				 yyval=newExpNode(IdK);
				 yyval->type=Char;
				 
#line 273 "E:\\MyVC\\compiler\\cscript1\\parse.c"
			}
		}
		break;
	case 10:
		{
#ifdef YYDEBUG
			YYSTYPE *yya[2];
			yyinitdebug(yya, 2);
#endif
			{
#line 81 "E:\\MyVC\\compiler\\cscript1\\parse.y"

				 yyval=newExpNode(IdK);
				 yyval->type=Float;
				 
#line 289 "E:\\MyVC\\compiler\\cscript1\\parse.c"
			}
		}
		break;
	case 11:
		{
#ifdef YYDEBUG
			YYSTYPE *yya[2];
			yyinitdebug(yya, 2);
#endif
			{
#line 86 "E:\\MyVC\\compiler\\cscript1\\parse.y"

				 yyval=newExpNode(IdK);
				 yyval->type=Void;
				 
#line 305 "E:\\MyVC\\compiler\\cscript1\\parse.c"
			}
		}
		break;
	case 12:
		{
#ifdef YYDEBUG
			YYSTYPE *yya[2];
			yyinitdebug(yya, 2);
#endif
			{
#line 93 "E:\\MyVC\\compiler\\cscript1\\parse.y"

				  yyval=newExpNode(IdK);
				  yyval->attr.name=copyString(tokenString);
				 
#line 321 "E:\\MyVC\\compiler\\cscript1\\parse.c"
			}
		}
		break;
	case 13:
		{
#ifdef YYDEBUG
			YYSTYPE *yya[7];
			yyinitdebug(yya, 7);
#endif
			{
#line 100 "E:\\MyVC\\compiler\\cscript1\\parse.y"
 
                  yyval=newDeclNode(FuncVarK);
                  yyval->type=yyval->type;
                  yyval->attr.name=yyattribute(2 - 6)->attr.name;
                  yyval->child[0]=yyattribute(4 - 6);
                  yyval->child[1]=yyattribute(6 - 6);
                  
                
#line 341 "E:\\MyVC\\compiler\\cscript1\\parse.c"
			}
		}
		break;
	case 14:
		{
#ifdef YYDEBUG
			YYSTYPE *yya[7];
			yyinitdebug(yya, 7);
#endif
			{
#line 109 "E:\\MyVC\\compiler\\cscript1\\parse.y"

                        yyval = newDeclNode(FuncVarK);
                        yyval->type = yyval->type;
						yyval->attr.name=yyattribute(2 - 6)->attr.name;
                        yyval->child[1] = yyattribute(6 - 6);
                
#line 359 "E:\\MyVC\\compiler\\cscript1\\parse.c"
			}
		}
		break;
	case 15:
		{
#ifdef YYDEBUG
			YYSTYPE *yya[6];
			yyinitdebug(yya, 6);
#endif
			{
#line 116 "E:\\MyVC\\compiler\\cscript1\\parse.y"

                        yyval = newDeclNode(FuncVarK);
                        yyval->type = yyval->type;
						yyval->attr.name=yyattribute(2 - 5)->attr.name;
                        yyval->child[1] = yyattribute(5 - 5);
                
#line 377 "E:\\MyVC\\compiler\\cscript1\\parse.c"
			}
		}
		break;
	case 16:
		{
#ifdef YYDEBUG
			YYSTYPE *yya[2];
			yyinitdebug(yya, 2);
#endif
			{
#line 125 "E:\\MyVC\\compiler\\cscript1\\parse.y"
 yyval=yyattribute(1 - 1);
#line 390 "E:\\MyVC\\compiler\\cscript1\\parse.c"
			}
		}
		break;
	case 17:
		{
#ifdef YYDEBUG
			YYSTYPE *yya[4];
			yyinitdebug(yya, 4);
#endif
			{
#line 129 "E:\\MyVC\\compiler\\cscript1\\parse.y"

                   YYSTYPE t=yyattribute(1 - 3);
                   if(t!=NULL)
                   {
                        while(t->sibling!=NULL)
                          t=t->sibling;
                        t->sibling=yyattribute(3 - 3);
                        yyval=yyattribute(1 - 3);
                   }
                   else
                         yyval=yyattribute(3 - 3);
                 
#line 414 "E:\\MyVC\\compiler\\cscript1\\parse.c"
			}
		}
		break;
	case 18:
		{
#ifdef YYDEBUG
			YYSTYPE *yya[2];
			yyinitdebug(yya, 2);
#endif
			{
#line 142 "E:\\MyVC\\compiler\\cscript1\\parse.y"
yyval=yyattribute(1 - 1);
#line 427 "E:\\MyVC\\compiler\\cscript1\\parse.c"
			}
		}
		break;
	case 19:
		{
#ifdef YYDEBUG
			YYSTYPE *yya[3];
			yyinitdebug(yya, 3);
#endif
			{
#line 146 "E:\\MyVC\\compiler\\cscript1\\parse.y"

                  yyval=newDeclNode(SingleVarK);
                  yyval->attr.name=yyattribute(2 - 2)->attr.name;
                  yyval->type=yyval->type;
                  
#line 444 "E:\\MyVC\\compiler\\cscript1\\parse.c"
			}
		}
		break;
	case 20:
		{
#ifdef YYDEBUG
			YYSTYPE *yya[5];
			yyinitdebug(yya, 5);
#endif
			{
#line 152 "E:\\MyVC\\compiler\\cscript1\\parse.y"

                  yyval=newDeclNode(ArrayVarK);
                  yyval->attr.name=yyattribute(2 - 4)->attr.name;
                  yyval->type=yyval->type;
                  yyval->array_size=0;
                  
#line 462 "E:\\MyVC\\compiler\\cscript1\\parse.c"
			}
		}
		break;
	case 21:
		{
#ifdef YYDEBUG
			YYSTYPE *yya[4];
			yyinitdebug(yya, 4);
#endif
			{
#line 161 "E:\\MyVC\\compiler\\cscript1\\parse.y"

                        yyval = newStmtNode(CompoundK);
                        yyval->child[0] = yyattribute(2 - 3);
                      
#line 478 "E:\\MyVC\\compiler\\cscript1\\parse.c"
			}
		}
		break;
	case 22:
		{
#ifdef YYDEBUG
			YYSTYPE *yya[5];
			yyinitdebug(yya, 5);
#endif
			{
#line 166 "E:\\MyVC\\compiler\\cscript1\\parse.y"

                        YYSTYPE t = yyattribute(2 - 4);
                        if (t != NULL)
                        { 
                          while (t->sibling != NULL)
                            t = t->sibling;
                          t->sibling = yyattribute(3 - 4);
                          yyval = newStmtNode(CompoundK);
                          yyval->child[0] = yyattribute(2 - 4);
                        }
                        else 
                        {
                          yyval = newStmtNode(CompoundK);

⌨️ 快捷键说明

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