def parse_return_stmt(self): if self.peek_tok.type == token.SEMI: return ast.ReturnStatement(self.cur_tok, None) stmt = ast.ReturnStatement(self.cur_tok, None) self.next() stmt.value = self.parse_expr(LOWEST) return stmt
def vFunction(self, node): self.current_function_id = node.id self.p() proc = node.type.type == 'void' if proc: self.w('PROCEDURE') else: self.w('FUNCTION') self.w(node.id) self.visit(node.params) if not proc: self.w('RETURN') self.visit(node.type) self.p('IS') self.pi('BEGIN') if node.id == 'main': # hack for main block = copy.deepcopy(node.block) block.add(ast.ReturnStatement(ast.Literal(0))) self.visit(block) else: self.visit(node.block) self.uw('END') self.w(self.current_function_id) self.p(';') self.p() self.current_function_id = None
def vFunction(self, node): self.current_function_id = node.id self.p() proc = node.returnType.type == 'void' if proc: self.w('PROCEDURE') else: self.w('FUNCTION') self.w(node.id) self.visit(node.params) if not proc: self.w(':') self.visit(node.returnType) self.p(';') if node.id == 'main': # hack for main block = copy.deepcopy(node.block) ret = ast.ReturnStatement(ast.IntLiteral(0)) ret.symtab = node.symtab block.add(ret) self.visit(block) else: self.visit(node.block) self.p(';') self.p() self.current_function_id = None
def _parse_return_statement(self) -> Optional[ast.ReturnStatement]: token = self._current_token self._next_token() return_value = self._parse_expression(PrecedenceLevel.LOWEST) if return_value is None: return None if self._peek_token_is(TokenType.SEMICOLON): self._next_token() return ast.ReturnStatement(token, return_value)
def ParseReturnStatement(self): returnStmt = ast.ReturnStatement(self.currToken) # TODO implement Expressions self.nextToken() ## TO move forward returnStmt.ReturnValue = self.parseExpression(Precedence.LOWEST) return returnStmt
def parseReturnStatement(self): stmt = ast.ReturnStatement(Token=self.curToken,ReturnValue=None) self.nextToken() stmt.ReturnValue = self.parseExpression(self.operators.LOWEST) while not self.curTokenIs(tokens.SEMICOLON): self.nextToken() return stmt
def parseReturnStatement(self): stmt = ast.ReturnStatement() stmt.Token = self.curToken self.nextToken() """ while not self.curTokenIs(token.SEMICOLON): self.nextToken() """ stmt.ReturnValue = self.parseExpression(LOWEST) if self.peekTokenIs(token.SEMICOLON): self.nextToken() return stmt
def p_return_statement_02(t): '''return_statement : RETURN SEMI''' t[0] = ast.ReturnStatement(None)
def p_return_statement_01(t): '''return_statement : RETURN assignment_statement''' t[0] = ast.ReturnStatement(t[2])
def p_statement_return(t): '''statement : RETURN expression SEMICOLON''' t[0] = ast.ReturnStatement(t[2])
def return_statement(p): return ast.ReturnStatement(p[1])
def p_statement_emptyreturn(t): '''statement : RETURN SEMICOLON''' t[0] = ast.ReturnStatement(t.lexer.lineno, None)