Пример #1
0
def StmtWhile():
    yield ps.token(TOKEN.WHILE)
    yield ps.token(TOKEN.PAR_OPEN)
    condition = yield Exp
    yield ps.token(TOKEN.PAR_CLOSE)
    yield ps.token(TOKEN.CURL_OPEN)
    contents = yield ps.many(Stmt)
    yield ps.token(TOKEN.CURL_CLOSE)

    return AST.LOOP(init=None, cond=condition, update=None, stmts=contents)
Пример #2
0
def StmtFor():
    yield ps.token(TOKEN.FOR)
    yield ps.token(TOKEN.PAR_OPEN)
    initial = yield ps.times(ActStmt, 0, 1)
    initial = initial[0] if len(initial) > 0 else None
    yield ps.token(TOKEN.SEMICOLON)
    condition = yield ps.times(Exp, 0, 1)
    condition = condition[0] if len(condition) > 0 else None
    yield ps.token(TOKEN.SEMICOLON)
    update = yield ps.times(ActStmt, 0, 1)
    update = update[0] if len(update) > 0 else None
    yield ps.token(TOKEN.PAR_CLOSE)
    yield ps.token(TOKEN.CURL_OPEN)
    contents = yield ps.many(Stmt)
    yield ps.token(TOKEN.CURL_CLOSE)
    return AST.LOOP(init=initial,
                    cond=condition,
                    update=update,
                    stmts=contents)
Пример #3
0
 AST.LOOP(
     init=AST.ACTSTMT(val=AST.ASSIGNMENT(
         varref=AST.VARREF(id=Token(None, TOKEN.IDENTIFIER,
                                    "x"),
                           fields=[]),
         expr=AST.DEFERREDEXPR(
             contents=[Token(None, TOKEN.IDENTIFIER, "x")
                       ]))),
     cond=AST.DEFERREDEXPR(contents=[
         Token(None, TOKEN.IDENTIFIER, "x"),
         Token(None, TOKEN.OP_IDENTIFIER, "=="),
         Token(None, TOKEN.IDENTIFIER, "y")
     ]),
     update=AST.FUNCALL(id=Token(None, TOKEN.IDENTIFIER,
                                 "f"),
                        kind=FunKind.FUNC,
                        args=[]),
     stmts=[
         AST.STMT(
             val=AST.RETURN(expr=None)),
         AST.STMT(val=AST.IFELSE(condbranches=[
             AST.CONDBRANCH(expr=AST.DEFERREDEXPR(contents=[
                 Token(None, TOKEN.IDENTIFIER, "x"),
                 Token(None, TOKEN.OP_IDENTIFIER, "=="),
                 Token(None, TOKEN.IDENTIFIER, "y")
             ]),
                            stmts=[
                                AST.STMT(val=AST.RETURN(
                                    expr=None))
                            ]),
             AST.CONDBRANCH(expr=AST.DEFERREDEXPR(contents=[
                 Token(None, TOKEN.IDENTIFIER, "x"),
                 Token(None, TOKEN.OP_IDENTIFIER, "=="),
                 Token(None, TOKEN.IDENTIFIER, "y")
             ]),
                            stmts=[
                                AST.STMT(val=AST.RETURN(
                                    expr=None))
                            ]),
             AST.CONDBRANCH(expr=None,
                            stmts=[
                                AST.STMT(val=AST.RETURN(
                                    expr=None))
                            ])
         ]))
     ])