Added object filename option to Compiler

java11
Sandy Brownlee 2 years ago
parent 6820b55cf1
commit 11be265081
  1. 23
      Triangle.Compiler/src/main/java/triangle/Compiler.java

@ -33,6 +33,8 @@ public class Compiler {
/** The filename for the object program, normally obj.tam. */
static String objectName = "obj.tam";
static boolean showTree = false;
private static Scanner scanner;
private static Parser parser;
@ -114,16 +116,29 @@ public class Compiler {
public static void main(String[] args) {
if (args.length < 1) {
System.out.println("Usage: tc filename [tree]");
System.out.println("Usage: tc filename [-o=outputfilename] [tree]");
System.exit(1);
}
parseArgs(args);
String sourceName = args[0];
boolean tree = (args.length > 1 && args[1].equalsIgnoreCase("tree"));
var compiledOK = compileProgram(sourceName, objectName, tree, false);
var compiledOK = compileProgram(sourceName, objectName, showTree, false);
if (!tree) {
if (!showTree) {
System.exit(compiledOK ? 0 : 1);
}
}
private static void parseArgs(String[] args) {
for (String s : args) {
var sl = s.toLowerCase();
if (sl.equals("tree")) {
showTree = true;
} else if (sl.startsWith("-o=")) {
objectName = s.substring(3);
}
}
}
}