
/*  A Bison parser, made from proj1.yac with Bison version GNU Bison version 1.22
  */

#define YYBISON 1  /* Identify Bison output.  */

#define	PGM	258
#define	VAR	259
#define	ARY	260
#define	OF	261
#define	INT	262
#define	REAL	263
#define	FUNC	264
#define	PROC	265
#define	BGN	266
#define	END	267
#define	IF	268
#define	THEN	269
#define	ELSE	270
#define	WHILE	271
#define	DO	272
#define	NOT	273
#define	DIV	274
#define	MOD	275
#define	AND	276
#define	OR	277
#define	ID	278
#define	NUM	279
#define	DD	280
#define	ASGN	281
#define	NE	282
#define	LE	283
#define	GE	284
#define	LP	285
#define	RP	286
#define	SC	287
#define	PE	288
#define	CO	289
#define	CL	290
#define	LB	291
#define	RB	292
#define	PL	293
#define	MI	294
#define	EQ	295
#define	LT	296
#define	GT	297
#define	MU	298
#define	DI	299
#define	UMIN	300

#line 5 "proj1.yac"

#include <stdio.h>
#include <string.h>

/* The parse stack type is a pointer to void in order that rule can */
/* return two types of items: strings and lists of strings. */
typedef void *STK_TYP;
#define YYSTYPE STK_TYP

/* A handy macro for printing quads (the label and fields 1-4). */
#define PRINT_QUAD(a,b,c,d,e)	printf("%s\t%s\t%s\t%s\t%s\n",a,b,c,d,e)

/* miscellaneous character variables */
char *temp, *temp1, *temp2;

/* Symbol table structure, kept as a doubly linked list (stack). */
/* Symbol types are:
/*    int, real, int ary, real ary, unknown, untyped procedure or program. */
typedef struct SYM
  {
  char *block;           /* name of enclosing block */
  char *name;            /* name of this symbol */
  char type;             /* i,r,I,R,u,' ': codes for symbol types */
  int  start, end;       /* array bounds */
  int  offset;           /* location of this symbol */
  int  nparms;           /* number of formal parameters for funcs, procs */
  struct SYM  *parmlist; /* list of formal parameters (NULL for variables) */
  struct SYM  *next;     /* pointer to next symbol in the list */
  struct SYM  *last;     /* pointer to last symbol in the list */
  } SYM;

/* pointer tot he base of the entire symbol table */
SYM  *prog = NULL;

/* pointer to the symbol of the subprogram currently being parsed: */
SYM  *subprog = NULL;

/* current top of symbol stack */
SYM  *top  = NULL;

/* miscellaneous symbol variables */
SYM  *sym1 = NULL;
SYM  *sym2 = NULL;

/* counter for offset locations for variables */
int offset = 0;

/* A type for a list of strings: a pointer to this type may also be */
/* passed on the parse stack. */
typedef struct STR_LST
  {
  char *str1;
  struct STR_LST *next;
  } STR_LST;
STR_LST *lbl_stk = NULL;
STR_LST *list1, *list2;

int tv_cnt = 0;    /* temporary variable counter */
int lbl_cnt = 0;   /* label counter */

#ifndef YYLTYPE
typedef
  struct yyltype
    {
      int timestamp;
      int first_line;
      int first_column;
      int last_line;
      int last_column;
      char *text;
   }
  yyltype;

#define YYLTYPE yyltype
#endif

#ifndef YYSTYPE
#define YYSTYPE int
#endif
#include <stdio.h>

#ifndef __cplusplus
#ifndef __STDC__
#define const
#endif
#endif



#define	YYFINAL		151
#define	YYFLAG		-32768
#define	YYNTBASE	46

#define YYTRANSLATE(x) ((unsigned)(x) <= 300 ? yytranslate[x] : 79)

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,     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,     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,     2,     3,     4,     5,
     6,     7,     8,     9,    10,    11,    12,    13,    14,    15,
    16,    17,    18,    19,    20,    21,    22,    23,    24,    25,
    26,    27,    28,    29,    30,    31,    32,    33,    34,    35,
    36,    37,    38,    39,    40,    41,    42,    43,    44,    45
};

#if YYDEBUG != 0
static const short yyprhs[] = {     0,
     0,     1,     2,    15,    17,    21,    22,    29,    31,    40,
    42,    44,    45,    49,    50,    55,    56,    64,    65,    71,
    72,    76,    80,    86,    90,    91,    93,    95,    99,   106,
   110,   112,   114,   116,   117,   118,   125,   126,   127,   135,
   136,   139,   141,   142,   148,   150,   155,   157,   161,   163,
   167,   171,   175,   179,   183,   187,   189,   193,   197,   201,
   204,   207,   209,   213,   217,   221,   225,   229,   231,   236,
   238,   242
};

static const short yyrhs[] = {    -1,
     0,     3,    23,    30,    49,    47,    31,    32,    50,    53,
    48,    61,    33,     0,    23,     0,    49,    34,    23,     0,
     0,    50,     4,    49,    35,    51,    32,     0,    52,     0,
     5,    36,    24,    25,    24,    37,     6,    52,     0,     7,
     0,     8,     0,     0,    53,    54,    32,     0,     0,    56,
    50,    55,    61,     0,     0,     9,    23,    57,    59,    35,
    52,    32,     0,     0,    10,    23,    58,    59,    32,     0,
     0,    30,    60,    31,     0,    49,    35,    51,     0,    60,
    32,    49,    35,    51,     0,    11,    62,    12,     0,     0,
    63,     0,    64,     0,    63,    32,    64,     0,    23,    36,
    75,    37,    26,    75,     0,    23,    26,    75,     0,    73,
     0,    61,     0,    67,     0,     0,     0,    16,    65,    75,
    66,    17,    64,     0,     0,     0,    13,    75,    68,    14,
    64,    69,    70,     0,     0,    15,    64,     0,    23,     0,
     0,    23,    72,    36,    75,    37,     0,    23,     0,    23,
    30,    74,    31,     0,    75,     0,    74,    34,    75,     0,
    76,     0,    76,    40,    76,     0,    76,    27,    76,     0,
    76,    42,    76,     0,    76,    29,    76,     0,    76,    41,
    76,     0,    76,    28,    76,     0,    77,     0,    76,    38,
    77,     0,    76,    39,    77,     0,    76,    22,    77,     0,
    39,    77,     0,    38,    77,     0,    78,     0,    77,    43,
    78,     0,    77,    44,    78,     0,    77,    19,    78,     0,
    77,    20,    78,     0,    77,    21,    78,     0,    71,     0,
    23,    30,    74,    31,     0,    24,     0,    30,    75,    31,
     0,    18,    78,     0
};

#endif

#if YYDEBUG != 0
static const short yyrline[] = { 0,
    73,   102,   109,   118,   125,   137,   139,   155,   157,   171,
   176,   183,   184,   187,   199,   218,   231,   236,   253,   256,
   257,   263,   283,   302,   305,   306,   309,   310,   313,   318,
   323,   324,   325,   326,   334,   340,   353,   360,   370,   372,
   379,   387,   393,   398,   410,   415,   431,   439,   450,   451,
   466,   481,   496,   511,   526,   543,   544,   550,   556,   572,
   579,   585,   586,   592,   598,   604,   610,   624,   625,   645,
   650,   654
};

static const char * const yytname[] = {   "$","error","$illegal.","PGM","VAR",
"ARY","OF","INT","REAL","FUNC","PROC","BGN","END","IF","THEN","ELSE","WHILE",
"DO","NOT","DIV","MOD","AND","OR","ID","NUM","DD","ASGN","NE","LE","GE","LP",
"RP","SC","PE","CO","CL","LB","RB","PL","MI","EQ","LT","GT","MU","DI","UMIN",
"prog","@1","@2","idlist","decs","type","stype","spdecs","spdec","@3","sphead",
"@4","@5","args","parlist","cpdstmt","opstmt","stmtlist","stmt","@6","@7","ifstmt",
"@8","@9","estmt","var","@10","procstmt","explist","exp","sexp","term","factor",
""
};
#endif

static const short yyr1[] = {     0,
    47,    48,    46,    49,    49,    50,    50,    51,    51,    52,
    52,    53,    53,    55,    54,    57,    56,    58,    56,    59,
    59,    60,    60,    61,    62,    62,    63,    63,    64,    64,
    64,    64,    64,    65,    66,    64,    68,    69,    67,    70,
    70,    71,    72,    71,    73,    73,    74,    74,    75,    75,
    75,    75,    75,    75,    75,    76,    76,    76,    76,    76,
    76,    77,    77,    77,    77,    77,    77,    78,    78,    78,
    78,    78
};

static const short yyr2[] = {     0,
     0,     0,    12,     1,     3,     0,     6,     1,     8,     1,
     1,     0,     3,     0,     4,     0,     7,     0,     5,     0,
     3,     3,     5,     3,     0,     1,     1,     3,     6,     3,
     1,     1,     1,     0,     0,     6,     0,     0,     7,     0,
     2,     1,     0,     5,     1,     4,     1,     3,     1,     3,
     3,     3,     3,     3,     3,     1,     3,     3,     3,     2,
     2,     1,     3,     3,     3,     3,     3,     1,     4,     1,
     3,     2
};

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

static const short yydefgoto[] = {   149,
     7,    17,     5,    11,    30,    31,    13,    18,    44,    19,
    32,    33,    48,    70,    37,    38,    39,    40,    61,   123,
    41,    79,   140,   146,    56,    75,    42,    96,    97,    58,
    59,    60
};

static const short yypact[] = {    15,
    16,     1,    19,-32768,    20,    28,    26,-32768,    29,-32768,
    65,    19,    54,    33,    48,    53,    69,    57,-32768,     8,
-32768,-32768,    39,    68,-32768,    65,    73,-32768,-32768,    58,
-32768,    80,    80,    35,-32768,    30,-32768,    96,    79,-32768,
-32768,-32768,-32768,    69,    88,-32768,    19,    81,    82,    -1,
   -16,-32768,    35,    -1,    -1,-32768,-32768,    55,    -9,-32768,
    35,    35,    35,    35,-32768,    39,-32768,    90,    44,    56,
    78,-32768,-32768,    35,    77,    86,    -9,    -9,   104,    -1,
    35,    35,    35,    -1,    -1,    35,    35,    35,    -1,    -1,
    -1,    -1,    -1,-32768,-32768,   -10,-32768,    83,-32768,    95,
     8,-32768,    19,    89,     9,    35,-32768,    39,    -9,   -13,
   -13,   -13,    -9,    -9,   -13,   -13,   -13,-32768,-32768,-32768,
-32768,-32768,   105,-32768,    35,    97,    87,-32768,    72,-32768,
-32768,    91,-32768,    39,-32768,    35,   119,     8,-32768,   111,
-32768,-32768,    78,-32768,    39,-32768,-32768,-32768,   127,   129,
-32768
};

static const short yypgoto[] = {-32768,
-32768,-32768,   -11,   112,   -97,   -68,-32768,-32768,-32768,-32768,
-32768,-32768,    99,-32768,   -12,-32768,-32768,   -64,-32768,-32768,
-32768,-32768,-32768,-32768,-32768,-32768,-32768,    59,   -34,    17,
   -47,   -44
};


#define	YYLAST		133


static const short yytable[] = {    57,
    14,    99,   104,   128,    24,    73,    77,    78,    80,    89,
    90,    91,    27,    74,    28,    29,    50,     1,    76,   -43,
   124,    51,    52,   125,    84,    85,    94,    95,    53,    98,
     3,    67,   109,    92,    93,    69,   113,   114,     2,   131,
   144,     4,   125,   133,   118,   119,   120,   121,   122,    23,
     8,    34,    50,     6,    35,    62,     9,    51,    52,    63,
    10,    36,    15,    16,    53,    64,     6,    20,    12,   141,
    21,   132,    54,    55,   147,    22,    80,     6,   101,    23,
   148,    81,    82,    83,    28,    29,   102,   103,    25,    46,
   135,   129,    84,    85,    86,    87,    88,   110,   111,   112,
    43,   142,   115,   116,   117,     6,   138,    65,    45,    47,
    66,    68,   106,    72,   100,    71,   107,   108,   127,   126,
   130,   134,   136,   137,   143,   145,   150,   139,   151,     0,
    26,    49,   105
};

static const short yycheck[] = {    34,
    12,    66,    71,   101,    17,    50,    54,    55,    22,    19,
    20,    21,     5,    30,     7,     8,    18,     3,    53,    36,
    31,    23,    24,    34,    38,    39,    61,    62,    30,    64,
    30,    44,    80,    43,    44,    47,    84,    85,    23,    31,
   138,    23,    34,   108,    89,    90,    91,    92,    93,    11,
    23,    13,    18,    34,    16,    26,    31,    23,    24,    30,
    32,    23,     9,    10,    30,    36,    34,    35,     4,   134,
    23,   106,    38,    39,   143,    23,    22,    34,    35,    11,
   145,    27,    28,    29,     7,     8,    31,    32,    32,    32,
   125,   103,    38,    39,    40,    41,    42,    81,    82,    83,
    33,   136,    86,    87,    88,    34,    35,    12,    36,    30,
    32,    24,    36,    32,    25,    35,    31,    14,    24,    37,
    32,    17,    26,    37,     6,    15,     0,    37,     0,    -1,
    19,    33,    74
};
/* -*-C-*-  Note some compilers choke on comments on `#line' lines.  */
#line 3 "/usr/local/gnu/lib/bison.simple"

/* Skeleton output parser for bison,
   Copyright (C) 1984, 1989, 1990 Bob Corbett and Richard Stallman

   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 1, 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., 675 Mass Ave, Cambridge, MA 02139, USA.  */


#ifndef alloca
#ifdef __GNUC__
#define alloca __builtin_alloca
#else /* not GNU C.  */
#if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi)
#include <alloca.h>
#else /* not sparc */
#if defined (MSDOS) && !defined (__TURBOC__)
#include <malloc.h>
#else /* not MSDOS, or __TURBOC__ */
#if defined(_AIX)
#include <malloc.h>
 #pragma alloca
#else /* not MSDOS, __TURBOC__, or _AIX */
#ifdef __hpux
#ifdef __cplusplus
extern "C" {
void *alloca (unsigned int);
};
#else /* not __cplusplus */
void *alloca ();
#endif /* not __cplusplus */
#endif /* __hpux */
#endif /* not _AIX */
#endif /* not MSDOS, or __TURBOC__ */
#endif /* not sparc.  */
#endif /* not GNU C.  */
#endif /* alloca not defined.  */

/* 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.  */

/* 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	return(0)
#define YYABORT 	return(1)
#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
#define YYLEX		yylex(&yylval, &yylloc)
#else
#define YYLEX		yylex(&yylval)
#endif
#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

/* Prevent warning if -Wstrict-prototypes.  */
#ifdef __GNUC__
int yyparse (void);
#endif

#if __GNUC__ > 1		/* GNU C and GNU C++ define this.  */
#define __yy_bcopy(FROM,TO,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_bcopy (from, to, count)
     char *from;
     char *to;
     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_bcopy (char *from, char *to, int count)
{
  register char *f = from;
  register char *t = to;
  register int i = count;

  while (i-- > 0)
    *t++ = *f++;
}

#endif
#endif

#line 184 "/usr/local/gnu/lib/bison.simple"
int
yyparse()
{
  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;

#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");
	  return 2;
	}
      yystacksize *= 2;
      if (yystacksize > YYMAXDEPTH)
	yystacksize = YYMAXDEPTH;
      yyss = (short *) alloca (yystacksize * sizeof (*yyssp));
      __yy_bcopy ((char *)yyss1, (char *)yyss, size * sizeof (*yyssp));
      yyvs = (YYSTYPE *) alloca (yystacksize * sizeof (*yyvsp));
      __yy_bcopy ((char *)yyvs1, (char *)yyvs, size * sizeof (*yyvsp));
#ifdef YYLSP_NEEDED
      yyls = (YYLTYPE *) alloca (yystacksize * sizeof (*yylsp));
      __yy_bcopy ((char *)yyls1, (char *)yyls, size * 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 74 "proj1.yac"
{
		/* generate the program symbol (bottom of the stack) */
			prog = new_sym();
			top = prog;
			top->block=strsave(yyvsp[-2]);
			top->name=strsave(yyvsp[-2]);
			top->parmlist=top;
		/* process STR_LST structure returned from idlist */
		/* add parameters returned from idlist to sym. table */
		/* 1st: transform the circular list to a linear list */
			list1=((STR_LST *)yyvsp[0])->next;
			((STR_LST *)yyvsp[0])->next=NULL;
			while (list1!=NULL)
			  {
			  sym1 = new_sym();
			  if (top->parmlist==top) top->parmlist=sym1;
			  top->next = sym1;
			  sym1->last = top;
			  top=sym1;
			  top->block = strsave(prog->block);
			  top->name = list1->str1;
			  top->type = 'u';
			  prog->nparms++;
			  list2=list1;
			  list1=list2->next;
			  free(list2);
			  }
			;
    break;}
case 2:
#line 103 "proj1.yac"
{
		/* All symbols have been collected for the program. */
		/* Report them now. */
			print_sym(prog);
			PRINT_QUAD("_start","NOP","","","");
			;
    break;}
case 3:
#line 110 "proj1.yac"
{
			PRINT_QUAD("","CALL","","","_exit");
			;
    break;}
case 4:
#line 119 "proj1.yac"
{
			list1=(STR_LST *)malloc(sizeof(STR_LST));
			list1->str1 = yyvsp[0];
			list1->next = list1;
			yyval = list1;
			;
    break;}
case 5:
#line 126 "proj1.yac"
{
			list1=(STR_LST *)malloc(sizeof(STR_LST));
			list1->str1=yyvsp[0];
			list1->next=((STR_LST *)yyvsp[-2])->next;
			((STR_LST *)yyvsp[-2])->next=list1;
			yyval=list1;
			;
    break;}
case 6:
#line 138 "proj1.yac"
{yyval = NULL;;
    break;}
case 7:
#line 140 "proj1.yac"
{
		/* 1st: transform the circular list into a linear linked list */
			list1=((STR_LST *)yyvsp[-3])->next;
			((STR_LST *)yyvsp[-3])->next=NULL;
			while (list1!=NULL)
			  {
			  add_sym(list1->str1,yyvsp[-1]);
			  list2=list1;
			  list1=list2->next;
			  free(list2);
			  }
			;
    break;}
case 8:
#line 156 "proj1.yac"
{ yyval=yyvsp[0]; ;
    break;}
case 9:
#line 158 "proj1.yac"
{
			yyval=(void *)malloc(strlen("ary ")+strlen(yyvsp[-5])+strlen(yyvsp[-3])+
					  strlen(yyvsp[0])+10);
			strcpy(yyval,"ary ");
			strcat(yyval,yyvsp[-5]);
			strcat(yyval," ");
			strcat(yyval,yyvsp[-3]);
			strcat(yyval," ");
			strcat(yyval,yyvsp[0]);
			;
    break;}
case 10:
#line 172 "proj1.yac"
{
			yyval=(char *)malloc(4);
			strcpy(yyval,"int");
			;
    break;}
case 11:
#line 177 "proj1.yac"
{
			yyval=(char *)malloc(5);
			strcpy(yyval,"real");
			;
    break;}
case 14:
#line 188 "proj1.yac"
{
		/* print out the subprogram's symbol table */
			print_sym(subprog);
		/*
			temp=next_lbl();
			printf("*\n*entry point is %s\n",temp);
			PRINT_QUAD(temp,"NOP","","","");
		*/
			PRINT_QUAD(subprog->name,"NOP","","","");
			;
    break;}
case 15:
#line 199 "proj1.yac"
{
			int i;
		/* End the subroutine with a return statement */
			PRINT_QUAD("","RTN","","","");
		/* Adjust symbol table so the next subroutine or the */
		/* main program can be parsed next.  Drop local variables */
		/* while keeping parameter data. */
			top=subprog;
			for (i=0; i<top->nparms; i++)
			  {
			  subprog=subprog->next;
			  }
			sym1=subprog->next;
			top->next=NULL;
			subprog->next=NULL;
			free_sym_chain(sym1);
			;
    break;}
case 16:
#line 219 "proj1.yac"
{
		/* Set up a new symbol for the function.  Update the */
		/* subprogram symbol pointer. */
			subprog=new_sym();
			top->next=subprog;
			subprog->last=top;
			top=subprog;
			top->block=strsave(yyvsp[0]);
			top->name=strsave(yyvsp[0]);
			top->offset=offset;
			top->parmlist=top;
			;
    break;}
case 17:
#line 232 "proj1.yac"
{
		/* Set up the return value type for the subprogram. */
			subprog->type=((char *)yyvsp[-1])[0];
			;
    break;}
case 18:
#line 237 "proj1.yac"
{
		/* Set up a new symbol for the procedure.  Update the */
		/* subprogram symbol pointer. */
			subprog=new_sym();
			top->next=subprog;
			subprog->last=top;
			top=subprog;
			top->block=strsave(yyvsp[0]);
			top->name=strsave(yyvsp[0]);
			top->offset=offset;
		/* Make the parmlist not NULL.  One way procedures and */
		/* functions are distinguished from other symbols is that */
		/* the parmlist pointer is not NULL, even though there may */
		/* may be no parmeter list. */
			top->parmlist=top;
			;
    break;}
case 21:
#line 258 "proj1.yac"
{
			yyval=yyvsp[-1];
			;
    break;}
case 22:
#line 264 "proj1.yac"
{
		/* Process the identifier list.  Make symbols for the */
		/* parameters, linking them to both the stack top and */
		/* the subprogram parameter list. */
			list1=((STR_LST *)yyvsp[-2])->next;
			((STR_LST *)yyvsp[-2])->next=NULL;
			while (list1!=NULL)
			  {
			  add_sym(list1->str1,yyvsp[0]);
			  subprog->nparms++;
			  list2=list1;
			  list1=list1->next;
			  free(list2);
			  }
		/* This will be the first parameter in the list.  Set up */
		/* the parameter pointer to this parameter. */
			subprog->parmlist=subprog->next;
			yyval=NULL;
			;
    break;}
case 23:
#line 284 "proj1.yac"
{
		/* Process the identifier list.  Make symbols for the */
		/* parameters, linking them to both the stack top and */
		/* the subprogram parameter list. */
			list1=((STR_LST *)yyvsp[-2])->next;
			((STR_LST *)yyvsp[-2])->next=NULL;
			while (list1!=NULL)
			  {
			  add_sym(list1->str1,yyvsp[0]);
			  subprog->nparms++;
			  list2=list1;
			  list1=list1->next;
			  free(list2);
			  }
			yyval=NULL;
			;
    break;}
case 29:
#line 314 "proj1.yac"
{
		/* Assignment to an array element. */
			PRINT_QUAD("","[]=",yyvsp[-5],yyvsp[-3],yyvsp[0]);
			;
    break;}
case 30:
#line 319 "proj1.yac"
{
		/* Assignment to a scalar. */
			PRINT_QUAD("","MOV",yyvsp[0],"",yyvsp[-2]);
			;
    break;}
case 34:
#line 327 "proj1.yac"
{
		/* Label loop top and stack the label on the label stack. */
			temp=next_lbl();
			push_lbl(temp);
			PRINT_QUAD(temp,"NOP","","","");
			;
    break;}
case 35:
#line 334 "proj1.yac"
{
		/* Check for end of loop.  Stack the branch label. */
			temp=next_lbl();
			push_lbl(temp);
			PRINT_QUAD("","JZ",yyvsp[0],"",temp);
			;
    break;}
case 36:
#line 341 "proj1.yac"
{
		/* Pop the 2 saved labels.  Unconditional jump to the */
		/* 1st label, label a NOP statement with the second. */
			temp1=pop_lbl();
			temp2=pop_lbl();
			PRINT_QUAD("","JMP","","",temp2);
			PRINT_QUAD(temp1,"NOP","","","");
			free(temp1);
			free(temp2);
			;
    break;}
case 37:
#line 354 "proj1.yac"
{
		/* Handle labels for the ifstmt */
			temp=next_lbl();
			push_lbl(temp);
			PRINT_QUAD("","JZ",yyvsp[0],"",temp);
			;
    break;}
case 38:
#line 361 "proj1.yac"
{
			temp1=next_lbl();
			PRINT_QUAD("","JMP","","",temp1);
			temp=pop_lbl();
			PRINT_QUAD(temp,"NOP","","","");
			push_lbl(temp1);
			free(temp);
			;
    break;}
case 40:
#line 373 "proj1.yac"
{
		/* Handle lables for if without else. */
			temp=pop_lbl();
			PRINT_QUAD(temp,"NOP","","","");
			free(temp);
			;
    break;}
case 41:
#line 380 "proj1.yac"
{
		/* Handle labels for if with else. */
			temp=pop_lbl();
			PRINT_QUAD(temp,"NOP","","","");
			free(temp);
			;
    break;}
case 42:
#line 388 "proj1.yac"
{
		/* Parser stack the value of the identifier returned by Lex */
			yyval=(void *)malloc(strlen(yylval)+1);
			strcpy(yyval,yylval);
			;
    break;}
case 43:
#line 394 "proj1.yac"
{
		/* Save identifier of an array on the label stack */
			push_lbl(yylval);
			;
    break;}
case 44:
#line 399 "proj1.yac"
{
		/* Make a temporary variable equal to the evaluation of the */
		/* array reference. */
			temp=pop_lbl();
			temp1=next_tv();
			PRINT_QUAD("","[]",temp,yyvsp[-1],temp1);
			yyval=temp1;
			free(temp);
			;
    break;}
case 45:
#line 411 "proj1.yac"
{
		/* Call the procedure */
			PRINT_QUAD("","CALL","","",yyvsp[0]);
			;
    break;}
case 46:
#line 416 "proj1.yac"
{
		/* "PUSH" variables before calling procedure */
			list1=((STR_LST *)yyvsp[-1])->next;
			((STR_LST *)yyvsp[-1])->next=NULL;
			while (list1!=NULL)
			  {
			  PRINT_QUAD("","PUSH","","",list1->str1);
			  list2=list1->next;
			  free(list1);
			  list1=list2;
			  }
			PRINT_QUAD("","CALL","","",yyvsp[-3]);
			;
    break;}
case 47:
#line 432 "proj1.yac"
{
		/* Start building a circular list of expressions for passing */
			list1=(STR_LST *)malloc(sizeof(STR_LST));
			list1->str1 = yyvsp[0];
			list1->next = list1;
			yyval = list1;
			;
    break;}
case 48:
#line 440 "proj1.yac"
{
		/* Add to the circular list of expressions for parm passing */
			list1=(STR_LST *)malloc(sizeof(STR_LST));
			list1->str1=yyvsp[0];
			list1->next=((STR_LST *)yyvsp[-2])->next;
			((STR_LST *)yyvsp[-2])->next=list1;
			yyval=list1;
			;
    break;}
case 50:
#line 452 "proj1.yac"
{
		/* Expand the '=' operation with our set of quad operations */
			temp=next_lbl();
			temp1=next_tv();
			temp2=next_tv();
			PRINT_QUAD("","MOV","1","",temp1);
			PRINT_QUAD("","SUB",yyvsp[-2],yyvsp[0],temp2);
			PRINT_QUAD("","JZ",temp2,"",temp);
			PRINT_QUAD("","MOV","0","",temp1);
			PRINT_QUAD(temp,"NOP","","","");
			yyval = temp1;
			free(temp);
			free(temp2);
			;
    break;}
case 51:
#line 467 "proj1.yac"
{
		/* Expand the '<>' operation with our set of quad operations */
			temp1=next_tv();
			temp2=next_tv();
			temp=next_lbl();
			PRINT_QUAD("","MOV","0","",temp1);
			PRINT_QUAD("","SUB",yyvsp[-2],yyvsp[0],temp2);
			PRINT_QUAD("","JZ",temp2,"",temp);
			PRINT_QUAD("","MOV","1","",temp1);
			PRINT_QUAD(temp,"NOP","","","");
			yyval = temp1;
			free(temp);
			free(temp2);
			;
    break;}
case 52:
#line 482 "proj1.yac"
{
		/* Expand the '>' operation with our set of quad operations */
			temp1=next_tv();
			temp2=next_tv();
			temp=next_lbl();
			PRINT_QUAD("","MOV","1","",temp1);
			PRINT_QUAD("","SUB",yyvsp[-2],yyvsp[0],temp2);
			PRINT_QUAD("","JGZ",temp2,"",temp);
			PRINT_QUAD("","MOV","0","",temp1);
			PRINT_QUAD(temp,"NOP","","","");
			yyval = temp1;
			free(temp);
			free(temp2);
			;
    break;}
case 53:
#line 497 "proj1.yac"
{
		/* Expand the '>=' operation with our set of quad operations */
			temp1=next_tv();
			temp2=next_tv();
			temp=next_lbl();
			PRINT_QUAD("","MOV","0","",temp1);
			PRINT_QUAD("","SUB",yyvsp[0],yyvsp[-2],temp2);
			PRINT_QUAD("","JGZ",temp2,"",temp);
			PRINT_QUAD("","MOV","1","",temp1);
			PRINT_QUAD(temp,"NOP","","","");
			yyval = temp1;
			free(temp);
			free(temp2);
			;
    break;}
case 54:
#line 512 "proj1.yac"
{
		/* Expand the '<' operation with our set of quad operations */
			temp1=next_tv();
			temp2=next_tv();
			temp=next_lbl();
			PRINT_QUAD("","MOV","1","",temp1);
			PRINT_QUAD("","SUB",yyvsp[0],yyvsp[-2],temp2);
			PRINT_QUAD("","JGZ",temp2,"",temp);
			PRINT_QUAD("","MOV","0","",temp1);
			PRINT_QUAD(temp,"NOP","","","");
			yyval = temp1;
			free(temp);
			free(temp2);
			;
    break;}
case 55:
#line 527 "proj1.yac"
{
		/* Expand the '<=' operation with our set of quad operations */
			temp1=next_tv();
			temp2=next_tv();
			temp=next_lbl();
			PRINT_QUAD("","MOV","0","",temp1);
			PRINT_QUAD("","SUB",yyvsp[-2],yyvsp[0],temp2);
			PRINT_QUAD("","JGZ",temp2,"",temp);
			PRINT_QUAD("","MOV","1","",temp1);
			PRINT_QUAD(temp,"NOP","","","");
			yyval = temp1;
			free(temp);
			free(temp2);
			;
    break;}
case 57:
#line 545 "proj1.yac"
{
			temp=next_tv();
			PRINT_QUAD("","ADD",yyvsp[-2],yyvsp[0],temp);
			yyval = temp;
			;
    break;}
case 58:
#line 551 "proj1.yac"
{
			temp=next_tv();
			PRINT_QUAD("","SUB",yyvsp[-2],yyvsp[0],temp);
			yyval = temp;
			;
    break;}
case 59:
#line 557 "proj1.yac"
{
		/* Expand the 'or' operation with our set of quad operations */
			temp=next_tv();
			temp1=next_lbl();
			temp2=next_lbl();
			PRINT_QUAD("","MOV","0","",temp);
			PRINT_QUAD("","JZ",yyvsp[-2],"",temp1);
			PRINT_QUAD("","MOV","1","",temp);
			PRINT_QUAD(temp1,"JZ",yyvsp[0],"",temp2);
			PRINT_QUAD("","MOV","1","",temp);
			PRINT_QUAD(temp2,"NOP","","","");
			yyval = temp;
			free(temp1);
			free(temp2);
			;
    break;}
case 60:
#line 573 "proj1.yac"
{
		/* Expand unary minus with our set of quad operations */
			temp=next_tv();
			PRINT_QUAD("","SUB","0",yyvsp[0],yyvsp[0]);
			yyval=yyvsp[0];
			;
    break;}
case 61:
#line 580 "proj1.yac"
{
			yyval = yyvsp[0];
			;
    break;}
case 63:
#line 587 "proj1.yac"
{
			temp=next_tv();
			PRINT_QUAD("","MUL",yyvsp[-2],yyvsp[0],temp);
			yyval = temp;
			;
    break;}
case 64:
#line 593 "proj1.yac"
{
			temp=next_tv();
			PRINT_QUAD("","DI",yyvsp[-2],yyvsp[0],temp);
			yyval = temp;
			;
    break;}
case 65:
#line 599 "proj1.yac"
{
			temp=next_tv();
			PRINT_QUAD("","DIV",yyvsp[-2],yyvsp[0],temp);
			yyval = temp;
			;
    break;}
case 66:
#line 605 "proj1.yac"
{
			temp=next_tv();
			PRINT_QUAD("","MOD",yyvsp[-2],yyvsp[0],temp);
			yyval = temp;
			;
    break;}
case 67:
#line 611 "proj1.yac"
{ 
		/* Expand the 'and' operation with our set of quad operations */
			temp=next_tv();
			temp1=next_lbl();
			PRINT_QUAD("","MOV","0","",temp);
			PRINT_QUAD("","JZ",yyvsp[-2],"",temp1);
			PRINT_QUAD("","JZ",yyvsp[0],"",temp1);
			PRINT_QUAD("","MOV","1","",temp);
			PRINT_QUAD(temp1,"NOP","","","");
			yyval = temp;
			;
    break;}
case 69:
#line 626 "proj1.yac"
{
		/* Convert circular list of expressions to a linear list */
		/* Write "PUSH" commands to send the expressions, the */
		/* CALL command to call the subroutine, and the PULL */
		/* command to return the value */
			list1=((STR_LST *)yyvsp[-1])->next;
			((STR_LST *)yyvsp[-1])->next=NULL;
			while (list1!=NULL)
			  {
			  PRINT_QUAD("","PUSH","","",list1->str1);
			  list2=list1->next;
			  free(list1);
			  list1=list2;
			  }
			PRINT_QUAD("","CALL","","",yyvsp[-3]);
			temp1=next_tv();
			PRINT_QUAD("","PULL","","",temp1);
			yyval=temp1;
			;
    break;}
case 70:
#line 646 "proj1.yac"
{
		yyval=(char *)malloc(strlen(yylval)+1);
		strcpy(yyval,yylval);
		;
    break;}
case 71:
#line 651 "proj1.yac"
{
		yyval = yyvsp[-1];
		;
    break;}
case 72:
#line 655 "proj1.yac"
{
		/* Expand the 'not' operation with our set of quad operations */
		temp=next_lbl();
		temp1=next_tv();
		PRINT_QUAD("","MOV","1","",temp1);
		PRINT_QUAD("","JZ",yyvsp[0],"",temp);
		PRINT_QUAD("","MOV","0","",temp1);
		PRINT_QUAD(temp,"NOP","","","");
		free(temp);
		;
    break;}
}
   /* the action file gets copied in in place of this dollarsign */
#line 465 "/usr/local/gnu/lib/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;
}
#line 666 "proj1.yac"


#include "lex.yy.c"

/* Return an unique temporary variable.  Note that compiler generated */
/* labels start with upper case letters.  */
char *next_tv()
{
	char *s;
	s=(char *)malloc(10);
	if (s==NULL) 
	  {
	  printf("no room: next_tv (tv_cnt=%d)...\n",tv_cnt);
	  exit(1);
	  }
	sprintf(s,"T%d",tv_cnt++);
	return(s);
}

/* Return a unique label. */
char *next_lbl()
{
	char *s;
	s=(char *)malloc(10);
	if (s==NULL) 
	  {
	  printf("no room: next_lbl (lbl_cnt=%d)...\n",lbl_cnt);
	  exit(1);
	  }
	sprintf(s,"L%d",lbl_cnt++);
	return(s);
}
	
/* Save a character value (typically a label) on a stack. */
void push_lbl(c)
char *c;
{
	char *s;
	STR_LST *l;
	l=(STR_LST *)malloc(sizeof(STR_LST));
	if (l==NULL)
	  {
	  printf("no room: push_lbl (stack)\n");
	  exit(1);
	  }
	l->next=lbl_stk;
	l->str1=(char *)malloc(strlen(c)+1);
	if (l->str1==NULL)
 	  {
	  printf("no room: push_lbl (string)\n");
	  exit(1);
	  }
	strcpy(l->str1,c);
	lbl_stk=l;
}

/* retrieve a character value from the "label stack". */
char *pop_lbl()
{
	char *s;
	STR_LST *l;
	s=lbl_stk->str1;
	l=lbl_stk;
	lbl_stk=lbl_stk->next;
	free(l);
	return(s);
}
	
/***********  Symbol table routines **********/

/* Generate a new, blank symbol */
SYM *new_sym() 
{
	SYM *s;
	s=(SYM *)malloc(sizeof(SYM));
	s->block=NULL;
	s->name=NULL;
	s->type=' ';
	s->start=0;
	s->end=0;
	s->offset=0;
	s->nparms=0;
	s->parmlist=NULL;
	s->next=NULL;
	s->last=NULL;
	return(s);
}

/* Look for the symbol in the current context.  Return its pointer. */
SYM *find_sym(s)
char *s;
{
	SYM *f;
	int notfound;
	f=top;
	if (f!=NULL) notfound=strcmp(s,f->name);
	while (notfound && f!=NULL)
	  {
	  notfound=strcmp(s,f->name);
	  f=f->last;
	  }
	return(f);
}

/* Add a new symbol to the top of the symbol stack */
void add_sym(str,t)
char *str; /* name of new symbol */
char *t; /* type of symbol */
{
	SYM *s, *ss;

	ss=find_sym(str);
	if (ss!=NULL)
	  if (0==strcmp(ss->block,top->block))
	    {
	    printf("ERROR: duplicate declaration of name %s in block %s\n",
		ss->name, ss->block);
	    return;
	    }
	s=new_sym();
	s->block=strsave(top->block);
	top->next=s;
	s->last=top;
	top=s;
	top->name=str;
	if (t[0]=='i' || t[0]=='r') top->type=t[0];
	else
	  {
	  sscanf(t,"ary %d %d %c", &(top->start), &(top->end), &(top->type));
	  top->type -=32;  /* switch to upper case */
	  }
	top->offset=offset;
	offset = 4 * (top->end - top->start + 1) + offset;
	return;
}

/* Print the current symbol table. */
void print_sym(sub)
SYM *sub;
{
	SYM *s, *ss;
	int i;

	printf("*B %s\n",sub->block);
	s=top;
	while (s!=NULL)
	  {
	  if (s->parmlist==NULL)
	    {
	    printf("*V %s %s ",s->block,s->name);
	    if (s->type=='i') printf("integer ");
	    if (s->type=='r') printf("real ");
	    if (s->type=='I') printf("integer [%d..%d] ",s->start,s->end);
	    if (s->type=='R') printf("real [%d..%d] ",s->start,s->end);
	    if (s->type=='u') printf("unknown ");
	    printf("%d\n",s->offset);
	    }
	  else
	    {
	    if (s->type == ' ' && s->last!=NULL) printf("*R ");
	    else if (s->type==' ') printf("*P ");
	    else              printf("*F ");
	    printf("%s %s ",s->block,s->name);
	    if (s->type == 'i') printf("integer ");
	    else if (s->type == 'r') printf("real ");
	    printf("%d\n",s->nparms);
	    ss=s->parmlist;
	    if (ss->next!=s)
	      {
	      i=0;
	      while (i<s->nparms)
	        {
	        printf("*P%d ",++i);
	        if (ss->type=='i') printf("integer ");
	        if (ss->type=='r') printf("real ");
	        if (ss->type=='I') 
			printf("integer [%d..%d] ",ss->start,ss->end);
	        if (ss->type=='R') 
			printf("real [%d..%d] ",ss->start,ss->end);
	        if (ss->type=='u') printf("unknown ");
	        printf("%d\n",ss->offset);
	        ss=ss->next;
	        }
	      }
	    }
	  s=s->last;
	  }
}

/* Delete all of the symbols pointed to by s to the top of the stack. */ 
void free_sym_chain(s)
SYM *s;
{
	SYM *ss;
	while (s!=NULL)
	  {
	  free(s->block);
	  free(s->name);
	  ss=s->next;
	  free(s);
	  s=ss;
	  }
}

/* Parse error routine */
yyerror(s)
char *s;
{ printf("%s error at line no. %d \n",s,lineno);
}

main()
{
	yyparse();
}
