refines class Main {
    protected static void usage() {
        System.err.println("Usage: java " + $str($TEqn) +
	       ".Main [-f file]");
        System.err.println("       -f for input from file");
        System.exit(-10);
    }

    public static void main(String args[]) {
        int     argc    = args.length;
        int                non_switch_args;
        int                i, j;
        char               ch;
        AstProperties props;
        BaliParser         myParser = null;
        AstNode       root;
        PrintWriter        pw;
        String             line;     // one line from the user
        String             input;    // one Language command (terminated with line ".")
        ByteArrayInputStream is;     // is and dis are used together
        DataInputStream      dis;    // to "feed" the scanner.
        BufferedReader       userInput = null;

        // Step 1: print the Marquee...

 	Class c = Main.class;
	String s = c.getName();
        int dot = s.indexOf(".");
        String packageName = s.substring(0, dot);
        System.out.println(packageName + " Started...");

        // Step 2: a general routine to pick off command line options
        //         options are removed from command line and
        //         args array is adjusted accordingly.

   
        non_switch_args = 0;
        for (i=0; i < argc; i++) {
            if (args[i].charAt(0) == '-') {

            // switches of form -xxxxx (where xxx is a sequence of 1
            // or more characters

               for (j=1; j < args[i].length(); j++) {
                  if (args[i].charAt(j) == 'f') {
                     try {
                        userInput =
                           new BufferedReader(new FileReader(args[i+1]));
                     }
                     catch (Exception e) {
                        System.err.println("File " + args[i+1] + " not found:" 
+ e.getMessage());
                     }
                     i++;
                     break;
                  }
                  else
                     usage();
                 }
               }
             else {
                // non-switch arg
                args[non_switch_args] = args[i];
                non_switch_args++;
            }
         }

         // Step 3: there must be at least one real argument, otherwise error

         if (non_switch_args != 0)    usage();

         // Step 4: Initialize output stream
         //         Standard initialization stuff that should be
	 //         platform independent.

         props = new AstProperties();
         String lineSeparator =
            System.getProperties().getProperty("line.separator");
         if (lineSeparator.compareTo("\n") != 0)
            pw = new PrintWriter(new FixDosOutputStream(System.out));
         else
            pw = new PrintWriter(System.out);
         props.setProperty("output", pw);
 
         // Step 5: Get input and parse until an empty line is entered.
         //         An empty line is something with "." only.


         if (userInput == null)
            userInput = new BufferedReader(new InputStreamReader(System.in));
         do {
            // LanguageName statement loop
            input = "";       // initialize input string

            // Step 6.1: print prompt

            System.out.print("\n" + packageName + "> ");
            System.out.flush();

            // Step 5.2: collect in variable input over multiple line reads
            do {
               line = "";
               try {
                  line = userInput.readLine();
               }
               catch (Exception e) {
                  System.exit(10);
               }
               if (line == null) break;
               if (line.compareTo("") == 0)
                  continue;
               if (line.compareTo(".") == 0)
                  break;
               input += "\n" + line;
               System.out.print(" > ");
               System.out.flush();
            } while (true);

            if (input == "")
               break;

            // Step 5.3: parse input string

            is  = new ByteArrayInputStream(input.getBytes());
            dis = new DataInputStream(is);
            if (myParser == null)
               myParser = new BaliParser(dis);
            else
               myParser.ReInit(dis);

            try {
               root = Parser.getStartRoot(myParser);
            }
            catch (Throwable e) {
               System.out.println("Parsing Exception Thrown: " +
                  e.getMessage());
            e.printStackTrace();
               continue;     // go to next $(LanguageName) statement
            }
 

            // Step 5.4: Parse of input command succeeded!