package main;

import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.ArrayList;
import java.util.List;

import com.beust.jcommander.JCommander;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.ParameterException;
import java_cup.runtime.Symbol;
import parse.Lexer;
import parse.SymbolConstants;

import static error.ErrorManager.em;

// command line options
class DriverOptions {
   @Parameter(description = "<source file>")
   public List<String> parameters = new ArrayList<>();

   @Parameter(names = {"--help", "-h"}, description = "Usage help", help = true)
   public boolean help = false;

   @Parameter(names = {"--lexer"}, description = "Lexical analysis")
   public boolean lexer = true;
}

// main
public class Driver {

   public static void main(String[] args) {
      // parse command line options
      DriverOptions options = new DriverOptions();
      JCommander jCommander = new JCommander(options);
      jCommander.setProgramName("Driver");

      try {
         jCommander.parse(args);
      }
      catch (ParameterException e) {
         System.out.println(e.getMessage());
         jCommander.usage();
         System.exit(1);
      }

      if (options.help) {
         jCommander.usage();
         return;
      }

      Reader input = null;
      try {
         // set the input (source code) to compile
         if (options.parameters.isEmpty())
            input = new InputStreamReader(System.in);
         else
            input = new FileReader(options.parameters.get(0));

         // do only lexical analyses
         if (options.lexer)
            lexicalAnalysis(input);

         em.summary();
      }
      catch (IOException e) {
         System.out.println(e.getMessage());
         System.exit(2);
      }
      finally {
         // closes the input file
         if (input instanceof FileReader)
            try {
               input.close();
            }
            catch (IOException e) {
               System.out.println(e.getMessage());
               System.exit(3);
            }
      }
   }

   public static void lexicalAnalysis(Reader input) throws IOException {
      Lexer lexer = new Lexer(input);
      Symbol tok;
      do {
         tok = lexer.next_token();
         System.out.printf("%-55s %-8s %s%n",
                           tok,
                           SymbolConstants.terminalNames[tok.sym],
                           tok.value == null ? "" : tok.value);
      } while (tok.sym != SymbolConstants.EOF);
   }

}

@@ -331,16 +331,46 @@
 Symbol;%0A
+import parse.SymbolConstants;%0A
 import p
@@ -394,31 +394,22 @@
 t parse.
-SymbolConstants
+parser
 ;%0A%0Aimpor
@@ -796,16 +796,120 @@
  lexer =
+ false;%0A%0A   @Parameter(names = %7B%22--parser%22%7D, description = %22Syntax analysis%22)%0A   public boolean parser =
  true;%0A%7D
@@ -1813,24 +1813,126 @@
 is(input);%0A%0A
+         // do only lexical analyses%0A         if (options.parser)%0A            syntaxAnalysis(input);%0A%0A
          em.
@@ -2054,24 +2054,130 @@
 2);%0A      %7D%0A
+      catch (Exception e) %7B%0A         System.out.println(e.getMessage());%0A         System.exit(3);%0A      %7D%0A
       finall
@@ -2424,33 +2424,33 @@
     System.exit(
-3
+4
 );%0A            %7D
@@ -2848,16 +2848,16 @@
 value);%0A
-
       %7D 
@@ -2902,10 +2902,187 @@
 ;%0A   %7D%0A%0A
+   public static void syntaxAnalysis(Reader input) throws Exception %7B%0A      Lexer lexer = new Lexer(input);%0A      parser parser = new parser(lexer);%0A      parser.parse();%0A   %7D%0A%0A
 %7D%0A

Add syntax analysis to compiler driver