예제 #1
0
    def if_statement(self):

        if self.currtok[0] == "KWDIF":
            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()

                    if self.currtok[0] == "KWDELSE":
                        self.currtok = next(self.tokens)
                        elsestmt = self.statement()
                        return ast.IfStmt(cond, stmt, elsestmt)
                    else:

                        return ast.IfStmt(cond, stmt)
                else:
                    raise CLiteSyntaxError("Right parenthesis expected",
                                           self.currtok[1])
            else:
                raise CLiteSyntaxError("Left parenthesis expected",
                                       self.currtok[1])
        else:
            raise CLiteSyntaxError("Keyword if expected", self.currtok[1])
예제 #2
0
파일: e_parser.py 프로젝트: greeny277/cb1
def p_ifstmt(p):
    '''ifstmt : TKIF '(' cond_expr ')' block TKELSE block
              | TKIF '(' cond_expr ')' block '''
    if len(p) == 8:
        p[0] = ast.IfStmt(p[3], p[5], p[7]).addloc(p.lineno(1))
    else:
        p[0] = ast.IfStmt(p[3], p[5], ast.Block()).addloc(p.lineno(1))
예제 #3
0
 def __cond(self):
     if_stmt_node = ast.IfStmt()
     self.__eat(token.IF)
     if_stmt_node.if_part.bool_expr = self.__bexpr()
     self.__eat(token.THEN)
     if_stmt_node.if_part.stmt_list = self.__bstmts(ast.StmtList())
     if_stmt_node = self.__condt(if_stmt_node)
     self.__eat(token.END)
     return if_stmt_node
예제 #4
0
def p_selection_statement_2(p):
    'selection_statement : IF LPAREN expression RPAREN statement ELSE statement'
    p[0] = ast.IfStmt(p[3], p[5], p[7], p.lineno(1) + __start_line_no - 1)
예제 #5
0
파일: code_parser.py 프로젝트: phrb/Orio
def p_selection_statement_2(p):
    "selection_statement : IF LPAREN expression RPAREN statement ELSE statement"
    p[0] = ast.IfStmt(p[3], p[5], p[7])
예제 #6
0
파일: code_parser.py 프로젝트: phrb/Orio
def p_selection_statement_1(p):
    "selection_statement : IF LPAREN expression RPAREN statement"
    p[0] = ast.IfStmt(p[3], p[5], None)
예제 #7
0
def p_stmt_if_noelse(p):
    'stmt : IF LPAREN expr RPAREN stmt'
    p[0] = ast.IfStmt(p[3], p[5], ast.SkipStmt(None), p.lineno(1))
예제 #8
0
def p_stmt_if_else(p):
    'stmt : IF LPAREN expr RPAREN stmt ELSE stmt'
    p[0] = ast.IfStmt(p[3], p[5], p[7], p.lineno(1))
예제 #9
0
    def __convertToASTs(self, dstmts, tile_level, contain_loop, loop_inames,
                        loop_info_table, int_vars):
        '''
        To recursively convert the given list, containing processed statements and possibly 
        if-branching statements, to AST. A sample of the given list is as follows:
           [s1, t-exp, [s2, s3], [s4]]
        which represents the following AST:
           s1; if (t-exp) {s2; s3;} else s4;
        '''

        # initialize the list of ASTs
        asts = []

        # iterating over each list element
        i = 0
        while i < len(dstmts):
            s = dstmts[i]

            # if it's an AST
            if isinstance(s, tuple):
                is_tiled, stmts = s
                stmts = [s.replicate() for s in stmts]

                # already tiled; no need to enclose with an inter-tile loop nest
                if is_tiled:
                    asts.extend(stmts)

                # need to enclose with a single-level inter-tile loop nest
                elif contain_loop:

                    # add single-level tiled loop
                    rev_inames = loop_inames[:]
                    rev_inames.reverse()
                    l = ast.CompStmt(stmts)
                    for iname in rev_inames:
                        tname = self.__getTileSizeName(iname, tile_level)
                        lb_exp = ast.IdentExp(
                            self.__getTileIterName(iname, tile_level))
                        _, _, _, st_exp, _ = loop_info_table[iname]
                        lbody = l
                        l = self.__getIntraTileLoop(iname, tname, lb_exp,
                                                    st_exp, lbody)
                        l.fully_tiled = True

                    # to recursively tile all boundary tiles
                    if self.use_boundary_tiling:
                        new_tile_level = min(tile_level - 1,
                                             self.recursive_tile_level)
                        if new_tile_level > 0:
                            l = self.__startTiling(l, new_tile_level, int_vars)

                    # insert the tiled loop to the AST list
                    asts.append(l)

                # need to enclose with a multilevel inter-tile loop nest
                else:
                    lbody = ast.CompStmt(stmts)
                    st_exps = []
                    for iname in loop_inames:
                        _, _, _, st_exp, _ = loop_info_table[iname]
                        st_exps.append(st_exp)
                    l = self.__getMultiLevelTileLoop(tile_level, loop_inames,
                                                     st_exps, lbody)
                    asts.append(l)

                # increment index
                i += 1

            # if it's an if-statement's test expression
            else:
                if not isinstance(s, ast.BinOpExp):
                    err('orio.module.ortil.transformation internal error: a test expression is expected'
                        )

                # generate AST for the true statement
                t1 = self.__convertToASTs(dstmts[i + 1], tile_level,
                                          contain_loop, loop_inames,
                                          loop_info_table, int_vars)

                # generate AST for the false statement
                t2 = self.__convertToASTs(dstmts[i + 2], tile_level,
                                          contain_loop, loop_inames,
                                          loop_info_table, int_vars)

                # generate AST for the if-statement
                test_exp = s.replicate()
                true_stmt = ast.CompStmt(t1)
                false_stmt = ast.CompStmt(t2)
                asts.append(ast.IfStmt(test_exp, true_stmt, false_stmt))

                # increment index
                i += 3

        # return the list of ASTs
        return asts
예제 #10
0
    def if_statement(self):
        self.expect(T.IF)
        cond = self.expr()
        stmt = self.statement()

        return ast.IfStmt(cond, stmt)
예제 #11
0
def p_selection_statement_1(p):
    'selection_statement : IF LPAREN expression RPAREN statement'
    p[0] = ast.IfStmt(p[3], p[5], None, line_no=str(p.lineno(1) + __start_line_no - 1))
예제 #12
0
def p_selection_statement_2(p):
    "selection_statement : IF LPAREN expression RPAREN statement ELSE statement"
    p[0] = ast.IfStmt(p[3], p[5], p[7], getLineNumber(p.lineno(1)))
예제 #13
0
def p_selection_statement_1(p):
    'selection_statement : IF LPAREN expression RPAREN statement'
    p[0] = ast.IfStmt(p[3], p[5], None, getLineNumber(p.lineno(1)))
예제 #14
0
def p_if_stmt_else(p):
    '''if_stmt : IF bool_expr THEN simple_instr ELSE simple_instr'''
    p[0] = ast.IfStmt(p[2], p[4], p[6])
예제 #15
0
def p_if_stmt(p):
    '''if_stmt : IF bool_expr THEN simple_instr'''
    p[0] = ast.IfStmt(p[2], p[4])