NAME
     compiler - controls the main flow of the program. 
     outblock - checks the outblock.
     error    - a typical error handling function.

SYNOPSIS
     #include "getsym.h"
     compiler.c

     void
     compiler(void);

     void
     outblock(void);

     void
     error(char *msg, ...);

DESCRIPTION
     The file "compiler.c" contains all the functions mentioned above. It
     controls the main flow of the compiler. At first it determines that

		 ---------     -------     ---
          ----->| program |-->| ident |-->| ; |--->
		 ---------     -------     ---

     a 'program' identifier is declared followed by the identifier. The
     program declaration must end with a semicolon otherwise it will 
     complain. Upon getting successful with the program declaration, it
     passes the control to outblock.

     outblock checks for a variable declaration 'VAR', followed by a single
     or multiple variables to be registered in the variable table. 

		 _____     _______
          ----->| var |-->| ident |----------- 
		 -----  ^  -------            |
	        ___	|        ___          |
          <----| ; |____|_______| , |_________|
	        ---              --- 	

     Two points should be remembered here:

	  o A program without a variable declaration fails miserably. For
	    example:

                ------- example program starts below ---------
		program test;

		procedure proc1(a, b);
		var c, d;
		begin
		     ...
		end;

		begin
		    proc1(1, 2);
		end.
                ------- example program ends here  ------------
            
	    is a valid program but it fails with an error message:

  	        "Error: A var declaration is required."

	    so, you must declare a variable even if you don't want to use
	    one.
     
     outblock initializes the global variable Table(refer to table.h) by:

	  Table = init_table();

     then it registers variables declared with the function table(refer to
     table.c):

	  table(tok.charvalue, Table);

     After registering the variables, it passess the control over to 
     statement or procedure depending on the option available. But 
     before passing control to statement it changes the global variable 
     procedure_flag:

	  procedure_flag = 0;

     This global variable is used to detemine the necessary codes required
     to produce in the assembly codes. When, procedure_flag is set to 1,
     codes are generated relative to the Base Register. For example:

	  a := 1;

     will produce something like:

	  loadi   r3, 1
	  store   r3, 0   # considering the address of a is 0

     when procedure_flag is set to 0(off). However, the same source will
     produce something like:

	  loadi   r3, 1
	  store   r3, 0(BR) # considering the address of a is 0

     when procedure_flag is set to 1(on).

     error is declared like:

	  void error(char *msg, ...);

     It takes a message through the msg pointer and formats the output
     as the format passed through the msg pointer. So,

	  error("A VAR declaration is required.");
	  error("line: %d: Procedure declaration in required.", tok.sline)
	  error("lins: %d: Undeclared variable '%s'", tok.sline, tmp)

     all should work fine. It uses vfprintf(3) to format the passed message. 
     This error message is used through out the program. Point to remember
     regarding this function is that it makes an exit from the program.

FILES
     compiler.c
     getsym.h

WARNING
     The following variables are declared as extern variables:

          extern  TOKEN   tok;    
          extern  FILE    *infile;
          extern  FILE    *outfile;
          extern  struct  list    *Table;
          extern  int     procedure_flag;

     These variables should be declared somewhere before explicitly used.
     Here, these variables were declared in main.c.

SEE ALSO
     statement, procedure, table, vprintf(3).

AUTHOR
     Chakma Junan <jchakma@yahoo.com> 
     Information and Computer Sciences
     Toyohashi University of Technology.
     (It was originially implemented by: ohno@edu.tut.ac.jp)

     Last Updated: Mon Feb 14 20:32:56 JST 2000

