|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.adamcornett.cminus.Compiler
public class Compiler
This is the main entry point for the compiler.
| Nested Class Summary | |
|---|---|
private static class |
Compiler.flag
Represents a command line argument or flag |
| Field Summary | |
|---|---|
private static HashMap<String,String> |
args
The set of command line arguments and the values |
static int |
BuildNumber
The automatically generated build number |
static String |
BuildStatus
The build status of the program |
private static String |
className
The class name of the file being compiled |
private static Function |
curFunc
The current function the parser is in, stored to make adding & defining functions easier |
private static Set<String> |
extra_args
The list of files passed via the command line |
private static HashSet<String> |
flags
The collection of set command line flags |
private static FunctionTable |
functions
The function table for the current program |
private static boolean |
inFuncDec
TRUE if the scanner is currently in a function definition,
FALSE otherwise. |
private static int |
lastScopeNumber
This is a hack var to store the last scope number for the parser when it builds the AST. |
private static org.apache.commons.logging.Log |
log
The Commons Log for the class |
private static String |
logFileName
The name of the log file being used |
static String |
MajorVersion
Major version number, pulled from the messages.properties file |
static String |
MinorVersion
Minor version number, pulled from the messages.properties file. |
private static Scope |
rootScope
The root("Global") variable scope |
| Constructor Summary | |
|---|---|
Compiler()
|
|
| Method Summary | |
|---|---|
static void |
addFunction(Function f)
Add a function to the function table. |
static void |
addFunctionCall(org.antlr.runtime.Token t)
When the parser encounters a function call, the ID token is passed to this function. |
private static void |
addIOFunctions()
|
static void |
addSymbol(Symbol s)
Add a symbol to the current scope's symbol table. |
static void |
addSymbolUse(org.antlr.runtime.Token t)
When the parser encounters a variable, it passes the token to this method, where it is added to the symbols use list. |
private static boolean |
compile(org.antlr.runtime.CharStream input)
This is the actual compile method |
static boolean |
compile(File file)
This method compiles a given source file into a Jasmin file. |
static boolean |
compile(InputStream source)
|
static boolean |
compile(String source)
|
static void |
endFuncDec()
Called at the end of a function declaration, used in combination witht he addFunction(Function) method to build a function defintion. |
static int |
enterScope(org.antlr.runtime.Token t)
Creates and pushes a new scope based on the token |
static void |
exitScope()
Called at the end of the scope to go up the scope chain. |
static Function |
findFunction(String text)
Looks for a function in the global function table. |
static String |
getArg(String a)
Returns the value of an argument |
static int |
getLastScopeNumber()
This method provides the tree constructions constructors with the the last scope number. |
protected static void |
init_flags()
Setup all possible command line flags |
protected static void |
init_log()
Setup the log |
static boolean |
isFlag(String f)
Checks if a given flag has been set |
static void |
main(String[] args)
The main method of the program |
static void |
printf(String s,
Object... args)
Makes life easier |
private static void |
printUsage()
Print the information about how to execute the program and the available flags. |
private static void |
printVersion()
Print version and build information |
private static void |
processArgs(String[] args)
Process the command line args array into the flags and args data structures |
static void |
puts(Object o)
A quick wrapper for PrintStream.println(Object) |
private static void |
rebuild()
Recreates the ANTLR parser and lexer |
static void |
setFlag(String string)
Set a flag |
static void |
setLastScopeNumber(int lastScopeNumber)
Sets the last scope number value. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int BuildNumber
public static final String BuildStatus
public static final String MajorVersion
public static final String MinorVersion
private static HashMap<String,String> args
private static String className
private static Function curFunc
private static Set<String> extra_args
private static HashSet<String> flags
private static FunctionTable functions
private static boolean inFuncDec
TRUE if the scanner is currently in a function definition,
FALSE otherwise.
private static int lastScopeNumber
private static org.apache.commons.logging.Log log
private static String logFileName
private static Scope rootScope
| Constructor Detail |
|---|
public Compiler()
| Method Detail |
|---|
public static void addFunction(Function f)
f - The new function to addfunctionspublic static void addFunctionCall(org.antlr.runtime.Token t)
Function.addCall(TokenLocation) method.
t - The ID token of the callpublic static void addSymbol(Symbol s)
s - The symbol to add.Scope.pushScope(Scope)public static void addSymbolUse(org.antlr.runtime.Token t)
t - Symbol.addUse(TokenLocation)
public static boolean compile(File file)
throws IOException,
org.antlr.runtime.RecognitionException
fname - The name of the C-Minus source file
IOException - If the file cannot be opened
org.antlr.runtime.RecognitionException - If there is an error during parsingcompile(CharStream)
public static boolean compile(InputStream source)
throws IOException,
org.antlr.runtime.RecognitionException
source - An input stream representing the source to be compiled
TRUE if the code is compiled without errors,
otherwise FALSE.
IOException - If there is an error reading from the InputStream.
org.antlr.runtime.RecognitionException - If there is an error during compilation.compile(CharStream)
public static boolean compile(String source)
throws IOException,
org.antlr.runtime.RecognitionException
source - A string containing the source to be compiled.
TRUE if the code is compiled without errors,
otherwise FALSE.
IOException - If there is an error reading the string during parsing.
org.antlr.runtime.RecognitionException - Thrown if there is an error during the compilation.compile(CharStream)public static void endFuncDec()
addFunction(Function) method to build a function defintion.
public static int enterScope(org.antlr.runtime.Token t)
t - The token to associated with beginning with the scope
Scope.pushScope(Scope)public static void exitScope()
Scope.popScope()public static Function findFunction(String text)
text - The name of the function.
public static String getArg(String a)
a - The argument name to get the value for
public static int getLastScopeNumber()
exitScope() method gets called.
public static boolean isFlag(String f)
f - The flag to be checked for
f is setpublic static void main(String[] args)
args - execution arguments
public static void printf(String s,
Object... args)
s - The format string.args - The arguments/valuesPrintStream.printf(String, Object...)public static void puts(Object o)
PrintStream.println(Object)
o - The object to printpublic static void setFlag(String string)
string - the name of the flag (without the '--')public static void setLastScopeNumber(int lastScopeNumber)
lastScopeNumber - getLastScopeNumber()private static void addIOFunctions()
private static boolean compile(org.antlr.runtime.CharStream input)
throws IOException,
org.antlr.runtime.RecognitionException
input - The input to use
IOException
org.antlr.runtime.RecognitionExceptionprivate static void printUsage()
private static void printVersion()
private static void processArgs(String[] args)
args - private static void rebuild()
protected static void init_flags()
protected static void init_log()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||