/*********************************************************************
 * Author: B. Alex Bridges                                           *
 * Login ID: brid0129                                                *
 * Class: CPSC-431, Winter 2000                                      *
 * Project: Laboratory Exercise 2                                    *
 * Description: This program is a lexical analyzer and the parser    *
 *              portion of a syntax analyzer for the lanaguage Micro *
 *              Modula-2.                                            *
 * Contents: main method which drives program.                       *
 *********************************************************************/

/* IMPORTS */
import java.io.*;


class Prog2
{
  /* CONSTANTS */
    final static boolean b_debug = false; // CONTROLS EXTRA DEBUG OUTPUT

  /* GLOBAL VARIABLES */
  // NONE

  /*************************************************************************
   * Method: main                                                          *
   * Purpose: Drives program.                                              *
   * Input: --COMMAND-LINE ARGUMENTS--                                     *
   *        1. 'SOURCE_FILE' = The filename of the source program which    *
   *                           must end in '.mm'.                          *
   * Output: --EXIT VALUES--                                               *
   *         => COMPLETED SUCCESSFULLY = +1                                *
   *         => FATAL ERROR/EXCEPTION  = -1                                *
   *************************************************************************/
  public static void main(String[] args)
  {
    /* LOCAL VARIABLES */
    BufferedReader br_file_in_org;    // ORIGINAL FILE INPUT STREAM SETUP v1.0
    StreamTokenizer stmT_file_in_org; // ORIGINAL FILE INPUT STREAM SETUP v2.0
    
    /* HEADER */
    System.out.println("*******************************************\n"+
                       "* BAB's Micro Modula-2 Compiler v2.0 Beta *\n"+
                       "*******************************************\n");

    /* CHECKING FOR REQUIRED ARGUMENT */
    if(args.length != 1)
    {
      System.out.println(" FATAL ERROR: The following command-line argument must be included:\n"+
                         "  => 1. 'SOURCE_FILE' = The filename of the source program which \n"+
                         "                        must end in '.mm'");

      System.exit(-1);
    } // if
    if(b_debug)
    {
      System.out.println("The following command-line arguments were provided:\n"+
                         " => 1. 'SOURCE_FILE' = " + args[0] + "\n");
    } // if

    /* ORIGINAL FILE INPUT STREAM v1.0 SETUP FOR SPECIFIED FILE */
    br_file_in_org = File.open(args[0], true);

    if(br_file_in_org == null)
      System.exit(-1);

    /* ORIGINAL FILE INPUT STREAM v2.0 SETUP FOR SPECIFIED FILE */
    stmT_file_in_org = Lexical.setup(br_file_in_org);

    if(stmT_file_in_org == null)
      System.exit(-1);

    /* INPUT CONTROL */    
    // => LEXICAL AND SYNTAX ANALYZER   
    Syntax.parse(stmT_file_in_org);
    
    System.out.println("\n Program exiting . . . ");
    System.exit(1);
  } // method main
} // class Prog2

