www.pudn.com > lab3.rar > lab3.tab.c


 
/*  A Bison parser, made from lab3.y 
    by GNU Bison version 1.28  */ 
 
#define YYBISON 1  /* Identify Bison output.  */ 
 
#define	IF	257 
#define	ELSE	258 
#define	WHILE	259 
#define	RETURN	260 
#define	VOID	261 
#define	INT	262 
#define	CHAR	263 
#define	ID	264 
#define	NUM	265 
#define	NE	266 
#define	LT	267 
#define	LE	268 
#define	EQ	269 
#define	GT	270 
#define	GE	271 
#define	ADDOP	272 
#define	CHAR_LITERAL	273 
#define	STRING_LITERAL	274 
#define	CDECL	275 
#define	STDCALL	276 
#define	ELLIPSIS	277 
#define	IFX	278 
 
#line 1 "lab3.y" 
 
#include "lab3.h" 
 
#define YYERROR_VERBOSE 1 
 
tablelen = 0; 
level = 0; 
right = 1; 
typecount = 0; 
typecheck = 0; 
 
#line 13 "lab3.y" 
typedef union { 
    char *id;             /* identifier */ 
    int  value;           /* value */ 
    char op[3];           /* operator */ 
    symbol *sign;         /* symbol */ 
    expr expn;            /* expression */ 
} YYSTYPE; 
#include  
 
#ifndef __cplusplus 
#ifndef __STDC__ 
#define const 
#endif 
#endif 
 
 
 
#define	YYFINAL		129 
#define	YYFLAG		-32768 
#define	YYNTBASE	39 
 
#define YYTRANSLATE(x) ((unsigned)(x) <= 278 ? yytranslate[x] : 72) 
 
static const char yytranslate[] = {     0, 
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2, 
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2, 
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2, 
     2,     2,     2,     2,     2,     2,    36,     2,     2,    31, 
    32,    26,    37,    33,    38,     2,    27,     2,     2,     2, 
     2,     2,     2,     2,     2,     2,     2,     2,    28,     2, 
    25,     2,     2,     2,     2,     2,     2,     2,     2,     2, 
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2, 
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2, 
    29,     2,    30,     2,     2,     2,     2,     2,     2,     2, 
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2, 
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2, 
     2,     2,    34,     2,    35,     2,     2,     2,     2,     2, 
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2, 
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2, 
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2, 
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2, 
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2, 
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2, 
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2, 
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2, 
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2, 
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2, 
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2, 
     2,     2,     2,     2,     2,     2,     2,     2,     2,     2, 
     2,     2,     2,     2,     2,     1,     3,     4,     5,     6, 
     7,     8,     9,    10,    11,    12,    13,    14,    15,    16, 
    17,    18,    19,    20,    21,    22,    23,    24 
}; 
 
#if YYDEBUG != 0 
static const short yyprhs[] = {     0, 
     0,     1,     4,     7,     9,    11,    13,    17,    24,    29, 
    37,    39,    41,    43,    46,    49,    56,    62,    64,    66, 
    70,    72,    75,    79,    84,    86,    91,    94,    95,    98, 
    99,   101,   103,   105,   107,   109,   112,   114,   120,   128, 
   134,   137,   141,   145,   147,   149,   154,   158,   160,   162, 
   164,   166,   168,   170,   172,   176,   178,   182,   184,   186, 
   188,   190,   193,   195,   197,   199,   203,   205,   207,   209, 
   211,   213,   218,   220,   221,   225,   227,   229 
}; 
 
static const short yyrhs[] = {    -1, 
    40,    41,     0,    41,    42,     0,    42,     0,    43,     0, 
    45,     0,    44,    10,    28,     0,    44,    10,    29,    11, 
    30,    28,     0,    44,    26,    10,    28,     0,    44,    26, 
    10,    29,    11,    30,    28,     0,     8,     0,     7,     0, 
     9,     0,    46,    50,     0,    46,    28,     0,    44,    71, 
    10,    31,    47,    32,     0,    44,    10,    31,    47,    32, 
     0,    48,     0,     7,     0,    48,    33,    49,     0,    49, 
     0,    44,    10,     0,    44,    26,    10,     0,    44,    10, 
    29,    30,     0,    23,     0,    34,    51,    52,    35,     0, 
    51,    43,     0,     0,    52,    53,     0,     0,    54,     0, 
    50,     0,    55,     0,    56,     0,    57,     0,    58,    28, 
     0,    28,     0,     3,    31,    58,    32,    53,     0,     3, 
    31,    58,    32,    53,     4,    53,     0,     5,    31,    58, 
    32,    53,     0,     6,    28,     0,     6,    58,    28,     0, 
    59,    25,    58,     0,    60,     0,    10,     0,    10,    29, 
    58,    30,     0,    62,    61,    62,     0,    62,     0,    14, 
     0,    13,     0,    16,     0,    17,     0,    15,     0,    12, 
     0,    62,    18,    63,     0,    63,     0,    63,    64,    65, 
     0,    65,     0,    26,     0,    27,     0,    36,     0,    66, 
    65,     0,    67,     0,    37,     0,    38,     0,    31,    58, 
    32,     0,    59,     0,    68,     0,    11,     0,    19,     0, 
    20,     0,    10,    31,    69,    32,     0,    70,     0,     0, 
    70,    33,    58,     0,    58,     0,    21,     0,    22,     0 
}; 
 
#endif 
 
#if YYDEBUG != 0 
static const short yyrline[] = { 0, 
    50,    69,    76,    82,    90,    96,   104,   118,   132,   146, 
   162,   169,   176,   185,   193,   203,   222,   243,   249,   266, 
   272,   280,   307,   334,   361,   378,   386,   392,   395,   401, 
   404,   410,   416,   422,   428,   436,   442,   450,   456,   464, 
   472,   478,   486,   499,   508,   519,   532,   586,   595,   601, 
   607,   613,   619,   625,   633,   655,   664,   688,   697,   704, 
   711,   720,   738,   747,   754,   763,   770,   780,   787,   795, 
   803,   813,   833,   839,   842,   857,   874,   880 
}; 
#endif 
 
 
#if YYDEBUG != 0 || defined (YYERROR_VERBOSE) 
 
static const char * const yytname[] = {   "$","error","$undefined.","IF","ELSE", 
"WHILE","RETURN","VOID","INT","CHAR","ID","NUM","NE","LT","LE","EQ","GT","GE", 
"ADDOP","CHAR_LITERAL","STRING_LITERAL","CDECL","STDCALL","ELLIPSIS","IFX","'='", 
"'*'","'/'","';'","'['","']'","'('","')'","','","'{'","'}'","'%'","'+'","'-'", 
"program","@1","declaration_list","declaration","var_declaration","type_specifer", 
"fun_declaration","fun_tag","params","param_list","param","compound_stmt","local_declarations", 
"statement_list","statement","expression_stmt","if_stmt","while_stmt","return_stmt", 
"expression","var","simple_expression","relop","additive_expression","term", 
"mulop","unary_expression","unaryop","factor","call","args","arg_list","calling_convention", NULL 
}; 
#endif 
 
static const short yyr1[] = {     0, 
    40,    39,    41,    41,    42,    42,    43,    43,    43,    43, 
    44,    44,    44,    45,    45,    46,    46,    47,    47,    48, 
    48,    49,    49,    49,    49,    50,    51,    51,    52,    52, 
    53,    53,    53,    53,    53,    54,    54,    55,    55,    56, 
    57,    57,    58,    58,    59,    59,    60,    60,    61,    61, 
    61,    61,    61,    61,    62,    62,    63,    63,    64,    64, 
    64,    65,    65,    66,    66,    67,    67,    67,    67,    67, 
    67,    68,    69,    69,    70,    70,    71,    71 
}; 
 
static const short yyr2[] = {     0, 
     0,     2,     2,     1,     1,     1,     3,     6,     4,     7, 
     1,     1,     1,     2,     2,     6,     5,     1,     1,     3, 
     1,     2,     3,     4,     1,     4,     2,     0,     2,     0, 
     1,     1,     1,     1,     1,     2,     1,     5,     7,     5, 
     2,     3,     3,     1,     1,     4,     3,     1,     1,     1, 
     1,     1,     1,     1,     3,     1,     3,     1,     1,     1, 
     1,     2,     1,     1,     1,     3,     1,     1,     1,     1, 
     1,     4,     1,     0,     3,     1,     1,     1 
}; 
 
static const short yydefact[] = {     1, 
     0,    12,    11,    13,     2,     4,     5,     0,     6,     0, 
     3,     0,    77,    78,     0,     0,    15,    28,    14,     7, 
     0,     0,     0,     0,    30,     0,    12,    25,     0,     0, 
    18,    21,     9,     0,     0,    27,     0,     0,     0,    22, 
     0,    17,     0,     0,     0,     0,     0,     0,     0,    45, 
    69,    70,    71,    37,     0,    26,    64,    65,    32,    29, 
    31,    33,    34,    35,     0,    67,    44,    48,    56,    58, 
     0,    63,    68,     8,     0,    23,    20,     0,    16,     0, 
     0,    41,     0,     0,    74,     0,    36,     0,    54,    50, 
    49,    53,    51,    52,     0,     0,    59,    60,    61,     0, 
    67,    62,    24,    10,     0,     0,    42,     0,    76,     0, 
    73,    66,    43,    55,    47,    57,     0,     0,    46,    72, 
     0,    38,    40,    75,     0,    39,     0,     0,     0 
}; 
 
static const short yydefgoto[] = {   127, 
     1,     5,     6,     7,    29,     9,    10,    30,    31,    32, 
    59,    25,    38,    60,    61,    62,    63,    64,    65,    66, 
    67,    96,    68,    69,   100,    70,    71,    72,    73,   110, 
   111,    16 
}; 
 
static const short yypact[] = {-32768, 
    89,-32768,-32768,-32768,    89,-32768,-32768,    -8,-32768,    61, 
-32768,    62,-32768,-32768,     5,    36,-32768,-32768,-32768,-32768, 
    38,    15,    -9,    34,    89,    37,    56,-32768,    -5,    60, 
    41,-32768,-32768,    58,    15,-32768,    32,     6,    81,    82, 
   100,-32768,    76,    83,    80,    79,    84,    85,    40,   -21, 
-32768,-32768,-32768,-32768,    44,-32768,-32768,-32768,-32768,-32768, 
-32768,-32768,-32768,-32768,    86,    92,-32768,    88,    30,-32768, 
    44,-32768,-32768,-32768,    90,-32768,-32768,    91,-32768,    44, 
    44,-32768,    93,    44,    44,    94,-32768,    44,-32768,-32768, 
-32768,-32768,-32768,-32768,    44,    44,-32768,-32768,-32768,    44, 
-32768,-32768,-32768,-32768,    95,    96,-32768,    99,-32768,    98, 
   101,-32768,-32768,    30,   104,-32768,    42,    42,-32768,-32768, 
    44,   114,-32768,-32768,    42,-32768,   123,   124,-32768 
}; 
 
static const short yypgoto[] = {-32768, 
-32768,-32768,   120,   106,     2,-32768,-32768,    97,-32768,   102, 
   125,-32768,-32768,   -31,-32768,-32768,-32768,-32768,   -49,   -67, 
-32768,-32768,    43,    45,-32768,   -70,-32768,-32768,-32768,-32768, 
-32768,-32768 
}; 
 
 
#define	YYLAST		145 
 
 
static const short yytable[] = {    83, 
   102,    12,     8,   101,    40,    86,     8,    84,    47,    85, 
    48,    49,    13,    14,    23,    50,    51,    15,    33,    34, 
    41,    27,     3,     4,    52,    53,    37,   101,   101,   116, 
   105,   106,   101,    54,   108,   109,    55,    28,   113,    18, 
    56,    46,    57,    58,    47,    24,    48,    49,    26,    50, 
    51,    50,    51,    50,    51,    97,    98,    15,    52,    53, 
    52,    53,    52,    53,    35,    99,    39,    82,    44,    54, 
    55,   124,    55,    43,    55,    18,    57,    58,    57,    58, 
    57,    58,     2,     3,     4,   122,   123,   -19,    17,    20, 
    21,    42,    22,   126,    18,     2,     3,     4,    28,    89, 
    90,    91,    92,    93,    94,    95,    20,    21,    74,    76, 
    75,    79,    78,    87,    80,    81,    88,   125,   104,   103, 
   107,    95,   128,   129,    11,   112,   117,   118,   119,   120, 
    36,    45,     0,   121,    19,     0,     0,     0,   115,   114, 
     0,     0,     0,     0,    77 
}; 
 
static const short yycheck[] = {    49, 
    71,    10,     1,    71,    10,    55,     5,    29,     3,    31, 
     5,     6,    21,    22,    10,    10,    11,    26,    28,    29, 
    26,     7,     8,     9,    19,    20,    25,    95,    96,   100, 
    80,    81,   100,    28,    84,    85,    31,    23,    88,    34, 
    35,    10,    37,    38,     3,    10,     5,     6,    11,    10, 
    11,    10,    11,    10,    11,    26,    27,    26,    19,    20, 
    19,    20,    19,    20,    31,    36,    30,    28,    11,    28, 
    31,   121,    31,    33,    31,    34,    37,    38,    37,    38, 
    37,    38,     7,     8,     9,   117,   118,    32,    28,    28, 
    29,    32,    31,   125,    34,     7,     8,     9,    23,    12, 
    13,    14,    15,    16,    17,    18,    28,    29,    28,    10, 
    29,    32,    30,    28,    31,    31,    25,     4,    28,    30, 
    28,    18,     0,     0,     5,    32,    32,    32,    30,    32, 
    25,    35,    -1,    33,    10,    -1,    -1,    -1,    96,    95, 
    -1,    -1,    -1,    -1,    43 
}; 
/* -*-C-*-  Note some compilers choke on comments on `#line' lines.  */ 
#line 3 "/usr/local/share/bison.simple" 
/* This file comes from bison-1.28.  */ 
 
/* Skeleton output parser for bison, 
   Copyright (C) 1984, 1989, 1990 Free Software Foundation, Inc. 
 
   This program is free software; you can redistribute it and/or modify 
   it under the terms of the GNU General Public License as published by 
   the Free Software Foundation; either version 2, or (at your option) 
   any later version. 
 
   This program is distributed in the hope that it will be useful, 
   but WITHOUT ANY WARRANTY; without even the implied warranty of 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
   GNU General Public License for more details. 
 
   You should have received a copy of the GNU General Public License 
   along with this program; if not, write to the Free Software 
   Foundation, Inc., 59 Temple Place - Suite 330, 
   Boston, MA 02111-1307, USA.  */ 
 
/* As a special exception, when this file is copied by Bison into a 
   Bison output file, you may use that output file without restriction. 
   This special exception was added by the Free Software Foundation 
   in version 1.24 of Bison.  */ 
 
/* This is the parser code that is written into each bison parser 
  when the %semantic_parser declaration is not specified in the grammar. 
  It was written by Richard Stallman by simplifying the hairy parser 
  used when %semantic_parser is specified.  */ 
 
#ifndef YYSTACK_USE_ALLOCA 
#ifdef alloca 
#define YYSTACK_USE_ALLOCA 
#else /* alloca not defined */ 
#ifdef __GNUC__ 
#define YYSTACK_USE_ALLOCA 
#define alloca __builtin_alloca 
#else /* not GNU C.  */ 
#if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi) || (defined (__sun) && defined (__i386)) 
#define YYSTACK_USE_ALLOCA 
#include  
#else /* not sparc */ 
/* We think this test detects Watcom and Microsoft C.  */ 
/* This used to test MSDOS, but that is a bad idea 
   since that symbol is in the user namespace.  */ 
#if (defined (_MSDOS) || defined (_MSDOS_)) && !defined (__TURBOC__) 
#if 0 /* No need for malloc.h, which pollutes the namespace; 
	 instead, just don't use alloca.  */ 
#include  
#endif 
#else /* not MSDOS, or __TURBOC__ */ 
#if defined(_AIX) 
/* I don't know what this was needed for, but it pollutes the namespace. 
   So I turned it off.   rms, 2 May 1997.  */ 
/* #include   */ 
 #pragma alloca 
#define YYSTACK_USE_ALLOCA 
#else /* not MSDOS, or __TURBOC__, or _AIX */ 
#if 0 
#ifdef __hpux /* haible@ilog.fr says this works for HPUX 9.05 and up, 
		 and on HPUX 10.  Eventually we can turn this on.  */ 
#define YYSTACK_USE_ALLOCA 
#define alloca __builtin_alloca 
#endif /* __hpux */ 
#endif 
#endif /* not _AIX */ 
#endif /* not MSDOS, or __TURBOC__ */ 
#endif /* not sparc */ 
#endif /* not GNU C */ 
#endif /* alloca not defined */ 
#endif /* YYSTACK_USE_ALLOCA not defined */ 
 
#ifdef YYSTACK_USE_ALLOCA 
#define YYSTACK_ALLOC alloca 
#else 
#define YYSTACK_ALLOC malloc 
#endif 
 
/* Note: there must be only one dollar sign in this file. 
   It is replaced by the list of actions, each action 
   as one case of the switch.  */ 
 
#define yyerrok		(yyerrstatus = 0) 
#define yyclearin	(yychar = YYEMPTY) 
#define YYEMPTY		-2 
#define YYEOF		0 
#define YYACCEPT	goto yyacceptlab 
#define YYABORT 	goto yyabortlab 
#define YYERROR		goto yyerrlab1 
/* Like YYERROR except do call yyerror. 
   This remains here temporarily to ease the 
   transition to the new meaning of YYERROR, for GCC. 
   Once GCC version 2 has supplanted version 1, this can go.  */ 
#define YYFAIL		goto yyerrlab 
#define YYRECOVERING()  (!!yyerrstatus) 
#define YYBACKUP(token, value) \ 
do								\ 
  if (yychar == YYEMPTY && yylen == 1)				\ 
    { yychar = (token), yylval = (value);			\ 
      yychar1 = YYTRANSLATE (yychar);				\ 
      YYPOPSTACK;						\ 
      goto yybackup;						\ 
    }								\ 
  else								\ 
    { yyerror ("syntax error: cannot back up"); YYERROR; }	\ 
while (0) 
 
#define YYTERROR	1 
#define YYERRCODE	256 
 
#ifndef YYPURE 
#define YYLEX		yylex() 
#endif 
 
#ifdef YYPURE 
#ifdef YYLSP_NEEDED 
#ifdef YYLEX_PARAM 
#define YYLEX		yylex(&yylval, &yylloc, YYLEX_PARAM) 
#else 
#define YYLEX		yylex(&yylval, &yylloc) 
#endif 
#else /* not YYLSP_NEEDED */ 
#ifdef YYLEX_PARAM 
#define YYLEX		yylex(&yylval, YYLEX_PARAM) 
#else 
#define YYLEX		yylex(&yylval) 
#endif 
#endif /* not YYLSP_NEEDED */ 
#endif 
 
/* If nonreentrant, generate the variables here */ 
 
#ifndef YYPURE 
 
int	yychar;			/*  the lookahead symbol		*/ 
YYSTYPE	yylval;			/*  the semantic value of the		*/ 
				/*  lookahead symbol			*/ 
 
#ifdef YYLSP_NEEDED 
YYLTYPE yylloc;			/*  location data for the lookahead	*/ 
				/*  symbol				*/ 
#endif 
 
int yynerrs;			/*  number of parse errors so far       */ 
#endif  /* not YYPURE */ 
 
#if YYDEBUG != 0 
int yydebug;			/*  nonzero means print parse trace	*/ 
/* Since this is uninitialized, it does not stop multiple parsers 
   from coexisting.  */ 
#endif 
 
/*  YYINITDEPTH indicates the initial size of the parser's stacks	*/ 
 
#ifndef	YYINITDEPTH 
#define YYINITDEPTH 200 
#endif 
 
/*  YYMAXDEPTH is the maximum size the stacks can grow to 
    (effective only if the built-in stack extension method is used).  */ 
 
#if YYMAXDEPTH == 0 
#undef YYMAXDEPTH 
#endif 
 
#ifndef YYMAXDEPTH 
#define YYMAXDEPTH 10000 
#endif 
 
/* Define __yy_memcpy.  Note that the size argument 
   should be passed with type unsigned int, because that is what the non-GCC 
   definitions require.  With GCC, __builtin_memcpy takes an arg 
   of type size_t, but it can handle unsigned int.  */ 
 
#if __GNUC__ > 1		/* GNU C and GNU C++ define this.  */ 
#define __yy_memcpy(TO,FROM,COUNT)	__builtin_memcpy(TO,FROM,COUNT) 
#else				/* not GNU C or C++ */ 
#ifndef __cplusplus 
 
/* This is the most reliable way to avoid incompatibilities 
   in available built-in functions on various systems.  */ 
static void 
__yy_memcpy (to, from, count) 
     char *to; 
     char *from; 
     unsigned int count; 
{ 
  register char *f = from; 
  register char *t = to; 
  register int i = count; 
 
  while (i-- > 0) 
    *t++ = *f++; 
} 
 
#else /* __cplusplus */ 
 
/* This is the most reliable way to avoid incompatibilities 
   in available built-in functions on various systems.  */ 
static void 
__yy_memcpy (char *to, char *from, unsigned int count) 
{ 
  register char *t = to; 
  register char *f = from; 
  register int i = count; 
 
  while (i-- > 0) 
    *t++ = *f++; 
} 
 
#endif 
#endif 
 
#line 217 "/usr/local/share/bison.simple" 
 
/* The user can define YYPARSE_PARAM as the name of an argument to be passed 
   into yyparse.  The argument should have type void *. 
   It should actually point to an object. 
   Grammar actions can access the variable by casting it 
   to the proper pointer type.  */ 
 
#ifdef YYPARSE_PARAM 
#ifdef __cplusplus 
#define YYPARSE_PARAM_ARG void *YYPARSE_PARAM 
#define YYPARSE_PARAM_DECL 
#else /* not __cplusplus */ 
#define YYPARSE_PARAM_ARG YYPARSE_PARAM 
#define YYPARSE_PARAM_DECL void *YYPARSE_PARAM; 
#endif /* not __cplusplus */ 
#else /* not YYPARSE_PARAM */ 
#define YYPARSE_PARAM_ARG 
#define YYPARSE_PARAM_DECL 
#endif /* not YYPARSE_PARAM */ 
 
/* Prevent warning if -Wstrict-prototypes.  */ 
#ifdef __GNUC__ 
#ifdef YYPARSE_PARAM 
int yyparse (void *); 
#else 
int yyparse (void); 
#endif 
#endif 
 
int 
yyparse(YYPARSE_PARAM_ARG) 
     YYPARSE_PARAM_DECL 
{ 
  register int yystate; 
  register int yyn; 
  register short *yyssp; 
  register YYSTYPE *yyvsp; 
  int yyerrstatus;	/*  number of tokens to shift before error messages enabled */ 
  int yychar1 = 0;		/*  lookahead token as an internal (translated) token number */ 
 
  short	yyssa[YYINITDEPTH];	/*  the state stack			*/ 
  YYSTYPE yyvsa[YYINITDEPTH];	/*  the semantic value stack		*/ 
 
  short *yyss = yyssa;		/*  refer to the stacks thru separate pointers */ 
  YYSTYPE *yyvs = yyvsa;	/*  to allow yyoverflow to reallocate them elsewhere */ 
 
#ifdef YYLSP_NEEDED 
  YYLTYPE yylsa[YYINITDEPTH];	/*  the location stack			*/ 
  YYLTYPE *yyls = yylsa; 
  YYLTYPE *yylsp; 
 
#define YYPOPSTACK   (yyvsp--, yyssp--, yylsp--) 
#else 
#define YYPOPSTACK   (yyvsp--, yyssp--) 
#endif 
 
  int yystacksize = YYINITDEPTH; 
  int yyfree_stacks = 0; 
 
#ifdef YYPURE 
  int yychar; 
  YYSTYPE yylval; 
  int yynerrs; 
#ifdef YYLSP_NEEDED 
  YYLTYPE yylloc; 
#endif 
#endif 
 
  YYSTYPE yyval;		/*  the variable used to return		*/ 
				/*  semantic values from the action	*/ 
				/*  routines				*/ 
 
  int yylen; 
 
#if YYDEBUG != 0 
  if (yydebug) 
    fprintf(stderr, "Starting parse\n"); 
#endif 
 
  yystate = 0; 
  yyerrstatus = 0; 
  yynerrs = 0; 
  yychar = YYEMPTY;		/* Cause a token to be read.  */ 
 
  /* Initialize stack pointers. 
     Waste one element of value and location stack 
     so that they stay on the same level as the state stack. 
     The wasted elements are never initialized.  */ 
 
  yyssp = yyss - 1; 
  yyvsp = yyvs; 
#ifdef YYLSP_NEEDED 
  yylsp = yyls; 
#endif 
 
/* Push a new state, which is found in  yystate  .  */ 
/* In all cases, when you get here, the value and location stacks 
   have just been pushed. so pushing a state here evens the stacks.  */ 
yynewstate: 
 
  *++yyssp = yystate; 
 
  if (yyssp >= yyss + yystacksize - 1) 
    { 
      /* Give user a chance to reallocate the stack */ 
      /* Use copies of these so that the &'s don't force the real ones into memory. */ 
      YYSTYPE *yyvs1 = yyvs; 
      short *yyss1 = yyss; 
#ifdef YYLSP_NEEDED 
      YYLTYPE *yyls1 = yyls; 
#endif 
 
      /* Get the current used size of the three stacks, in elements.  */ 
      int size = yyssp - yyss + 1; 
 
#ifdef yyoverflow 
      /* Each stack pointer address is followed by the size of 
	 the data in use in that stack, in bytes.  */ 
#ifdef YYLSP_NEEDED 
      /* This used to be a conditional around just the two extra args, 
	 but that might be undefined if yyoverflow is a macro.  */ 
      yyoverflow("parser stack overflow", 
		 &yyss1, size * sizeof (*yyssp), 
		 &yyvs1, size * sizeof (*yyvsp), 
		 &yyls1, size * sizeof (*yylsp), 
		 &yystacksize); 
#else 
      yyoverflow("parser stack overflow", 
		 &yyss1, size * sizeof (*yyssp), 
		 &yyvs1, size * sizeof (*yyvsp), 
		 &yystacksize); 
#endif 
 
      yyss = yyss1; yyvs = yyvs1; 
#ifdef YYLSP_NEEDED 
      yyls = yyls1; 
#endif 
#else /* no yyoverflow */ 
      /* Extend the stack our own way.  */ 
      if (yystacksize >= YYMAXDEPTH) 
	{ 
	  yyerror("parser stack overflow"); 
	  if (yyfree_stacks) 
	    { 
	      free (yyss); 
	      free (yyvs); 
#ifdef YYLSP_NEEDED 
	      free (yyls); 
#endif 
	    } 
	  return 2; 
	} 
      yystacksize *= 2; 
      if (yystacksize > YYMAXDEPTH) 
	yystacksize = YYMAXDEPTH; 
#ifndef YYSTACK_USE_ALLOCA 
      yyfree_stacks = 1; 
#endif 
      yyss = (short *) YYSTACK_ALLOC (yystacksize * sizeof (*yyssp)); 
      __yy_memcpy ((char *)yyss, (char *)yyss1, 
		   size * (unsigned int) sizeof (*yyssp)); 
      yyvs = (YYSTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yyvsp)); 
      __yy_memcpy ((char *)yyvs, (char *)yyvs1, 
		   size * (unsigned int) sizeof (*yyvsp)); 
#ifdef YYLSP_NEEDED 
      yyls = (YYLTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yylsp)); 
      __yy_memcpy ((char *)yyls, (char *)yyls1, 
		   size * (unsigned int) sizeof (*yylsp)); 
#endif 
#endif /* no yyoverflow */ 
 
      yyssp = yyss + size - 1; 
      yyvsp = yyvs + size - 1; 
#ifdef YYLSP_NEEDED 
      yylsp = yyls + size - 1; 
#endif 
 
#if YYDEBUG != 0 
      if (yydebug) 
	fprintf(stderr, "Stack size increased to %d\n", yystacksize); 
#endif 
 
      if (yyssp >= yyss + yystacksize - 1) 
	YYABORT; 
    } 
 
#if YYDEBUG != 0 
  if (yydebug) 
    fprintf(stderr, "Entering state %d\n", yystate); 
#endif 
 
  goto yybackup; 
 yybackup: 
 
/* Do appropriate processing given the current state.  */ 
/* Read a lookahead token if we need one and don't already have one.  */ 
/* yyresume: */ 
 
  /* First try to decide what to do without reference to lookahead token.  */ 
 
  yyn = yypact[yystate]; 
  if (yyn == YYFLAG) 
    goto yydefault; 
 
  /* Not known => get a lookahead token if don't already have one.  */ 
 
  /* yychar is either YYEMPTY or YYEOF 
     or a valid token in external form.  */ 
 
  if (yychar == YYEMPTY) 
    { 
#if YYDEBUG != 0 
      if (yydebug) 
	fprintf(stderr, "Reading a token: "); 
#endif 
      yychar = YYLEX; 
    } 
 
  /* Convert token to internal form (in yychar1) for indexing tables with */ 
 
  if (yychar <= 0)		/* This means end of input. */ 
    { 
      yychar1 = 0; 
      yychar = YYEOF;		/* Don't call YYLEX any more */ 
 
#if YYDEBUG != 0 
      if (yydebug) 
	fprintf(stderr, "Now at end of input.\n"); 
#endif 
    } 
  else 
    { 
      yychar1 = YYTRANSLATE(yychar); 
 
#if YYDEBUG != 0 
      if (yydebug) 
	{ 
	  fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]); 
	  /* Give the individual parser a way to print the precise meaning 
	     of a token, for further debugging info.  */ 
#ifdef YYPRINT 
	  YYPRINT (stderr, yychar, yylval); 
#endif 
	  fprintf (stderr, ")\n"); 
	} 
#endif 
    } 
 
  yyn += yychar1; 
  if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1) 
    goto yydefault; 
 
  yyn = yytable[yyn]; 
 
  /* yyn is what to do for this token type in this state. 
     Negative => reduce, -yyn is rule number. 
     Positive => shift, yyn is new state. 
       New state is final state => don't bother to shift, 
       just return success. 
     0, or most negative number => error.  */ 
 
  if (yyn < 0) 
    { 
      if (yyn == YYFLAG) 
	goto yyerrlab; 
      yyn = -yyn; 
      goto yyreduce; 
    } 
  else if (yyn == 0) 
    goto yyerrlab; 
 
  if (yyn == YYFINAL) 
    YYACCEPT; 
 
  /* Shift the lookahead token.  */ 
 
#if YYDEBUG != 0 
  if (yydebug) 
    fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]); 
#endif 
 
  /* Discard the token being shifted unless it is eof.  */ 
  if (yychar != YYEOF) 
    yychar = YYEMPTY; 
 
  *++yyvsp = yylval; 
#ifdef YYLSP_NEEDED 
  *++yylsp = yylloc; 
#endif 
 
  /* count tokens shifted since error; after three, turn off error status.  */ 
  if (yyerrstatus) yyerrstatus--; 
 
  yystate = yyn; 
  goto yynewstate; 
 
/* Do the default action for the current state.  */ 
yydefault: 
 
  yyn = yydefact[yystate]; 
  if (yyn == 0) 
    goto yyerrlab; 
 
/* Do a reduction.  yyn is the number of a rule to reduce with.  */ 
yyreduce: 
  yylen = yyr2[yyn]; 
  if (yylen > 0) 
    yyval = yyvsp[1-yylen]; /* implement default value of the action */ 
 
#if YYDEBUG != 0 
  if (yydebug) 
    { 
      int i; 
 
      fprintf (stderr, "Reducing via rule %d (line %d), ", 
	       yyn, yyrline[yyn]); 
 
      /* Print the symbols being reduced, and their result.  */ 
      for (i = yyprhs[yyn]; yyrhs[i] > 0; i++) 
	fprintf (stderr, "%s ", yytname[yyrhs[i]]); 
      fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]); 
    } 
#endif 
 
 
  switch (yyn) { 
 
case 1: 
#line 50 "lab3.y" 
{ 
           if (debug) { 
               printf("make symboltable[%d]\n",tablelen); 
           } 
           globaltable = MakeTable(NULL, 0); 
           symboltable[tablelen] = globaltable; 
           tablelen++; 
           if (0 == (argtemp.temp = (int *)malloc(50 * sizeof(int)))) { 
               printf("malloc for argument list buffer error\n"); 
               exit(1); 
           } 
           argtemp.size = 50; 
           if (0 == (arg_in.temp = (int *)malloc(50 * sizeof(int)))) { 
               printf("malloc for argument check buffer error\n"); 
               exit(1); 
           } 
           arg_in.size = 50; 
       ; 
    break;} 
case 2: 
#line 69 "lab3.y" 
{ 
           if (debug) { 
               printf("program => declaration_list\n"); 
           } 
       ; 
    break;} 
case 3: 
#line 77 "lab3.y" 
{/* 
           if (debug) { 
               printf("declaration_list => declaration_list declaration\n"); 
           }*/ 
       ; 
    break;} 
case 4: 
#line 83 "lab3.y" 
{/* 
           if (debug) { 
               printf("declaration_list => declaration\n"); 
           }*/ 
       ; 
    break;} 
case 5: 
#line 91 "lab3.y" 
{ 
           if (debug) { 
               printf("declaration => var_declaration\n"); 
           } 
       ; 
    break;} 
case 6: 
#line 97 "lab3.y" 
{ 
           if (debug) { 
               printf("declaration => fun_declaration\n"); 
           } 
       ; 
    break;} 
case 7: 
#line 105 "lab3.y" 
{ 
           struct table *tp = symboltable[tablelen-1]; 
           symbol *p = InsertSym(yyvsp[-1].id, tp); 
           if (0 == p) { 
               printf("line %3d error: %s :redefinition\n", lineno, yyvsp[-1].id); 
               right = 0; 
           } else { 
               p->type = yyvsp[-2].value; 
           } 
           if (debug) { 
               printf("var_declaration => type_specifer ID ;\n"); 
           } 
       ; 
    break;} 
case 8: 
#line 119 "lab3.y" 
{ 
           struct table *tp = symboltable[tablelen-1]; 
           symbol *p = InsertSym(yyvsp[-4].id, tp); 
           if (0 == p) { 
               printf("line %3d error: %s :redefinition\n", lineno, yyvsp[-4].id); 
               right = 0; 
           } else { 
               p->type = yyvsp[-5].value; 
           } 
           if (debug) { 
               printf("var_declaration => type_specifer ID [ NUM ] ;\n"); 
           } 
       ; 
    break;} 
case 9: 
#line 133 "lab3.y" 
{ 
           struct table *tp = symboltable[tablelen-1]; 
           symbol *p = InsertSym(yyvsp[-1].id, tp); 
           if (0 == p) { 
               printf("line %3d error: %s :redefinition\n", lineno, yyvsp[-1].id); 
               right = 0; 
           } else { 
               p->type = yyvsp[-3].value + 100; 
           } 
           if (debug) { 
               printf("var_declaration => type_specifer * ID ;\n"); 
           } 
       ; 
    break;} 
case 10: 
#line 147 "lab3.y" 
{ 
           struct table *tp = symboltable[tablelen-1]; 
           symbol *p = InsertSym(yyvsp[-4].id, tp); 
           if (0 == p) { 
               printf("line %3d error: %s :redefinition\n", lineno, yyvsp[-4].id); 
               right = 0; 
           } else { 
               p->type = yyvsp[-6].value + 100; 
           } 
           if (debug) { 
               printf("var_declaration => type_specifer * ID [ NUM ] ;\n"); 
           } 
       ; 
    break;} 
case 11: 
#line 163 "lab3.y" 
{ 
           yyval.value = INT; 
           if (debug) { 
               printf("type_specifer => INT\n"); 
           } 
       ; 
    break;} 
case 12: 
#line 170 "lab3.y" 
{ 
           yyval.value = VOID; 
           if (debug) { 
               printf("type_specifer => VOID\n"); 
           } 
       ; 
    break;} 
case 13: 
#line 177 "lab3.y" 
{ 
           yyval.value = CHAR; 
           if (debug) { 
               printf("type_specifer => CHAR\n"); 
           } 
       ; 
    break;} 
case 14: 
#line 186 "lab3.y" 
{ 
           tablelen--; 
           level--; 
       /*    if (debug) { 
               printf("fun_declaration => fun_tag compound_stmt\n"); 
           }*/ 
       ; 
    break;} 
case 15: 
#line 194 "lab3.y" 
{ 
           tablelen--; 
           level--; 
       /*    if (debug) { 
               printf("fun_declaration => fun_tag ;\n"); 
           }*/ 
       ; 
    break;} 
case 16: 
#line 204 "lab3.y" 
{ 
           char *p = InsertFun(yyvsp[-3].id, yyvsp[-5].value); 
           if (0 == p) { 
               printf("line %3d error: %s :function redefinition\n", lineno, yyvsp[-3].id); 
               right = 0; 
               free(argtemp.temp); 
           } 
           level++; 
           typecount = 0; 
           if (0 == (argtemp.temp = (int *)malloc(50 * sizeof(int)))) { 
               printf("malloc for argument list buffer error\n"); 
               exit(1); 
           } 
           argtemp.size = 50; 
           if (debug) { 
               printf("fun_tag => type_specifer calling_convention ID\n"); 
           } 
       ; 
    break;} 
case 17: 
#line 223 "lab3.y" 
{ 
           char *p = InsertFun(yyvsp[-3].id, yyvsp[-4].value); 
           if (0 == p) { 
               printf("line %3d error: %s :function redefinition\n", lineno, yyvsp[-3].id); 
               right = 0; 
               free(argtemp.temp); 
           } 
           level++; 
           typecount = 0; 
           if (0 == (argtemp.temp = (int *)malloc(50 * sizeof(int)))) { 
               printf("malloc for argument list buffer error\n"); 
               exit(1); 
           } 
           argtemp.size = 50; 
           if (debug) { 
               printf("fun_tag => type_specifer ID\n"); 
           } 
       ; 
    break;} 
case 18: 
#line 244 "lab3.y" 
{/* 
           if (debug) { 
               printf("params => param_list\n"); 
           }*/ 
       ; 
    break;} 
case 19: 
#line 250 "lab3.y" 
{ 
           if (typecount + 1 > argtemp.size) { 
               argtemp.temp = (int *)realloc(argtemp.temp,(argtemp.size + BUFFINCREMENT) * sizeof(int)); 
               if (0 == argtemp.temp) { 
                   printf("realloc for argument list buffer error\n"); 
                   exit(1); 
               } 
               argtemp.size += BUFFINCREMENT; 
           } 
           argtemp.temp[typecount++] = VOID; 
           if (debug) { 
               printf("params => VOID\n"); 
           } 
       ; 
    break;} 
case 20: 
#line 267 "lab3.y" 
{/* 
           if (debug) { 
               printf("param_list => param_list , param\n"); 
           }*/ 
       ; 
    break;} 
case 21: 
#line 273 "lab3.y" 
{/* 
           if (debug) { 
               printf("param_list => param\n"); 
           }*/ 
       ; 
    break;} 
case 22: 
#line 281 "lab3.y" 
{ 
           struct table *tp = symboltable[tablelen-1]; 
           symbol *p; 
 
           level++; 
           p = InsertSym(yyvsp[0].id, tp); 
           if (0 == p) { 
               printf("line %3d error: %s :redefinition\n", lineno, yyvsp[0].id); 
               right = 0; 
           } else { 
               p->type = yyvsp[-1].value; 
           } 
           level--; 
           if (typecount + 1 > argtemp.size) { 
               argtemp.temp = (int *)realloc(argtemp.temp,(argtemp.size + BUFFINCREMENT) * sizeof(int)); 
               if (0 == argtemp.temp) { 
                   printf("realloc for argument list buffer error\n"); 
                   exit(1); 
               } 
               argtemp.size += BUFFINCREMENT; 
           } 
           argtemp.temp[typecount++] = yyvsp[-1].value; 
           if (debug) { 
               printf("param => type_specifer ID\n"); 
           } 
       ; 
    break;} 
case 23: 
#line 308 "lab3.y" 
{ 
           struct table *tp = symboltable[tablelen-1]; 
           symbol *p; 
 
           level++; 
           p = InsertSym(yyvsp[0].id, tp); 
           if (0 == p) { 
               printf("line %3d error: %s :redefinition\n", lineno, yyvsp[0].id); 
               right = 0; 
           } else { 
               p->type = yyvsp[-2].value + 100; 
           } 
           level--; 
           if (typecount + 1 > argtemp.size) { 
               argtemp.temp = (int *)realloc(argtemp.temp,(argtemp.size + BUFFINCREMENT) * sizeof(int)); 
               if (0 == argtemp.temp) { 
                   printf("realloc for argument list buffer error\n"); 
                   exit(1); 
               } 
               argtemp.size += BUFFINCREMENT; 
           } 
           argtemp.temp[typecount++] = yyvsp[-2].value + 100; 
           if (debug) { 
               printf("param => type_specifer * ID\n"); 
           } 
       ; 
    break;} 
case 24: 
#line 335 "lab3.y" 
{ 
           struct table *tp = symboltable[tablelen-1]; 
           symbol *p; 
 
           level++; 
           p = InsertSym(yyvsp[-2].id, tp); 
           if (0 == p) { 
               printf("line %3d error: %s :redefinition\n", lineno, yyvsp[-2].id); 
               right = 0; 
           } else { 
               p->type = yyvsp[-3].value; 
           } 
           level--; 
           if (typecount + 1 > argtemp.size) { 
               argtemp.temp = (int *)realloc(argtemp.temp,(argtemp.size + BUFFINCREMENT) * sizeof(int)); 
               if (0 == argtemp.temp) { 
                   printf("realloc for argument list buffer error\n"); 
                   exit(1); 
               } 
               argtemp.size += BUFFINCREMENT; 
           } 
           argtemp.temp[typecount++] = yyvsp[-3].value; 
           if (debug) { 
               printf("param => type_specifer ID [ ]\n"); 
           } 
       ; 
    break;} 
case 25: 
#line 362 "lab3.y" 
{ 
           if (typecount + 1 > argtemp.size) { 
               argtemp.temp = (int *)realloc(argtemp.temp,(argtemp.size + BUFFINCREMENT) * sizeof(int)); 
               if (0 == argtemp.temp) { 
                   printf("realloc for argument list buffer error\n"); 
                   exit(1); 
               } 
               argtemp.size += BUFFINCREMENT; 
           } 
           argtemp.temp[typecount++] = ELLIPSIS; 
           if (debug) { 
               printf("param => ELLIPSIS\n"); 
           } 
       ; 
    break;} 
case 26: 
#line 379 "lab3.y" 
{/* 
           if (debug) { 
               printf("compound_stmt => { local_declarations statement_list }\n"); 
           }*/ 
       ; 
    break;} 
case 27: 
#line 387 "lab3.y" 
{/* 
           if (debug) { 
               printf("local_declarations =>local_declarations var_declaration\n"); 
           }*/ 
       ; 
    break;} 
case 29: 
#line 396 "lab3.y" 
{/* 
           if (debug) { 
               printf("statement_list => statement_list statement\n"); 
           }*/ 
       ; 
    break;} 
case 31: 
#line 405 "lab3.y" 
{/* 
           if (debug) { 
               printf("statement => expression_stmt\n"); 
           }*/ 
       ; 
    break;} 
case 32: 
#line 411 "lab3.y" 
{/* 
           if (debug) { 
               printf("statement => compound_stmt\n"); 
           }*/ 
       ; 
    break;} 
case 33: 
#line 417 "lab3.y" 
{/* 
           if (debug) { 
               printf("statement => if_stmt\n"); 
           }*/ 
       ; 
    break;} 
case 34: 
#line 423 "lab3.y" 
{/* 
           if (debug) { 
               printf("statement => while_stmt\n"); 
           }*/ 
       ; 
    break;} 
case 35: 
#line 429 "lab3.y" 
{/* 
           if (debug) { 
               printf("statement => return_stmt\n"); 
           }*/ 
       ; 
    break;} 
case 36: 
#line 437 "lab3.y" 
{ 
           if (debug) { 
               printf("expression_stmt => expression ;\n"); 
           } 
       ; 
    break;} 
case 37: 
#line 443 "lab3.y" 
{ 
           if (debug) { 
               printf("expression_stmt => ;\n"); 
           } 
       ; 
    break;} 
case 38: 
#line 451 "lab3.y" 
{ 
           if (debug) { 
               printf("if_stmt => IF ( expression ) statement\n"); 
           } 
       ; 
    break;} 
case 39: 
#line 457 "lab3.y" 
{ 
           if (debug) { 
               printf("if_stmt => IF ( expression ) statement ELSE statement\n"); 
           } 
       ; 
    break;} 
case 40: 
#line 465 "lab3.y" 
{ 
           if (debug) { 
               printf("while_stmt => WHILE ( expression ) statement\n"); 
           } 
       ; 
    break;} 
case 41: 
#line 473 "lab3.y" 
{ 
           if (debug) { 
               printf("return_stmt => RETURN ;\n"); 
           } 
       ; 
    break;} 
case 42: 
#line 479 "lab3.y" 
{ 
           if (debug) { 
               printf("return_stmt => RETURN expression ;\n"); 
           } 
       ; 
    break;} 
case 43: 
#line 487 "lab3.y" 
{ 
           if (yyvsp[-2].sign != 0) { 
               if (yyvsp[-2].sign->type != yyvsp[0].expn.type) { 
                   printf("line %3d error: = :the left and the right type does not match\n", lineno, yyvsp[-2].sign); 
                   right = 0; 
               } 
               yyval.expn.type = yyvsp[-2].sign->type; 
           } 
           if (debug) { 
               printf("expression => var = expression\n"); 
           } 
       ; 
    break;} 
case 44: 
#line 500 "lab3.y" 
{ 
           yyval.expn.type = yyvsp[0].expn.type; 
       /*    if (debug) { 
               printf("expression => simple_expression\n"); 
           }*/ 
       ; 
    break;} 
case 45: 
#line 509 "lab3.y" 
{ 
           yyval.sign = LookUp(yyvsp[0].id, symboltable[tablelen-1]); 
           if (0 == yyval.sign) { 
               printf("line %3d error: %s :undeclared identifier\n", lineno, yyvsp[0].id); 
               right = 0; 
           } 
           if (debug) { 
               printf("var => ID\n"); 
           } 
       ; 
    break;} 
case 46: 
#line 520 "lab3.y" 
{ 
           yyval.sign = LookUp(yyvsp[-3].id, symboltable[tablelen-1]); 
           if (0 == yyval.sign) { 
               printf("line %3d error: %s :undeclared identifier\n", lineno, yyvsp[-3].id); 
               right = 0; 
           } 
           if (debug) { 
               printf("var => ID [ expression ]\n"); 
           } 
       ; 
    break;} 
case 47: 
#line 533 "lab3.y" 
{ 
           yyval.expn.type = INT; 
           if ((yyvsp[-2].expn.type == INT || yyvsp[-2].expn.type == CHAR) && (yyvsp[0].expn.type == INT || yyvsp[0].expn.type == CHAR)) { 
               if (0 == strcmp(yyvsp[-1].op, "<")) { 
                   if (yyvsp[-2].expn.value < yyvsp[0].expn.value) { 
                       yyval.expn.value = 1; 
                   } else { 
                       yyval.expn.value = 0; 
                   } 
               } else if (0 == strcmp(yyvsp[-1].op, "<=")) { 
                   if (yyvsp[-2].expn.value <= yyvsp[0].expn.value) { 
                       yyval.expn.value = 1; 
                   } else { 
                       yyval.expn.value = 0; 
                   } 
               } else if (0 == strcmp(yyvsp[-1].op, ">")) { 
                   if (yyvsp[-2].expn.value > yyvsp[0].expn.value) { 
                       yyval.expn.value = 1; 
                   } else { 
                       yyval.expn.value = 0; 
                   } 
               } else if (0 == strcmp(yyvsp[-1].op, ">=")) { 
                   if (yyvsp[-2].expn.value >= yyvsp[0].expn.value) { 
                       yyval.expn.value = 1; 
                   } else { 
                       yyval.expn.value = 0; 
                   } 
               } else if (0 == strcmp(yyvsp[-1].op, "==")) { 
                   if (yyvsp[-2].expn.value == yyvsp[0].expn.value) { 
                       yyval.expn.value = 1; 
                   } else { 
                       yyval.expn.value = 0; 
                   } 
               } else { 
                   if (yyvsp[-2].expn.value != yyvsp[0].expn.value) { 
                       yyval.expn.value = 1; 
                   } else { 
                       yyval.expn.value = 0; 
                   } 
               } 
           } 
           if (yyvsp[-2].expn.type != INT && yyvsp[-2].expn.type != CHAR) { 
               printf("line %3d error: %s :illegal, left operand is not constant or character\n", lineno, yyvsp[-1].op); 
               right = 0; 
           } 
           if (yyvsp[0].expn.type != INT && yyvsp[0].expn.type != CHAR) { 
               printf("line %3d error: %s :illegal, right operand is not constant or character\n", lineno, yyvsp[-1].op); 
               right = 0; 
           } 
           if (debug) { 
               printf("simple_expression => additive_expression relop additive_expression\n"); 
           } 
       ; 
    break;} 
case 48: 
#line 587 "lab3.y" 
{ 
           yyval.expn.type = yyvsp[0].expn.type; 
       /*    if (debug) { 
               printf("simple_expression => additive_expression\n"); 
           }*/ 
       ; 
    break;} 
case 49: 
#line 596 "lab3.y" 
{ 
           if (debug) { 
               printf("relop => LE\n"); 
           } 
       ; 
    break;} 
case 50: 
#line 602 "lab3.y" 
{ 
           if (debug) { 
               printf("relop => LT\n"); 
           } 
       ; 
    break;} 
case 51: 
#line 608 "lab3.y" 
{ 
           if (debug) { 
               printf("relop => GT\n"); 
           } 
       ; 
    break;} 
case 52: 
#line 614 "lab3.y" 
{ 
           if (debug) { 
               printf("relop => GE\n"); 
           } 
       ; 
    break;} 
case 53: 
#line 620 "lab3.y" 
{ 
           if (debug) { 
               printf("relop => EQ\n"); 
           } 
       ; 
    break;} 
case 54: 
#line 626 "lab3.y" 
{ 
           if (debug) { 
               printf("relop => NE\n"); 
           } 
       ; 
    break;} 
case 55: 
#line 634 "lab3.y" 
{ 
           yyval.expn.type = INT; 
           if (yyvsp[-2].expn.type == INT && yyvsp[0].expn.type == INT) { 
               if (yyvsp[-1].op[0] == '+') { 
                   yyval.expn.value = yyvsp[-2].expn.value + yyvsp[0].expn.value; 
               } else { 
                   yyval.expn.value = yyvsp[-2].expn.value - yyvsp[0].expn.value;    
               } 
           } 
           if (yyvsp[-2].expn.type != INT) { 
               printf("line %3d error: %c :illegal, left operand is not constant\n", lineno, yyvsp[-1].op[0]); 
               right = 0; 
           } 
           if (yyvsp[0].expn.type != INT) { 
               printf("line %3d error: %c :illegal, right operand is not constant\n", lineno, yyvsp[-1].op[0]); 
               right = 0; 
           } 
           if (debug) { 
               printf("additive_expression => additive_expression ADDOP term\n"); 
           } 
       ; 
    break;} 
case 56: 
#line 656 "lab3.y" 
{ 
           yyval.expn.type = yyvsp[0].expn.type; 
       /*    if (debug) { 
               printf("additive_expression => term\n"); 
           }*/ 
       ; 
    break;} 
case 57: 
#line 665 "lab3.y" 
{ 
           yyval.expn.type = INT; 
           if (yyvsp[-2].expn.type == INT && yyvsp[0].expn.type == INT) { 
               if (yyvsp[-1].op[0] == '*') { 
                   yyval.expn.value = yyvsp[-2].expn.value * yyvsp[0].expn.value; 
               } else if (yyvsp[-1].op[0] == '/') { 
                   yyval.expn.value = yyvsp[-2].expn.value / yyvsp[0].expn.value;    
               } else { 
                   yyval.expn.value = yyvsp[-2].expn.value % yyvsp[0].expn.value;  
               } 
           } 
           if (yyvsp[-2].expn.type != INT) { 
               printf("line %3d error: %c :illegal, left operand is not constant\n", lineno, yyvsp[-1].op[0]); 
               right = 0; 
           } 
           if (yyvsp[0].expn.type != INT) { 
               printf("line %3d error: %c :illegal, right operand is not constant\n", lineno, yyvsp[-1].op[0]); 
               right = 0; 
           } 
           if (debug) { 
               printf("term => term mulop unary_expression\n"); 
           } 
       ; 
    break;} 
case 58: 
#line 689 "lab3.y" 
{ 
           yyval.expn.type = yyvsp[0].expn.type; 
       /*    if (debug) { 
               printf("term => unary_expression\n"); 
           }*/ 
       ; 
    break;} 
case 59: 
#line 698 "lab3.y" 
{ 
           yyval.op[0] = '*'; 
           if (debug) { 
               printf("mulop => *\n"); 
           } 
       ; 
    break;} 
case 60: 
#line 705 "lab3.y" 
{ 
           yyval.op[0] = '/'; 
           if (debug) { 
               printf("mulop => /\n"); 
           } 
       ; 
    break;} 
case 61: 
#line 712 "lab3.y" 
{ 
           yyval.op[0] = '%'; 
           if (debug) { 
               printf("mulop => %\n"); 
           } 
       ; 
    break;} 
case 62: 
#line 721 "lab3.y" 
{ 
           yyval.expn.type = INT; 
           if (yyvsp[0].expn.type == INT) { 
               if (yyvsp[-1].op[0] == '+') { 
                   yyval.expn.value = yyvsp[0].expn.value;   
               } else { 
                   yyval.expn.value = -yyvsp[0].expn.value;  
               } 
           } 
           if (yyvsp[0].expn.type != INT) { 
               printf("line %3d error: %c :illegal, right operand is not constant\n", lineno, yyvsp[-1].op[0]); 
               right = 0; 
           } 
           if (debug) { 
               printf("unary_expression => unaryop unary_expression\n"); 
           } 
       ; 
    break;} 
case 63: 
#line 739 "lab3.y" 
{ 
           yyval.expn.type = yyvsp[0].expn.type; 
       /*    if (debug) { 
               printf("unary_expression => factor\n"); 
           }*/ 
       ; 
    break;} 
case 64: 
#line 748 "lab3.y" 
{ 
           yyval.op[0] = '+'; 
           if (debug) { 
               printf("unaryop => +\n"); 
           } 
       ; 
    break;} 
case 65: 
#line 755 "lab3.y" 
{ 
           yyval.op[0] = '-'; 
           if (debug) { 
               printf("unaryop => -\n"); 
           } 
       ; 
    break;} 
case 66: 
#line 764 "lab3.y" 
{ 
           yyval.expn.type = yyvsp[-1].expn.type; 
           if (debug) { 
               printf("factor => ( expression )\n"); 
           } 
       ; 
    break;} 
case 67: 
#line 771 "lab3.y" 
{ 
           if (yyvsp[0].sign != 0) { 
               yyval.expn.type = yyvsp[0].sign->type; 
               yyval.expn.symadd = yyvsp[0].sign; 
           } 
           if (debug) { 
               printf("factor => var\n"); 
           } 
       ; 
    break;} 
case 68: 
#line 781 "lab3.y" 
{ 
           yyval.expn.type = yyvsp[0].expn.type; 
           if (debug) { 
               printf("factor => call\n"); 
           } 
       ; 
    break;} 
case 69: 
#line 788 "lab3.y" 
{ 
           yyval.expn.type = INT; 
           yyval.expn.value = atoi(yyvsp[0].id); 
           if (debug) { 
               printf("factor => NUM\n"); 
           } 
       ; 
    break;} 
case 70: 
#line 796 "lab3.y" 
{ 
           yyval.expn.type = CHAR; 
           yyval.expn.value = yyvsp[0].id[1]; 
           if (debug) { 
               printf("factor => CHAR_LITERAL\n"); 
           } 
       ; 
    break;} 
case 71: 
#line 804 "lab3.y" 
{ 
           yyval.expn.type = CHAR + 100; 
           yyval.expn.string = yyvsp[0].id; 
           if (debug) { 
               printf("factor => STRING_LITERAL\n"); 
           } 
       ; 
    break;} 
case 72: 
#line 814 "lab3.y" 
{ 
           yyval.expn.type = LookUpFun(yyvsp[-3].id); 
           if (0 == yyval.expn.type) { 
               printf("line %3d error: %s :undeclared function\n", lineno, yyvsp[-3].id); 
               right = 0; 
           } 
           typecheck = 0; 
           free(arg_in.temp); 
           if (0 == (arg_in.temp = (int *)malloc(50 * sizeof(int)))) { 
               printf("malloc for argument check buffer error\n"); 
               exit(1); 
           } 
           arg_in.size = 50; 
           if (debug) { 
               printf("call => ID ( args )\n"); 
           } 
       ; 
    break;} 
case 73: 
#line 834 "lab3.y" 
{/* 
           if (debug) { 
               printf("args => arg_list\n"); 
           }*/ 
       ; 
    break;} 
case 75: 
#line 843 "lab3.y" 
{ 
           if (typecheck + 1 > arg_in.size) { 
               arg_in.temp = (int *)realloc(arg_in.temp,(arg_in.size + BUFFINCREMENT) * sizeof(int)); 
               if (0 == arg_in.temp) { 
                   printf("realloc for argument check buffer error\n"); 
                   exit(1); 
               } 
               arg_in.size += BUFFINCREMENT; 
           } 
           arg_in.temp[typecheck++] = yyvsp[0].expn.type; 
       /*    if (debug) { 
               printf("arg_list => arg_list , expression\n"); 
           }*/ 
       ; 
    break;} 
case 76: 
#line 858 "lab3.y" 
{ 
           if (typecheck + 1 > arg_in.size) { 
               arg_in.temp = (int *)realloc(arg_in.temp,(arg_in.size + BUFFINCREMENT) * sizeof(int)); 
               if (0 == arg_in.temp) { 
                   printf("realloc for argument check buffer error\n"); 
                   exit(1); 
               } 
               arg_in.size += BUFFINCREMENT; 
           } 
           arg_in.temp[typecheck++] = yyvsp[0].expn.type; 
       /*    if (debug) { 
               printf("arg_list => expression\n"); 
           }*/ 
       ; 
    break;} 
case 77: 
#line 875 "lab3.y" 
{ 
           if (debug) { 
               printf("calling_convention => CDECL\n"); 
           } 
       ; 
    break;} 
case 78: 
#line 881 "lab3.y" 
{ 
           if (debug) { 
               printf("calling_convention => STDCALL\n"); 
           } 
       ; 
    break;} 
} 
   /* the action file gets copied in in place of this dollarsign */ 
#line 543 "/usr/local/share/bison.simple" 
 
  yyvsp -= yylen; 
  yyssp -= yylen; 
#ifdef YYLSP_NEEDED 
  yylsp -= yylen; 
#endif 
 
#if YYDEBUG != 0 
  if (yydebug) 
    { 
      short *ssp1 = yyss - 1; 
      fprintf (stderr, "state stack now"); 
      while (ssp1 != yyssp) 
	fprintf (stderr, " %d", *++ssp1); 
      fprintf (stderr, "\n"); 
    } 
#endif 
 
  *++yyvsp = yyval; 
 
#ifdef YYLSP_NEEDED 
  yylsp++; 
  if (yylen == 0) 
    { 
      yylsp->first_line = yylloc.first_line; 
      yylsp->first_column = yylloc.first_column; 
      yylsp->last_line = (yylsp-1)->last_line; 
      yylsp->last_column = (yylsp-1)->last_column; 
      yylsp->text = 0; 
    } 
  else 
    { 
      yylsp->last_line = (yylsp+yylen-1)->last_line; 
      yylsp->last_column = (yylsp+yylen-1)->last_column; 
    } 
#endif 
 
  /* Now "shift" the result of the reduction. 
     Determine what state that goes to, 
     based on the state we popped back to 
     and the rule number reduced by.  */ 
 
  yyn = yyr1[yyn]; 
 
  yystate = yypgoto[yyn - YYNTBASE] + *yyssp; 
  if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp) 
    yystate = yytable[yystate]; 
  else 
    yystate = yydefgoto[yyn - YYNTBASE]; 
 
  goto yynewstate; 
 
yyerrlab:   /* here on detecting error */ 
 
  if (! yyerrstatus) 
    /* If not already recovering from an error, report this error.  */ 
    { 
      ++yynerrs; 
 
#ifdef YYERROR_VERBOSE 
      yyn = yypact[yystate]; 
 
      if (yyn > YYFLAG && yyn < YYLAST) 
	{ 
	  int size = 0; 
	  char *msg; 
	  int x, count; 
 
	  count = 0; 
	  /* Start X at -yyn if nec to avoid negative indexes in yycheck.  */ 
	  for (x = (yyn < 0 ? -yyn : 0); 
	       x < (sizeof(yytname) / sizeof(char *)); x++) 
	    if (yycheck[x + yyn] == x) 
	      size += strlen(yytname[x]) + 15, count++; 
	  msg = (char *) malloc(size + 15); 
	  if (msg != 0) 
	    { 
	      strcpy(msg, "parse error"); 
 
	      if (count < 5) 
		{ 
		  count = 0; 
		  for (x = (yyn < 0 ? -yyn : 0); 
		       x < (sizeof(yytname) / sizeof(char *)); x++) 
		    if (yycheck[x + yyn] == x) 
		      { 
			strcat(msg, count == 0 ? ", expecting `" : " or `"); 
			strcat(msg, yytname[x]); 
			strcat(msg, "'"); 
			count++; 
		      } 
		} 
	      yyerror(msg); 
	      free(msg); 
	    } 
	  else 
	    yyerror ("parse error; also virtual memory exceeded"); 
	} 
      else 
#endif /* YYERROR_VERBOSE */ 
	yyerror("parse error"); 
    } 
 
  goto yyerrlab1; 
yyerrlab1:   /* here on error raised explicitly by an action */ 
 
  if (yyerrstatus == 3) 
    { 
      /* if just tried and failed to reuse lookahead token after an error, discard it.  */ 
 
      /* return failure if at end of input */ 
      if (yychar == YYEOF) 
	YYABORT; 
 
#if YYDEBUG != 0 
      if (yydebug) 
	fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]); 
#endif 
 
      yychar = YYEMPTY; 
    } 
 
  /* Else will try to reuse lookahead token 
     after shifting the error token.  */ 
 
  yyerrstatus = 3;		/* Each real token shifted decrements this */ 
 
  goto yyerrhandle; 
 
yyerrdefault:  /* current state does not do anything special for the error token. */ 
 
#if 0 
  /* This is wrong; only states that explicitly want error tokens 
     should shift them.  */ 
  yyn = yydefact[yystate];  /* If its default is to accept any token, ok.  Otherwise pop it.*/ 
  if (yyn) goto yydefault; 
#endif 
 
yyerrpop:   /* pop the current state because it cannot handle the error token */ 
 
  if (yyssp == yyss) YYABORT; 
  yyvsp--; 
  yystate = *--yyssp; 
#ifdef YYLSP_NEEDED 
  yylsp--; 
#endif 
 
#if YYDEBUG != 0 
  if (yydebug) 
    { 
      short *ssp1 = yyss - 1; 
      fprintf (stderr, "Error: state stack now"); 
      while (ssp1 != yyssp) 
	fprintf (stderr, " %d", *++ssp1); 
      fprintf (stderr, "\n"); 
    } 
#endif 
 
yyerrhandle: 
 
  yyn = yypact[yystate]; 
  if (yyn == YYFLAG) 
    goto yyerrdefault; 
 
  yyn += YYTERROR; 
  if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR) 
    goto yyerrdefault; 
 
  yyn = yytable[yyn]; 
  if (yyn < 0) 
    { 
      if (yyn == YYFLAG) 
	goto yyerrpop; 
      yyn = -yyn; 
      goto yyreduce; 
    } 
  else if (yyn == 0) 
    goto yyerrpop; 
 
  if (yyn == YYFINAL) 
    YYACCEPT; 
 
#if YYDEBUG != 0 
  if (yydebug) 
    fprintf(stderr, "Shifting error token, "); 
#endif 
 
  *++yyvsp = yylval; 
#ifdef YYLSP_NEEDED 
  *++yylsp = yylloc; 
#endif 
 
  yystate = yyn; 
  goto yynewstate; 
 
 yyacceptlab: 
  /* YYACCEPT comes here.  */ 
  if (yyfree_stacks) 
    { 
      free (yyss); 
      free (yyvs); 
#ifdef YYLSP_NEEDED 
      free (yyls); 
#endif 
    } 
  return 0; 
 
 yyabortlab: 
  /* YYABORT comes here.  */ 
  if (yyfree_stacks) 
    { 
      free (yyss); 
      free (yyvs); 
#ifdef YYLSP_NEEDED 
      free (yyls); 
#endif 
    } 
  return 1; 
} 
#line 888 "lab3.y" 
 
 
void info() 
{ 
    printf("lab3.exe -- Copyright (C) 2007 cj4 No.04120004\n"); 
    printf("Usage: lab3 [-d] filename\n"); 
    printf("----------------------------------------------------\n"); 
    printf("filename    specifies the name of input file\n"); 
    printf("-d          debug mode\n"); 
    exit(1); 
} 
 
int yyerror(char *s) 
{ 
    fprintf(stderr, "line %3d error: %s\n", lineno, s); 
    right = 0; 
    return (0); 
} 
 
int main(int argc, char *argv[]) 
{ 
    debug = 0; 
    switch (argc) { 
        case 3: 
            if (0 == strcmp(argv[1], "-d")) { 
                printf("============= debug mode =============\n"); 
                debug = 1; 
            } else { 
                info(); 
            } 
            if (NULL == (yyin = fopen(argv[2],"r"))) { 
                printf("file: %s open error!\n", argv[2]); 
                exit(1); 
            } 
            yyparse(); 
            free(argtemp.temp); 
            free(arg_in.temp); 
            fclose(yyin); 
            break; 
        case 2: 
            if (NULL == (yyin = fopen(argv[1],"r"))) { 
                printf("file: %s open error!\n", argv[1]); 
                exit(1); 
            } 
            yyparse(); 
            free(argtemp.temp); 
            free(arg_in.temp); 
            fclose(yyin); 
            break; 
        default: 
            info(); 
    } 
    if (right) { 
        printf("Well done!\n"); 
    } 
    return (0); 
}