|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectfi.hu.cs.titokone.Compiler
This class knows everything about the relation between symbolic code and binary code. It can transform a full source to binary or one symbolic command to binary or vice versa. Empty out all compiler commands and empty lines at the start of round 2.
Field Summary | |
private java.util.Vector |
code
This array contains the code. |
private MemoryLine[] |
codeMemoryLines
This field holds the Memoryline objects for the code. |
private int |
commandLineCount
This field counts the number of actual command lines found during the first round. |
private CompileDebugger |
compileDebugger
This field contains the CompileDebugger instance to inform of any compilation happenings. |
private boolean |
compileFinished
This value tells if all the lines are processed twice and getApplication can be run. |
private java.lang.String[] |
data
This array contains the data. |
private MemoryLine[] |
dataMemoryLines
This field holds the Memoryline objects for the data area. |
private java.lang.String |
defStdin
This field holds the value of Stdin if it was set with DEF command. |
private java.lang.String |
defStdout
This field holds the value of Stdout if it was set with DEF command. |
private int |
EMPTY
|
private boolean |
firstRound
This field keeps track of whether we are in the first round of compilation or the second. |
private java.util.HashMap |
invalidLabels
This field holds the invalid values to be introduced (i.e. |
private int |
MAXINT
Maximum value of the EQU and DC. |
private int |
MININT
Minimum value of the EQU and DC. |
private int |
nextLine
This field tells the next line to be checked. |
private int |
NOTVALID
|
private java.lang.String[] |
source
This field contains the source code as a String array. |
private SymbolicInterpreter |
symbolicInterpreter
This field contains the SymbolicInterpreter instance to use as part of the compilation. |
private java.util.HashMap |
symbols
This field holds the declared variables, labels and other symbols. |
private java.util.Vector |
symbolTable
This field acts as a symboltable, it is a String array vector where 1:st position holds the name of the symbol and the second either it's value (label, equ) or the command (ds 10, dc 10) |
private java.lang.String |
VALIDLABELCHARS
This field holds all the valid symbols on a label. |
Constructor Summary | |
Compiler()
This constructor sets up the class. |
Method Summary | |
void |
compile(java.lang.String source)
This function initializes transforms a symbolic source code into an application class. |
CompileInfo |
compileLine()
This function goes through one line of the code. |
private CompileInfo |
firstRoundProcess(java.lang.String line)
This function gathers new symbol information from the given line and checks its syntax. |
Application |
getApplication()
This method returns the readily-compiled application if the compilation is complete, or null otherwise. |
MemoryLine |
getSymbolicAndBinary(int binary)
This function transforms a binary command number to a MemoryLine containing both the binary and the symbolic command corresponding to it. |
MemoryLine |
getSymbolicAndBinary(MemoryLine binaryOnly)
This function transforms a MemoryLine containing only the binary command to a MemoryLine containing both the binary and the symbolic command corresponding to it. |
private CompileInfo |
initializeSecondRound()
This method initializes the code and data area arrays for the second round processing according to the dataAreaSize and commandLineCount variables. |
java.lang.String[] |
parseCompilerCommandLine(java.lang.String line)
This function tries to find a compiler command from the line. |
java.lang.String[] |
parseLine(java.lang.String symbolicOpcode)
This method parses a String and tries to find a label, opCode and all the other parts of a Command line. |
private CompileInfo |
secondRoundProcess(java.lang.String line)
This function transforms any commands to binary and stores both forms in the code array, or sets any initial data values in the data array. |
private boolean |
validLabelName(java.lang.String labelName)
This method tests whether a label name contains at least one non-number and consists of 0-9, A-Ö and _. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private java.lang.String[] source
private java.util.HashMap symbols
private java.util.HashMap invalidLabels
private int nextLine
private final java.lang.String VALIDLABELCHARS
private final int NOTVALID
private final int EMPTY
private final int MAXINT
private final int MININT
private java.lang.String defStdin
private java.lang.String defStdout
private boolean firstRound
private int commandLineCount
private java.util.Vector code
private java.util.Vector symbolTable
private java.lang.String[] data
private MemoryLine[] codeMemoryLines
private MemoryLine[] dataMemoryLines
private boolean compileFinished
private CompileDebugger compileDebugger
private SymbolicInterpreter symbolicInterpreter
Constructor Detail |
public Compiler()
Method Detail |
public void compile(java.lang.String source)
source
- The symbolic source code to be compiled.public CompileInfo compileLine() throws TTK91CompileException
TTK91CompileException
- If a) there is a syntax error
during the first round of checking (error code 101) or b) a
symbol is still undefined after the first round of compilation
is finished.public Application getApplication() throws java.lang.IllegalStateException
java.lang.IllegalStateException
public MemoryLine getSymbolicAndBinary(int binary)
binary
- The command to be translated as binary.
public MemoryLine getSymbolicAndBinary(MemoryLine binaryOnly)
binaryOnly
- A MemoryLine containing the binary only of the
command to be translated as binary. If the MemoryLine contains
both, the pre-set symbolic value is ignored.
private CompileInfo firstRoundProcess(java.lang.String line) throws TTK91CompileException
line
- The line of code to process.
TTK91CompileException
private CompileInfo initializeSecondRound()
private CompileInfo secondRoundProcess(java.lang.String line) throws TTK91CompileException
line
- The line of code to process.
TTK91CompileException
public java.lang.String[] parseLine(java.lang.String symbolicOpcode) throws TTK91CompileException
symbolicOpcode
- Symbolic form of an operation code.
TTK91CompileException
public java.lang.String[] parseCompilerCommandLine(java.lang.String line) throws TTK91CompileException
line
- String representing one line from source code.
TTK91CompileException
private boolean validLabelName(java.lang.String labelName)
labelName
- The label name to test.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |