|
|
@ -33,6 +33,8 @@ public class Compiler { |
|
|
|
|
|
|
|
|
|
|
|
/** The filename for the object program, normally obj.tam. */ |
|
|
|
/** The filename for the object program, normally obj.tam. */ |
|
|
|
static String objectName = "obj.tam"; |
|
|
|
static String objectName = "obj.tam"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static boolean showTree = false; |
|
|
|
|
|
|
|
|
|
|
|
private static Scanner scanner; |
|
|
|
private static Scanner scanner; |
|
|
|
private static Parser parser; |
|
|
|
private static Parser parser; |
|
|
@ -114,16 +116,29 @@ public class Compiler { |
|
|
|
public static void main(String[] args) { |
|
|
|
public static void main(String[] args) { |
|
|
|
|
|
|
|
|
|
|
|
if (args.length < 1) { |
|
|
|
if (args.length < 1) { |
|
|
|
System.out.println("Usage: tc filename [tree]"); |
|
|
|
System.out.println("Usage: tc filename [-o=outputfilename] [tree]"); |
|
|
|
System.exit(1); |
|
|
|
System.exit(1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
parseArgs(args); |
|
|
|
|
|
|
|
|
|
|
|
String sourceName = args[0]; |
|
|
|
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); |
|
|
|
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); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|