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

📄 ytab.c

📁 一个小型的c语言编译器,做的非常好,不过不是我做的.
💻 C
📖 第 1 页 / 共 5 页
字号:

# line 11 "c.y"
#include    "Common.h"
#include    "Debug.h"
#include	"Error.h"
#include	"SymTab.h"
#include	"GBStrTab.h"
#include	"GenCode.h"
#include	"stack.h"
#include    <stdio.h>
#include    <stdlib.h>
#include    <string.h>
#include    <assert.h>

extern  char* yytext;

// globe value 
// used by cSTRING , record current string context
char	g_String[MAX_STR_LEN];
const	char _FUNCTION_NAME[] = "func_%s";
const	char _CASE_NAME[] = "_case_";
const	char _DEFAULT_NAME[] = "_default_";
const	char _STRING_NAME[] = "_string_";

#define		IS_CASE(x)		( !strcmp( (x)->name, _CASE_NAME ) )
#define		IS_DEFAULT(x)	( !strcmp( (x)->name, _DEFAULT_NAME ) )

// label buffer for return
static	char	sg_return_label_buf[LABEL_LEN];

// used by function, to add parameter list to compound statement
static	symbol	*sg_parameter_list = NULL;

#define	PARSE_INFO(x)	StrToDebug(x, "\nIn yyparse() : ", "  --- YACC");

void	set_return_label(char *lb);
void	gen_return_label();
void	gen_return_stmt(symbol *x);
char	*get_string_context(char *s);
int		yylex();


# line 52 "c.y"
typedef union 
{
// note : NAME_LEN == 32
	char		p_char[32];
	int			num;
	int			ascii;
	symbol		*p_symbol;
} YYSTYPE;
# define idTYPEDEF 257
# define kFOR 258
# define kWHILE 259
# define kIF 260
# define kELSE 261
# define kCASE 262
# define kSWITCH 263
# define kDEFAULT 264
# define kGOTO 265
# define kRETURN 266
# define kDO 267
# define kBREAK 268
# define kCONTINUE 269
# define kSIZEOF 270
# define kAUTO 271
# define kREGISTER 272
# define kSTATIC 273
# define kEXTERN 274
# define kTYPEDEF 275
# define kINT 276
# define kLONG 277
# define kSHORT 278
# define kCHAR 279
# define kVOID 280
# define kFLOAT 281
# define kDOUBLE 282
# define kSIGNED 283
# define kUNSIGNED 284
# define kCONST 285
# define kVOLATILE 286
# define cSTRING 287
# define cINT 288
# define cREAL 289
# define cCHAR 290
# define oPLUS 291
# define oMINUS 292
# define oMUL 293
# define oDIV 294
# define oMOD 295
# define oEQUAL 296
# define oASSIGN 297
# define oUNEQU 298
# define oLT 299
# define oLE 300
# define oGT 301
# define oGE 302
# define oCOMMA 303
# define oSEMI 304
# define oCOLON 305
# define oQUESTION 306
# define oQUOTE 307
# define oDOTDOTDOT 308
# define oARROW 309
# define oLP 310
# define oRP 311
# define oLB 312
# define oRB 313
# define oLC 314
# define oRC 315
# define oBITOR 316
# define oBITAND 317
# define oBITNOT 318
# define oBITXOR 319
# define oLFTSHT 320
# define oRITSHT 321
# define oOR 322
# define oAND 323
# define oNOT 324
# define oADDADD 325
# define oSUBSUB 326
# define oPLUSASSIGN 327
# define oMINUSASSIGN 328
# define oMULASSIGN 329
# define oDIVASSIGN 330
# define oMODASSIGN 331
# define oBITORASSIGN 332
# define oBITANDASSIGN 333
# define oBITNOTASSIGN 334
# define oBITXORASSIGN 335
# define oLFTSHTASSIGN 336
# define oRITSHTASSIGN 337
# define yNAME 338
# define pINCLUDE 339
# define pINCLDNAME 340
#define yyclearin yychar = -1
#define yyerrok yyerrflag = 0
extern int yychar;
extern int yyerrflag;
#ifndef YYMAXDEPTH
#define YYMAXDEPTH 150
#endif
YYSTYPE yylval, yyval;
typedef int yytabelem;
# define YYERRCODE 256

# line 3309 "c.y"


void	set_return_label(char *lb)
{
	strcpy( sg_return_label_buf, lb);
}

void	gen_return_label()
{
	// return_lab:
	gen_label(sg_return_label_buf);
}

void	gen_return_stmt(symbol *x)
{
	if ( x )
	{
		// mov return value to ax
		gen_mov_value_to_reg(x, "ax");
	}

	// jmp return_lab
	gen_jump("jmp", sg_return_label_buf);
}

char	*get_string_context(char *s)
{
	char	*p = s + 1; // for "

	p[strlen(p) - 1] = '\0';
	return	p;
}

/* End of file */
yytabelem yyexca[] ={
-1, 1,
	0, -1,
	-2, 0,
-1, 33,
	314, 6,
	-2, 39,
-1, 95,
	315, 79,
	-2, 75,
	};
# define YYNPROD 179
# define YYLAST 895
yytabelem yyact[]={

    27,    38,    31,   103,   113,   114,   142,   105,   106,    35,
   104,   221,    50,    73,    13,    14,    15,    17,    16,    18,
    19,    20,    21,    22,    23,    24,    25,    26,    28,    29,
    77,    79,    81,    80,    69,    70,   143,   144,   145,   146,
   147,   148,   149,    31,   150,   151,   152,   139,   121,   202,
   120,   242,   244,    78,    39,   101,   134,   100,   208,   238,
   273,    71,   142,   122,   123,   249,   253,    72,    67,    68,
   207,   102,    44,    31,    43,   226,   241,   232,   172,   170,
   168,    31,   165,   169,   166,   173,   176,   171,   175,   174,
    73,   229,   143,   144,   145,   146,   147,   148,   149,    27,
   150,   151,   152,   228,   202,   224,   237,    77,    79,    81,
    80,    69,    70,    13,    14,    15,    17,    16,    18,    19,
    20,    21,    22,    23,    24,    25,    26,    28,    29,   202,
    78,   202,   202,   202,    50,   247,   286,   290,    71,   282,
   272,   265,   202,   240,    72,    67,    68,   202,   283,   256,
   264,   239,   202,   268,   235,   172,   170,   168,    31,   165,
   169,   166,   173,   176,   171,   175,   174,    73,   234,   202,
   202,   257,   109,   111,   110,   112,    27,   203,   202,   227,
    31,     8,    48,    47,    77,    79,    81,    80,    69,    70,
    13,    14,    15,    17,    16,    18,    19,    20,    21,    22,
    23,    24,    25,    26,    28,    29,   135,    78,   107,   285,
   108,    50,   222,    46,   267,    71,   117,   118,   119,   115,
   116,    72,    67,    68,   156,    85,    63,    59,    88,    58,
    83,    51,   172,   170,   168,    31,   165,   169,   166,   173,
   176,   171,   175,   174,    73,    56,    36,   243,    62,    91,
     4,    55,     2,    27,    32,   291,   287,   274,   231,   277,
   230,    77,    79,    81,    80,    69,    70,    13,    14,    15,
    17,    16,    18,    19,    20,    21,    22,    23,    24,    25,
    26,    28,    29,   271,    78,    73,   284,   280,    50,   270,
    60,   155,    71,    53,    96,    93,    73,   154,    72,    67,
    68,    98,    77,    79,    81,    80,    69,    70,    57,   250,
   262,    97,    31,    77,    79,    81,    80,    69,    70,   141,
   248,    61,   163,   162,   161,    78,   159,   158,   140,    90,
   245,    37,   157,    71,   182,   181,    78,   198,    73,    72,
    67,    68,   191,   192,    71,    45,   153,     5,    73,   179,
    72,    67,    68,    31,   178,    77,    79,    81,    80,    69,
    70,   205,   189,   190,    31,    77,    79,    81,    80,    69,
    70,   206,     1,   197,    54,    66,    74,    76,    78,   220,
    64,     3,    90,   138,   137,    82,    71,    84,    78,    53,
    73,    52,    72,    67,    68,    95,    71,   225,   183,   184,
    73,   160,    72,    67,    68,    34,    31,    77,    79,    81,
    80,    69,    70,   180,    12,    53,    31,    77,    79,    81,
    80,    69,    70,    11,   167,    10,     9,     0,     0,     0,
    78,   185,   186,   187,   188,     0,     0,   246,    71,    49,
   131,   133,     7,     0,    72,    67,    68,    87,    71,    33,
   126,   127,   128,   129,    72,    67,    68,    27,    31,     0,
    75,    30,    30,     0,     0,     0,     0,    30,    31,     0,
     0,    13,    14,    15,    17,    16,    18,    19,    20,    21,
    22,    23,    24,    25,    26,    28,    29,   258,    89,   223,
     0,    94,     0,     0,     0,     0,    27,     0,   193,   194,
   195,     0,     0,   132,     0,     0,     0,     0,   204,    30,
    13,    14,    15,    17,    16,    18,    19,    20,    21,    22,
    23,    24,    25,    26,    28,    29,   177,     6,     0,   136,
     0,     0,    89,     0,     0,     0,     0,    40,    41,    42,
     0,     0,    94,     0,     0,   196,     0,    30,     0,     0,
     0,     0,     0,   223,     0,     0,   132,   164,     0,     0,
    30,     0,     0,   199,   254,     0,     0,     0,     0,     0,
     0,     0,    86,     0,     0,     0,     0,     0,    99,     0,
     0,   261,     0,   263,   209,   210,   211,   212,   213,   214,
   215,   216,   217,   218,   219,   269,     0,     0,     0,     0,
     0,   236,     0,   275,   276,     0,     0,     0,     0,     0,
   281,     0,     0,     0,     0,   164,     0,   164,   288,     0,
     0,     0,     0,    99,   292,     0,     0,     0,     0,     0,
     0,     0,     0,     0,   233,     0,     0,     0,     0,     0,
     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
    89,     0,     0,   251,   252,     0,    92,   255,     0,   201,
     0,     0,     0,    86,     0,     0,     0,     0,     0,     0,
     0,     0,     0,     0,     0,     0,     0,     0,   266,     0,
     0,   164,   259,     0,     0,   260,     0,     0,     0,     0,
     0,     0,   164,     0,     0,     0,     0,     0,   278,   279,
    65,     0,     0,     0,     0,     0,     0,     0,     0,   164,
     0,   164,   289,     0,     0,     0,     0,     0,     0,     0,
     0,     0,     0,   164,   124,   125,    65,    65,    65,    65,
   130,   164,   164,     0,     0,     0,     0,     0,   164,     0,
     0,     0,     0,     0,     0,     0,   164,     0,     0,     0,
     0,     0,   164,     0,     0,     0,     0,     0,     0,    65,
    65,    65,    65,    65,    65,    65,    65,    65,    65,    65,
    65,    65,    65,    65,    65,    65,    65,     0,     0,     0,
     0,     0,     0,     0,     0,     0,     0,     0,   200,     0,
     0,     0,     0,     0,     0,     0,    65,     0,     0,     0,
     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
     0,     0,    65,     0,     0,     0,     0,     0,     0,     0,
     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
     0,     0,     0,     0,    65 };
yytabelem yypact[]={

  -158,  -158, -1000, -1000, -1000, -1000,  -295, -1000,  -286,   239,
   239,   239,  -238, -1000, -1000, -1000, -1000, -1000, -1000, -1000,
 -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000,
 -1000, -1000, -1000,   -84,  -121, -1000, -1000,  -302, -1000, -1000,
 -1000, -1000, -1000,    78,   -81,  -302,    68, -1000,  -336, -1000,
    -4,  -256, -1000, -1000,  -251,  -320,  -306,  -312,  -309,   -88,
  -127,  -316,   -72,   -77, -1000, -1000,  -262,   120,   120,   120,
   120,   120,   120,   130, -1000, -1000, -1000, -1000,   120, -1000,
 -1000, -1000,  -255, -1000,   -97, -1000,  -265, -1000, -1000, -1000,
    68, -1000,  -291, -1000,   -84,   239,   -26, -1000, -1000,  -295,
 -1000,   120,   120,   120,   120,   120,   120,   120,   120,   120,
   120,   120,   120,   120,   120,   120,   120,   120,   120,   120,
   120,    26, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000,
 -1000,  -257,  -134, -1000, -1000,   200, -1000, -1000, -1000,   120,
  -245, -1000,   120,   120,   120,   120,   120,   120,   120,   120,
   120,   120,   120, -1000,   -26,  -304,  -103, -1000, -1000, -1000,
 -1000, -1000, -1000, -1000,  -200,   120,  -230,  -125,  -207,  -219,
 -1000, -1000,  -233,  -336,  -136,  -150,   120,  -199,  -320,  -306,
  -312,  -309,   -88,  -127,  -127,  -316,  -316,  -316,  -316,   -72,
   -72,   -77,   -77, -1000, -1000, -1000,  -254,  -160, -1000, -1000,
  -235,  -260, -1000, -1000, -1000, -1000,  -261, -1000,    15, -1000,
 -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000,
  -180, -1000, -1000, -1000, -1000,  -240, -1000, -1000,   120,   120,
  -244,   -26,   120,  -155, -1000, -1000,  -133,   120, -1000, -1000,
   120, -1000, -1000,   120, -1000, -1000, -1000, -1000,   -26, -1000,
   -26,  -161,  -170,   120,   -45,  -151, -1000, -1000, -1000, -1000,
 -1000, -1000,   -26, -1000, -1000, -1000,  -171,  -250, -1000, -1000,
   -26,   -26, -1000,   120,   120, -1000, -1000,   -26,  -172,  -156,
   -52, -1000,  -168, -1000, -1000,   -26, -1000,   120, -1000,  -174,
 -1000,   -26, -1000 };
yytabelem yypgo[]={

     0,   426,   425,   423,   527,   460,   414,   442,   246,   405,
   250,   395,   225,   387,   385,   384,   383,   228,   381,   377,
   376,   375,   656,   380,   226,   248,   321,   290,   227,   229,
   308,   245,   251,   374,   231,   249,   441,   424,   373,   372,
   252,   347,   345,   401,   331,   328,   332,   327,   326,   324,
   323,   322,   320,   310,   309,   297,   224,   294,   291,   289,
   287,   286,   283,   260,   259,   258,   257,   256,   255,   247 };
yytabelem yyr1[]={

     0,    39,    39,    40,    40,    40,    42,    18,    44,    18,
    10,    10,    11,    11,     4,     4,     4,     4,     4,     4,
     1,     1,     1,     1,     1,     2,     2,     2,     2,     2,
     2,     2,     2,     2,     2,     3,     3,     9,     9,     8,
     8,     7,     6,     6,     6,     6,     6,    14,    14,    13,
    13,    12,    12,    12,    17,    17,    17,    45,    45,    15,
    16,     5,    46,    46,    46,    46,    46,    46,    52,    47,
    53,    47,    54,    47,    48,    55,    43,    57,    43,    58,
    43,    43,    56,    56,    59,    60,    49,    62,    49,    61,
    61,    63,    64,    50,    65,    50,    66,    67,    68,    50,
    51,    51,    51,    51,    37,    69,    37,    37,    36,    36,
    36,    36,    36,    36,    36,    36,    36,    36,    36,    36,
    35,    35,    34,    33,    33,    32,    32,    31,    31,    30,
    30,    29,    29,    28,    28,    28,    27,    27,    27,    27,
    27,    26,    26,    26,    25,    25,    25,    24,    24,    24,
    24,    23,    22,    22,    22,    22,    22,    22,    22,    22,
    22,    22,    21,    21,    21,    21,    21,    21,    20,    20,
    20,    20,    38,    38,    19,    19,    19,    41,    41 };
yytabelem yyr2[]={

     0,     3,     5,     3,     3,     3,     1,     9,     1,     7,
     7,     5,     3,     5,     5,     3,     5,     3,     5,     3,
     3,     3,     3,     3,     3,     3,     3,     3,     3,     3,
     3,     3,     3,     3,     3,     3,     3,     3,     7,     3,
     7,     3,     3,     9,     7,     9,     7,     3,     7,     3,
     7,     5,     5,     3,     3,     7,     9,     3,     7,     3,
     7,     3,     3,     3,     3,     3,     3,     3,     1,     9,
     1,    11,     1,     9,     5,     1,    11,     1,     9,     1,
     9,     5,     3,     5,     1,     1,    17,     1,    13,     5,
     1,     1,     1,    15,     1,    17,     1,     1,     1,    25,
     7,     5,     5,     7,     3,     1,     9,     1,     3,     7,
     7,     7,     7,     7,     7,     7,     7,     7,     7,     7,
     3,    11,     3,     3,     7,     3,     7,     3,     7,     3,
     7,     3,     7,     3,     7,     7,     3,     7,     7,     7,
     7,     3,     7,     7,     3,     7,     7,     3,     7,     7,
     7,     3,     3,     5,     5,     5,     5,     5,     5,     5,
     9,     9,     3,     9,     9,     7,     5,     5,     3,     3,
     3,     7,     3,     7,     3,     3,     3,     5,     5 };
yytabelem yychk[]={

 -1000,   -39,   -40,   -18,   -10,   -41,    -4,    -7,   339,    -1,
    -2,    -3,    -6,   271,   272,   273,   275,   274,   276,   277,
   278,   279,   280,   281,   282,   283,   284,   257,   285,   286,
    -5,   338,   -40,    -7,    -9,   304,    -8,   -44,   287,   340,
    -4,    -4,    -4,   312,   310,   -42,   297,   304,   303,   -43,
   314,   -34,   313,   -35,   -33,   -32,   -31,   -30,   -29,   -28,
   -27,   -26,   -25,   -24,   -23,   -22,   -21,   325,   326,   291,
   292,   318,   324,   270,   -20,    -5,   -19,   287,   310,   288,
   290,   289,   -14,   311,   -13,   -12,    -4,   -43,   -17,   -36,
   314,   -35,   -22,    -8,    -7,   -11,   -57,   315,   -10,    -4,
   313,   306,   322,   323,   316,   319,   317,   296,   298,   299,
   301,   300,   302,   320,   321,   291,   292,   293,   294,   295,
   312,   310,   325,   326,   -22,   -22,   -23,   -23,   -23,   -23,
   -22,   310,   -37,   -36,   311,   303,    -7,   -15,   -16,   312,
   -45,   -17,   297,   327,   328,   329,   330,   331,   332,   333,
   335,   336,   337,   -10,   -55,   -58,   -56,   -46,   -47,   -48,
   -43,   -49,   -50,   -51,    -5,   262,   264,   -37,   260,   263,
   259,   267,   258,   265,   269,   268,   266,   -37,   -32,   -31,
   -30,   -29,   -28,   -27,   -27,   -26,   -26,   -26,   -26,   -25,
   -25,   -24,   -24,   -23,   -23,   -23,   -37,   -38,   311,   -36,
   -22,    -4,   303,   311,   308,   -12,   -34,   315,   303,   -36,
   -36,   -36,   -36,   -36,   -36,   -36,   -36,   -36,   -36,   -36,
   -56,   315,   315,   -46,   305,   -34,   305,   304,   310,   310,
   -63,   -65,   310,    -5,   304,   304,   -37,   305,   313,   311,
   303,   311,   311,   -69,   313,   315,   -17,   315,   -52,   305,
   -54,   -37,   -37,   310,   -46,   -37,   304,   304,   -35,   -36,
   -36,   -46,   -53,   -46,   311,   311,   -37,   259,   304,   -46,
   -59,   -62,   311,   310,   -66,   -46,   -46,   -64,   -37,   -37,
   -60,   -46,   311,   304,   -61,   261,   304,   -67,   -46,   -37,
   311,   -68,   -46 };
yytabelem yydef[]={

     0,    -2,     1,     3,     4,     5,     0,     8,     0,    15,
    17,    19,    41,    20,    21,    22,    23,    24,    25,    26,
    27,    28,    29,    30,    31,    32,    33,    34,    35,    36,
    42,    61,     2,    -2,     0,    11,    37,     0,   177,   178,
    14,    16,    18,     0,     0,     0,     0,    10,     0,     9,
    77,     0,    44,   122,   120,   123,   125,   127,   129,   131,
   133,   136,   141,   144,   147,   151,   152,     0,     0,     0,
     0,     0,     0,     0,   162,   168,   169,   170,   107,   174,
   175,   176,     0,    46,    47,    49,    53,     7,    40,    54,
     0,   108,   151,    38,    39,    -2,   107,    81,    12,     0,
    43,   107,     0,     0,     0,     0,     0,     0,     0,     0,
     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
   107,     0,   166,   167,   153,   154,   155,   156,   157,   158,

⌨️ 快捷键说明

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