def typecheck(
     self,
     state: "TypeChecker.TypecheckingState" = None
 ) -> List[Tuple[TypeChecker.Types, str]]:
     if state is None:
         return self.typecheck(TypeChecker.TypecheckingState())
     if self.__next is None:
         val = TypeChecker.Types(self.__identifier_type)
         try:
             state.lookup_variable(str(self.__identifier))
             super().typecheckException(
                 "TYPECHECK ERROR: Variable {0} already defined".format(
                     str(self.__identifier)))
         except TypeChecker.TypecheckingStateException:
             state.bind_variable(str(self.__identifier), val)
         val = (val, str(self.__identifier))
         return [val]
     val = self.__next.typecheck(state)
     val2 = TypeChecker.Types(self.__identifier_type)
     try:
         state.lookup_variable(str(self.__identifier))
         super().typecheckException(
             "TYPECHECK ERROR: Variable {0} already defined".format(
                 str(self.__identifier)))
     except TypeChecker.TypecheckingStateException:
         state.bind_variable(str(self.__identifier), val2)
     val2 = (val2, str(self.__identifier))
     val.insert(0, val2)
     return val
Пример #2
0
 def typecheck(self, state: "TypeChecker.TypecheckingState" = None) -> TypeChecker.Types:
     if state is None:
         return self.typecheck(TypeChecker.TypecheckingState())
     try:
         state.lookup_variable(str(self.__identifier))
         super().typecheckException(
             "TYPECHECK ERROR: Variable '{0}' already declared".format(str(self.__identifier)))
     except TypeChecker.TypecheckingStateException:
         state.bind_variable(str(self.__identifier), TypeChecker.Types(self.__variable_type))
     return TypeChecker.Types(self.__variable_type)  # type is string
Пример #3
0
 def typecheck(self, state: "TypeChecker.TypecheckingState" = None) -> TypeChecker.Types:
     if state is None:
         return self.typecheck(TypeChecker.TypecheckingState())
     state.enter_scope()
     ret_type = TypeChecker.Types(self.__return_type)
     if self.__params is not None:
         self.__params = self.__params.typecheck(state)
     else:
         self.__params = list()
     try:
         state.lookup_function(str(self.__identifier))
         super().typecheckException("TYPECHECK EXCEPTION: Function with same name already declared")
     except TypeChecker.TypecheckingStateException:
         state.bind_function(str(self.__identifier), (ret_type, self.__params, self.__body, super().get_line(), super().get_column()))
     state.exit_scope()
     return ret_type