Example #1
0
def test_add_symbol():
    ST = SymbolTable("")
    T = FastRBTree()

    Content = {'Type': "int" , 'Attribute': None , 'TokenLocation': (10,2) }
    ST.InsertSymbol("age", Content)
    T.insert("age", Content)

    Content = {'Type': "float" , 'Attribute': 'static' , 'TokenLocation': (11,2) }
    ST.InsertSymbol("temperature", Content)
    T.insert("temperature", Content)

    Content = {'Type': "char" , 'Attribute': 'const' , 'TokenLocation': (12,2) }
    ST.InsertSymbol("letter", Content)
    T.insert("letter", Content)

    keys = ST.TopScope.keys()
    for key in keys:
        assert(T.__contains__(key))
        assert(T.get(key) == ST.TopScope.get(key))
        assert(T.get(key) is not ST.TopScope.get(key))

    #write test to prove that the returned item is a pointer

    return
Example #2
0
def test_find_in_table():
    ST = SymbolTable("")

    Content1 = {'Type': "int" , 'Attribute': 'static' , 'TokenLocation': (10,2) }
    ST.InsertSymbol("age", Content1)
    ST.PushNewScope();
    Content2 = {'Type': "float" , 'Attribute': None , 'TokenLocation': (11,2) }
    ST.InsertSymbol("temperature", Content2)
    ST.PushNewScope();
    Content3 = {'Type': "char" , 'Attribute': None , 'TokenLocation': (13,2) }
    ST.InsertSymbol("letter", Content3)
    ST.PushNewScope();

    assert( ST.FindSymbolInTable("letter")[0] == {1: Content3} )
    assert( ST.FindSymbolInTable("temperature")[0] == {2: Content2} )

    assert( (ST.FindSymbolInTable("age")[0] is {3: Content1}) == False )

    #nonexistent symbol case
    assert( ST.FindSymbolInTable("foo") == False )

    #searcing in current scope case
    assert( ST.FindSymbolInCurrentScope("age") == False )

    return
Example #3
0
def test_write_symbol_table():
    ST = SymbolTable("")
    ST.DebugMode = True

    Content1 = {'Type': "int" , 'Attribute': 'static' , 'TokenLocation': (10,2) }
    ST.InsertSymbol("age", Content1)
    ST.PushNewScope();
    Content2 = {'Type': "float" , 'Attribute': None , 'TokenLocation': (11,2) }
    ST.InsertSymbol("temperature", Content2)
    Content2 = {'Type': "float" , 'Attribute': 'static' , 'TokenLocation': (12,2) }
    ST.InsertSymbol("t2", Content2)
    ST.PushNewScope();
    Content3 = {'Type': "char" , 'Attribute': None , 'TokenLocation': (13,2) }
    ST.InsertSymbol("letter", Content3)
    ST.PushNewScope();

    ST.WriteSymbolTableToFile("Debug.out")
Example #4
0
def test_find_in_current_scope():
    ST = SymbolTable("")

    Content = {'Type': "int" , 'Attribute': None , 'TokenLocation': (10,2) }
    ST.InsertSymbol("age", Content)

    assert( ST.FindSymbolInCurrentScope("age") == Content )

    Content = {'Type': "float" , 'Attribute': 'const' , 'TokenLocation': (11,2) }
    ST.InsertSymbol("temperature", Content)

    assert( ST.FindSymbolInCurrentScope("temperature") == Content )

    Content = {'Type': "char" , 'Attribute': None , 'TokenLocation': (12,2) }
    ST.InsertSymbol("letter", Content)

    assert( ST.FindSymbolInCurrentScope("letter") == Content )

    #nonexistent symbol case
    assert( ST.FindSymbolInCurrentScope("foo") == False )


    return