Пример #1
0
 def parse_exp(cls):
     try:
         node = Node(Node.EXP)
         node.set_data_type(Token.LOGIC_EXP)
         left_node = cls.parse_multi_term_exp()
         if cls.get_next_token().get_type() in [Token.GT, Token.GET, Token.LT, Token.LET, Token.EQ, Token.NEQ]:
             node.set_left(left_node)
             node.set_middle(cls.parse_logic_op())
             node.set_right(cls.parse_multi_term_exp())
             return node
         return left_node
     except ErrorParse(cls.get_next_token().get_line_num(), cls.get_next_token().get_type()) as e:
         print e.content
Пример #2
0
 def parse_term_exp(cls):
     try:
         node = Node(Node.EXP)
         node.set_data_type(Token.TERM_EXP)
         left_node = cls.parse_factor()
         if cls.get_next_token().get_type() in [Token.MUL, Token.DIV]:
             node.set_left(left_node)
             node.set_middle(cls.parse_mul_div_op())
             node.set_right(cls.parse_term_exp())
             return node
         return left_node
     except ErrorParse(cls.get_next_token().get_line_num(), cls.get_next_token().get_type()) as e:
         print e.content
Пример #3
0
 def parse_term_exp(cls):
     try:
         node = Node(Node.EXP)
         node.set_data_type(Token.TERM_EXP)
         left_node = cls.parse_factor()
         if cls.get_next_token().get_type() in [Token.MUL, Token.DIV]:
             node.set_left(left_node)
             node.set_middle(cls.parse_mul_div_op())
             node.set_right(cls.parse_term_exp())
             return node
         return left_node
     except ErrorParse(cls.get_next_token().get_line_num(), cls.get_next_token().get_type()) as e:
         print e.content
Пример #4
0
 def parse_exp(cls):
     try:
         node = Node(Node.EXP)
         node.set_data_type(Token.LOGIC_EXP)
         left_node = cls.parse_multi_term_exp()
         if cls.get_next_token().get_type() in [Token.GT, Token.GET, Token.LT, Token.LET, Token.EQ, Token.NEQ]:
             node.set_left(left_node)
             node.set_middle(cls.parse_logic_op())
             node.set_right(cls.parse_multi_term_exp())
             return node
         return left_node
     except ErrorParse(cls.get_next_token().get_line_num(), cls.get_next_token().get_type()) as e:
         print e.content
Пример #5
0
 def parse_if_stmt(cls):
     try:
         node = Node(Node.IF_STMT)
         cls.read_token(Token.IF)
         cls.read_token(Token.LPARENT)
         node.set_left(cls.parse_exp())
         cls.read_token(Token.RPARENT)
         node.set_middle(cls.switch_stmt())
         if cls.iterator.has_next() and cls.get_next_token().get_type() == Token.ELSE:
             cls.read_token(Token.ELSE)
             node.set_right(cls.switch_stmt())
         return node
     except ErrorParse(cls.get_next_token().get_line_num(), cls.get_next_token().get_type()) as e:
         print e.content
Пример #6
0
 def parse_if_stmt(cls):
     try:
         node = Node(Node.IF_STMT)
         cls.read_token(Token.IF)
         cls.read_token(Token.LPARENT)
         node.set_left(cls.parse_exp())
         cls.read_token(Token.RPARENT)
         node.set_middle(cls.switch_stmt())
         if cls.iterator.has_next() and cls.get_next_token().get_type() == Token.ELSE:
             cls.read_token(Token.ELSE)
             node.set_right(cls.switch_stmt())
         return node
     except ErrorParse(cls.get_next_token().get_line_num(), cls.get_next_token().get_type()) as e:
         print e.content
Пример #7
0
 def parse_multi_term_exp(cls):
     try:
         node = Node(Node.EXP)
         node.set_data_type(Token.MULTI_TERM_EXP)
         left_node = cls.parse_term_exp()
         next_token_type = cls.get_next_token().get_type()
         if next_token_type == Token.PLUS:
             node.set_left(left_node)
             node.set_middle(cls.parse_add_minus_op())
             node.set_right(cls.parse_multi_term_exp())
         elif next_token_type == Token.MINUS:
             node.set_left(left_node)
             node.set_middle(Node(Node.OP, m_data_type=Token.PLUS))
             node.set_right(cls.parse_multi_term_exp())
         else:
             return left_node
         return node
     except ErrorParse(cls.get_next_token().get_line_num(), cls.get_next_token().get_type()) as e:
         print e.content
Пример #8
0
 def parse_multi_term_exp(cls):
     try:
         node = Node(Node.EXP)
         node.set_data_type(Token.MULTI_TERM_EXP)
         left_node = cls.parse_term_exp()
         next_token_type = cls.get_next_token().get_type()
         if next_token_type == Token.PLUS:
             node.set_left(left_node)
             node.set_middle(cls.parse_add_minus_op())
             node.set_right(cls.parse_multi_term_exp())
         elif next_token_type == Token.MINUS:
             node.set_left(left_node)
             node.set_middle(Node(Node.OP, m_data_type=Token.PLUS))
             node.set_right(cls.parse_multi_term_exp())
         else:
             return left_node
         return node
     except ErrorParse(cls.get_next_token().get_line_num(), cls.get_next_token().get_type()) as e:
         print e.content