Package rs.etf.pp1.symboltable.concepts

Examples of rs.etf.pp1.symboltable.concepts.Scope


   * cvorovu umecu u hes tabelu.
   */
  public static void init() {
    Scope universe = currentScope = new Scope(null);
   
    universe.addToLocals(new Obj(Obj.Type, "int", intType));
    universe.addToLocals(new Obj(Obj.Type, "char", charType));
    universe.addToLocals(new Obj(Obj.Con, "eol", charType, 10, 0));
    universe.addToLocals(new Obj(Obj.Con, "null", nullType, 0, 0));
   
    universe.addToLocals(chrObj = new Obj(Obj.Meth, "chr", charType, 0, 1));
    {
      openScope();
      currentScope.addToLocals(new Obj(Obj.Var, "i", intType, 0, 1));
      chrObj.setLocals(currentScope.getLocals());
      closeScope();
    }
   
    universe.addToLocals(ordObj = new Obj(Obj.Meth, "ord", intType, 0, 1));
    {
      openScope();
      currentScope.addToLocals(new Obj(Obj.Var, "ch", charType, 0, 1));
      ordObj.setLocals(currentScope.getLocals());
      closeScope();
    }
   
   
    universe.addToLocals(lenObj = new Obj(Obj.Meth, "len", intType, 0, 1));
    {
      openScope();
      currentScope.addToLocals(new Obj(Obj.Var, "arr", new Struct(Struct.Array, noType), 0, 1));
      lenObj.setLocals(currentScope.getLocals());
      closeScope();
    }
   
    currentLevel = -1;
View Full Code Here


   * tabele simbola, ako je doslo do greske jer smo pokusali da u tabelu simbola
   * za opseg ubacimo cvor sa imenom koje vec postoji.
   */
  public static Obj insert(int kind, String name, Struct type) {
    // create a new Object node with kind, name, type
    Obj newObj = new Obj(kind, name, type, 0, ((currentLevel != 0)? 1 : 0));
   
    // append the node to the end of the symbol list
    if (!currentScope.addToLocals(newObj)) {
      Obj res = currentScope.findSymbol(name);
      return (res != null) ? res : noObj;
    }
    else
      return newObj;
  }
View Full Code Here

   * najugnezdenijeg opsega, pa redom kroz opsege na nizim nivoima. Povratna
   * vrednost: - pronadjeni Obj cvor, ako je pretrazivanje bilo uspesno. -
   * Tab.noObj objekat, ako je pretrazivanje bilo neuspesno.
   */
  public static Obj find(String name) {
    Obj resultObj = null;
    for (Scope s = currentScope; s != null; s = s.getOuter()) {
      if (s.getLocals() != null) {
        resultObj = s.getLocals().searchKey(name);
        if (resultObj != null) break;
      }
View Full Code Here

    return hashTable.get(key);
  }

  @Override
  public boolean deleteKey(String key) {
    Obj o = null;
    if (hashTable.containsKey(key)) {
      o = hashTable.remove(key);
    }
    return !hashTable.containsKey(key) && (o != null);
  }
View Full Code Here

   * Inicijalizacija universe opsega, tj. njegovo popunjavanje Obj cvorovima,
   * kao sto je izlozeno na vezbama i predavanjima. Razlika je sto se Obj
   * cvorovu umecu u hes tabelu.
   */
  public static void init() {
    Scope universe = currentScope = new Scope(null);
   
    universe.addToLocals(new Obj(Obj.Type, "int", intType));
    universe.addToLocals(new Obj(Obj.Type, "char", charType));
    universe.addToLocals(new Obj(Obj.Con, "eol", charType, 10, 0));
    universe.addToLocals(new Obj(Obj.Con, "null", nullType, 0, 0));
   
    universe.addToLocals(chrObj = new Obj(Obj.Meth, "chr", charType, 0, 1));
    {
      openScope();
      currentScope.addToLocals(new Obj(Obj.Var, "i", intType, 0, 1));
      chrObj.setLocals(currentScope.getLocals());
      closeScope();
    }
   
    universe.addToLocals(ordObj = new Obj(Obj.Meth, "ord", intType, 0, 1));
    {
      openScope();
      currentScope.addToLocals(new Obj(Obj.Var, "ch", charType, 0, 1));
      ordObj.setLocals(currentScope.getLocals());
      closeScope();
    }
   
   
    universe.addToLocals(lenObj = new Obj(Obj.Meth, "len", intType, 0, 1));
    {
      openScope();
      currentScope.addToLocals(new Obj(Obj.Var, "arr", new Struct(Struct.Array, noType), 0, 1));
      lenObj.setLocals(currentScope.getLocals());
      closeScope();
View Full Code Here

 
  /**
   * Otvaranje novog opsega
   */
  public static void openScope() {
    currentScope = new Scope(currentScope);
    currentLevel++;
  }
View Full Code Here

   
   
    universe.addToLocals(lenObj = new Obj(Obj.Meth, "len", intType, 0, 1));
    {
      openScope();
      currentScope.addToLocals(new Obj(Obj.Var, "arr", new Struct(Struct.Array, noType), 0, 1));
      lenObj.setLocals(currentScope.getLocals());
      closeScope();
    }
   
    currentLevel = -1;
View Full Code Here

  public static SymbolTableFactory instance() {
    return inst;
  }
 
  public SymbolDataStructure createSymbolTableDataStructure() {
    return new HashTableDataStructure();
  }
View Full Code Here

    return numOfFields;
  }

  public SymbolDataStructure getMembers() {
    if (members == null)
      members = new HashTableDataStructure();
    return members;
  }
View Full Code Here

  }
 
  public static void dump(SymbolTableVisitor stv) {
    System.out.println("=====================SYMBOL TABLE DUMP=========================");
    if (stv == null)
      stv = new DumpSymbolTableVisitor();
    for (Scope s = currentScope; s != null; s = s.getOuter()) {
      s.accept(stv);
    }
    System.out.println(stv.getOutput());
  }
View Full Code Here

TOP

Related Classes of rs.etf.pp1.symboltable.concepts.Scope

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.