示例#1
0
 def token_pow(self, result):
     result = self.token_un(result)
     hold = TTree()
     while self.token != 'end' and (self.token == '^'):
         self.get_token()
         hold = self.token_brackets(hold)
         result = TTree(result, '^', hold)
     return result
示例#2
0
 def token_and(self, result):
     result = self.token_not(result)
     hold = TTree()
     while not self.token == 'end' and self.token == 'and':
         self.get_token()
         hold = self.token_not(hold)
         result = TTree(result, 'and', hold)
     return result
示例#3
0
 def token_mul(self, result):
     result = self.token_pow(result)
     hold = TTree()
     while self.token != 'end' and (self.token == '*' or self.token == '/'):
         sign = self.token
         self.get_token()
         hold = self.token_pow(hold)
         result = TTree(result, sign, hold)
     return result
示例#4
0
 def token_add(self, result):
     result = self.token_mul(result)
     hold = TTree()
     while not self.token == 'end' and (
             self.token == '+' or self.token == '-' or self.token == '>' or
             self.token == '<' or self.token == '>=' or self.token == '<='
             or self.token == '<>' or self.token == '='):
         sign = self.token
         self.get_token()
         hold = self.token_mul(hold)
         result = TTree(result, sign, hold)
     return result
示例#5
0
 def token_not(self, result):
     sign = self.token
     if (self.token_type == 'delimiter') and sign == 'not':
         self.get_token()
     result = self.token_add(result)
     if sign == 'not':
         result = TTree(sign, result)
     return result
示例#6
0
 def parse_return(self):
     if len(self.current_block_name) == 0 or self.is_begin_block is False:
         self.say_error('def_domain_err')
     # Считываем выражение
     exp = self.get_exp(TTree())
     self.domain_list[len(self.domain_list) - 1].set_result(exp)
     if self.token != 'eol':
         self.say_error('syntax_err')
示例#7
0
 def token_un(self, result):
     sign = self.token
     if (self.token_type == 'delimiter') and (sign == '+' or sign == '-'):
         self.get_token()
     result = self.token_brackets(result)
     if sign == '+' or sign == '-':
         result = TTree(sign, result)
     return result
示例#8
0
 def token_func(self, result):
     fun_token = self.token
     hold = TTree()
     hold1 = TTree()
     self.get_token()
     if self.token == 'end' or self.token != '(':
         self.say_error('syntax_err')
     self.get_token()
     result = self.token_add(result)
     i = self.find_domain_name(fun_token)
     if i != -1:
         # Обработка вызова функции, описывающей подобласть
         if self.token != ',':
             self.say_error('syntax_err')
         self.get_token()
         hold = self.token_add(hold)  # Аргумент y
         if self.token == ',':
             self.get_token()
             hold1 = self.token_add(hold1)  # Аргумент z
         if self.token != ')':
             self.say_error('syntax_err')
         arg_list = list(self.domain_list[i].arguments.keys())
         x = self.domain_list[i].arguments[arg_list[0]]
         y = self.domain_list[i].arguments[arg_list[1]]
         if len(arg_list) > 2:
             z = self.domain_list[i].arguments[arg_list[2]]
         else:
             z = TTree()
         result = TTree(self.domain_list[i].result, x, y, z, result, hold,
                        hold1)
     else:
         if self.token == ',':
             self.get_token()
             hold = self.token_add(hold)
         result = TTree(fun_token, result, hold)
     if self.token != ')':
         self.say_error('syntax_err')
     return result
示例#9
0
 def assignment(self):
     if self.is_begin_block is False or len(self.current_block_name) == 0:
         self.say_error('def_domain_err')
     # Считываем имя переменной
     self.get_token()
     name = self.token
     if name in self.domain_list[len(self.domain_list) - 1].arguments:
         self.say_error('assign_err')
     self.get_token()
     if self.token != '=':
         self.say_error('syntax_err')
     # Считываем выражение
     exp = self.get_exp(TTree())
     if name in self.domain_list[len(self.domain_list) - 1].variables:
         self.domain_list[len(self.domain_list) - 1].set_variable(name, exp)
     else:
         self.domain_list[len(self.domain_list) - 1].add_variable(name, exp)
     if self.token != 'eol':
         self.say_error('syntax_err')
示例#10
0
 def token_prim(self, result):
     if self.token_type == 'digit':
         val = float(self.token)
         result = TTree(val)
     elif self.token_type == 'function':
         result = self.token_func(result)
     elif self.token_type == 'variable':
         if self.token in self.domain_list[len(self.domain_list) -
                                           1].arguments:
             result = self.domain_list[len(self.domain_list) -
                                       1].arguments[self.token]
         elif self.token in self.domain_list[len(self.domain_list) -
                                             1].variables:
             result = self.domain_list[len(self.domain_list) -
                                       1].variables[self.token]
         else:
             self.say_error('undef_err')
     else:
         self.say_error('syntax_err')
     self.get_token()
     return result
示例#11
0
 def add_variable(self, name, value=TTree()):
     if name in self.variables:
         raise TException('redefinition_err')
     self.variables.setdefault(name, value)
示例#12
0
 def add_argument(self, name):
     if name in self.arguments:
         raise TException('redefinition_err')
     self.arguments.setdefault(name, TTree())
示例#13
0
 def __init__(self):
     self.name = ''  # Название геометрического объекта
     self.arguments = {}  # Таблица аргументов (координат)
     self.variables = {}  # Таблица переменных
     self.result = TTree(
     )  # Дерево разбора функционального выражения, описывающего object