/* * Name: Mike Cifelli * Course: CIS 443 - Programming Languages * Assignment: Lisp Parser */ package main; import parser.*; import error.ErrorManager; import java.io.*; /** * LispParserDriver is a program that takes the name of a file * as a command-line argument, creates an internal representation of the * S-expressions found in the file and prints them to the console. If no file * name is provided at the command-line, this program will read from standard * input. */ public class LispParserDriver { /** * Create internal representations of the S-expressions found in the file * whose name was given as a command-line argument and print them to the * console. If no file name was given, retrieve the S-expressions from * standard input. * * @param args * the command-line arguments: * */ public static void main(String[] args) { LispParser parser = null; if (args.length > 0) { // a file name was given at the command-line, attempt to create a // 'LispParser' on it try { parser = new LispParser(new FileInputStream(args[0]), args[0]); } catch (FileNotFoundException e) { ErrorManager.generateError(e.getMessage(), ErrorManager.CRITICAL_LEVEL); } } else { // no file name was given, create a 'LispParser' on standard input parser = new LispParser(System.in, "System.in"); } while (! parser.eof()) { try { SExpression sexpr = parser.getSExpr(); System.out.println(sexpr.toString()); } catch (RuntimeException e) { ErrorManager.generateError(e.getMessage(), 2); } catch (IOException e) { ErrorManager.generateError(e.getMessage(), ErrorManager.CRITICAL_LEVEL); } } } }