Example #1
0
 def eval(self, st):
     func_args, func_body = st.get(self.value)
     if len(func_args) != len(self.children):
         raise ValueError('Unmatching sizes between defined function args' +
                          f' and calling args ({len(func_args)} -- ' +
                          f'{len(self.children)})')
     inner_st = SymbolTable(father=st)
     inner_st.set(self.value, None)  # default return value
     for key, value in zip(func_args, self.children):
         inner_st.set(key, value.eval(st))
     func_body.eval(inner_st)
     return inner_st.get(self.value)
def main():

    table = SymbolTable()

    table.put(LetterGrade("A+"), 4.33)
    table.put(LetterGrade("A "), 4.00)
    table.put(LetterGrade("A-"), 3.67)
    table.put(LetterGrade("B+"), 3.33)
    table.put(LetterGrade("B "), 3.00)
    table.put(LetterGrade("B-"), 2.67)
    table.put(LetterGrade("C+"), 2.33)
    table.put(LetterGrade("C "), 2.00)
    table.put(LetterGrade("C-"), 1.67)
    table.put(LetterGrade("D "), 1.00)
    table.put(LetterGrade("F "), 0.00)

    for key in table.key_list():
        print(key.letter + key.extent, table.get(key))