def parse_declare_stmt(cls): try: node = Node(Node.DECLARE_STMT) var_node = Node(Node.VAR) if cls.get_next_token().get_type() in [Token.INT, Token.DOUBLE]: current_token = cls.iterator.next() data_type = Token.INT if current_token.get_type() == Token.INT else Token.DOUBLE var_node.set_data_type(data_type) else: next_token = cls.get_next_token() raise ErrorParse(next_token.get_line_num(), next_token.get_type()) if cls.get_next_token().get_type() == Token.ID: current_token = cls.iterator.next() var_node.set_value(current_token.get_value()) else: next_token = cls.get_next_token() raise ErrorParse(next_token.get_line_num(), next_token.get_type()) if cls.get_next_token().get_type() == Token.ASSIGN: cls.read_token(Token.ASSIGN) node.set_middle(cls.parse_exp()) elif cls.get_next_token().get_type() == Token.LBRACKET: cls.read_token(Token.LBRACKET) var_node.set_left(cls.parse_exp()) cls.read_token(Token.RBRACKET) cls.read_token(Token.SEMI) node.set_left(var_node) return node except ErrorParse(cls.get_next_token().get_line_num(), cls.get_next_token().get_type()) as e: print e.content
def parse_declare_stmt(cls): try: node = Node(Node.DECLARE_STMT) var_node = Node(Node.VAR) if cls.get_next_token().get_type() in [Token.INT, Token.DOUBLE]: current_token = cls.iterator.next() data_type = Token.INT if current_token.get_type() == Token.INT else Token.DOUBLE var_node.set_data_type(data_type) else: next_token = cls.get_next_token() raise ErrorParse(next_token.get_line_num(), next_token.get_type()) if cls.get_next_token().get_type() == Token.ID: current_token = cls.iterator.next() var_node.set_value(current_token.get_value()) else: next_token = cls.get_next_token() raise ErrorParse(next_token.get_line_num(), next_token.get_type()) if cls.get_next_token().get_type() == Token.ASSIGN: cls.read_token(Token.ASSIGN) node.set_middle(cls.parse_exp()) elif cls.get_next_token().get_type() == Token.LBRACKET: cls.read_token(Token.LBRACKET) var_node.set_left(cls.parse_exp()) cls.read_token(Token.RBRACKET) cls.read_token(Token.SEMI) node.set_left(var_node) return node except ErrorParse(cls.get_next_token().get_line_num(), cls.get_next_token().get_type()) as e: print e.content
def parse_literal(cls): try: if cls.iterator.has_next(): cls.currentToken = cls.iterator.next() current_token_type = cls.currentToken.get_type() node = Node(Node.LITERAL) node.set_data_type(current_token_type) node.set_value(cls.currentToken.get_value()) if current_token_type in [Token.LITERAL_INT, Token.LITERAL_DOU]: return node raise ErrorParse(cls.get_next_token().get_line_num(), "literal") except ErrorParse as e: print e.content
def parse_literal(cls): try: if cls.iterator.has_next(): cls.currentToken = cls.iterator.next() current_token_type = cls.currentToken.get_type() node = Node(Node.LITERAL) node.set_data_type(current_token_type) node.set_value(cls.currentToken.get_value()) if current_token_type in [Token.LITERAL_INT, Token.LITERAL_DOU]: return node raise ErrorParse(cls.get_next_token().get_line_num(), "literal") except ErrorParse as e: print e.content
def identifier(cls): try: node = Node(Node.VAR) next_token_type = cls.get_next_token().get_type() if next_token_type == Token.ID: node.set_value(cls.iterator.next().get_value()) else: raise ErrorParse(cls.get_next_token().get_line_num(), "identifier") if cls.get_next_token().get_type() == Token.LBRACKET: cls.read_token(Token.LBRACKET) node.set_left(cls.parse_exp()) cls.read_token(Token.RBRACKET) return node except ErrorParse as e: print e.content
def identifier(cls): try: node = Node(Node.VAR) next_token_type = cls.get_next_token().get_type() if next_token_type == Token.ID: node.set_value(cls.iterator.next().get_value()) else: raise ErrorParse(cls.get_next_token().get_line_num(), "identifier") if cls.get_next_token().get_type() == Token.LBRACKET: cls.read_token(Token.LBRACKET) node.set_left(cls.parse_exp()) cls.read_token(Token.RBRACKET) return node except ErrorParse as e: print e.content