Vapor Parser and AST
This parser and AST handles both Vapor and Vapor-M programs. Compile your program against the provided JAR file using the "-classpath" option.
To parse a Vapor program:
import cs132.util.ProblemException;
import cs132.vapor.parser.VaporParser;
import cs132.vapor.ast.VaporProgram;
import cs132.vapor.ast.VBuiltIn.Op;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.PrintStream;
...
public static VaporProgram parseVapor(InputStream in, PrintStream err)
throws IOException
{
Op[] ops = {
Op.Add, Op.Sub, Op.MulS, Op.Eq, Op.Lt, Op.LtS,
Op.PrintIntS, Op.HeapAllocZ, Op.Error,
};
boolean allowLocals = true;
String[] registers = null;
boolean allowStack = false;
VaporProgram program;
try {
program = VaporParser.run(new InputStreamReader(in), 1, 1,
java.util.Arrays.asList(ops),
allowLocals, registers, allowStack);
}
catch (ProblemException ex) {
err.println(ex.getMessage());
return null;
}
return program;
}
To parse a Vapor-M program, it's the same thing except:
boolean allowLocals = false;
String[] registers = {
"v0", "v1",
"a0", "a1", "a2", "a3",
"t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
"s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
"t8",
};
boolean allowStack = true;
A Vapor program will never contain the following AST nodes: VVarRef.Register, VMemRef.Stack. A Vapor-M program will never contain the following AST node: VVarRef.Local.