Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- public class SymbolTable{
- //stack of symbols woman
- //stack of array list of symbols
- //ArrayList <Symbol> symbolList;
- private Stack<ArrayList<Symbol>> symbolTable;
- public SymbolTable(){
- //symbolList = new ArrayList<Symbol>();
- symbolTable = new Stack<ArrayList<Symbol>>();
- }
- public void pushScope(){
- ArrayList<Symbol> s = new ArrayList<Symbol>();
- symbolTable.push(s);
- }
- public ArrayList<Symbol> popScope(){
- return symbolTable.pop();
- }
- public boolean insertSymbol(Symbol s){
- // boolean flag = false;
- //first check to see if the array list, peek on the top of stack
- //see if that array List contains the symbol
- ArrayList<Symbol> symbols = symbolTable.peek();
- for (Symbol s1 : symbols){
- if (s1.equals(s))
- return true;
- }
- symbols.add(s);
- return false;
- //redifined error
- }
- public void updateValue(Value val)
- {
- //save the pop of the stack
- ArrayList <Symbol> temp = symbolTable.pop();
- symbolTable.peek().get(symbolTable.peek().size()-1).updateValue(val);
- symbolTable.push(temp);
- }
- public void printTable(PrintStream outFile)
- {
- int depth = 0;
- for (ArrayList<Symbol> scope : symbolTable) {
- String indentation = new String();
- for (int i=0; i<depth; i++)
- indentation += " ";
- for (Symbol symbol : scope)
- outFile.println( indentation + symbol );
- depth++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement