-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJazSymbolTable.java
52 lines (49 loc) · 1.24 KB
/
JazSymbolTable.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import java.util.Stack;
public class JazSymbolTable {
Instruction[] codeSyntax;
Instruction toReturn;
private Stack ReturnStack;
int tableI, size, returnVal;
JazSymbolTable(){
ReturnStack = new Stack();
size = 200;
codeSyntax = new Instruction[size];
tableI = 0;
returnVal = 0;
}
//return methods
public Instruction getLine() {
toReturn = codeSyntax[tableI];
tableI++;
return toReturn;
}
//functions
public void setTableI(int i) { tableI = i; }
public void initReturnLine(){
ReturnStack.push(tableI); //saves the line number for the destination method to return to
}
public void callReturn(){
//used to return code to original line by tracking what method made the return call
tableI = (int) ReturnStack.pop();
}
public void addCode(Instruction instrIn){
if (tableI <= size);{
codeSyntax[tableI] = instrIn;
tableI++;
}
}
public void findScope(String scopeIn){
tableI = 0;
while (!scopeIn.equals(codeSyntax[tableI].getScope())){
tableI++;
}
}
public void print(){
for (int i = 0; i < tableI; i++){
System.out.println(
"Instruction = " + codeSyntax[i].getInstr() +
" : Parameter = " + codeSyntax[i].getParam() +
": Scope = " + codeSyntax[i].getScope());
}
}
}