Exemplo n.º 1
0
 def __while(self):
     self.__eat(token.WHILE)
     while_stmt_node = ast.WhileStmt()
     while_stmt_node.bool_expr = self.__bexpr()
     self.__eat(token.DO)
     while_stmt_node.stmt_list = self.__bstmts(ast.StmtList())
     self.__eat(token.END)
     return while_stmt_node
Exemplo n.º 2
0
    def while_statement(self):
        if self.currtok[0] == "KWDWHILE":
            self.currtok = next(self.tokens)
            if self.currtok[0] == "PCTLPAR":
                self.currtok = next(self.tokens)
                cond = self.expression()

                if self.currtok[0] == "PCTRPAR":
                    self.currtok = next(self.tokens)
                    stmt = self.statement()
                    ast.indent_level -= 1
                    return ast.WhileStmt(cond, stmt)

                else:
                    raise CLiteSyntaxError("Right parenthesis expected",
                                           self.currtok[1])
            else:
                raise CLiteSyntaxError("Left parenthesis expected",
                                       self.currtok[1])
        else:
            raise CLiteSyntaxError("While keyword expected", self.currtok[1])
Exemplo n.º 3
0
def p_whilestmt(p):
    '''whilestmt : TKWHILE '(' cond_expr ')' block'''
    p[0] = ast.WhileStmt(p[3], p[5]).addloc(p.lineno(1))
Exemplo n.º 4
0
def p_stmt_while(p):
    'stmt : WHILE LPAREN expr RPAREN stmt'
    p[0] = ast.WhileStmt(p[3], p[5], p.lineno(1))
Exemplo n.º 5
0
def p_while_stmt_do(p):
    '''while_stmt : DO simple_instr WHILE bool_expr'''
    p[0] = ast.WhileStmt(p[4], p[2], do_while=True)
Exemplo n.º 6
0
def p_while_stmt(p):
    '''while_stmt : WHILE bool_expr DO simple_instr'''
    p[0] = ast.WhileStmt(p[2], p[4])