Example #1
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 #2
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