示例#1
0
def main(t1: Place) -> Place:
    IOExists8(str, Place, str, bool, Place, Place, bool, bool)(
        lambda read_ahead, t_read_ahead, read_last, valid, t_brackets_end, t_end,
               success1, success2: (
            Requires(
                token(t1) and
                read_char_io(t1, stdin, read_ahead, success1, t_read_ahead) and
                brackets_io(t_read_ahead, read_ahead, read_last, valid, t_brackets_end) and
                read_last is None and
                write_char_io(t_brackets_end, stdout, ('1' if valid else '0'), success2, t_end)
            ),
            Ensures(
                token(t_end) and
                t_end == Result()
            ),
        )
    )

    m = Matcher()
    m.c, success, t2 = getchar(t1)
    t3, match = m.brackets(t2)
    if match:
        success, t4 = putchar('1', t3)
    else:
        success, t4 = putchar('0', t3)
    return t4
 def main(self, t1: Place) -> Place:
     IOExists1(Place)(lambda t2: (
         Requires(token(t1, 2) and example_io(t1, t2) and MustTerminate(2)),
         Ensures(token(t2) and t2 == Result()),
     ))
     Open(example_io(t1))
     success, t2 = putchar('h', t1)
     success, t3 = putchar('i', t2)
     return t3
示例#3
0
def main(t1: Place) -> None:
    Requires(token(t1, 2) and yes_io(t1))
    Ensures(False)

    t = t1

    while True:
        Invariant(token(t, 1) and yes_io(t))

        Open(yes_io(t))
        success, t2 = putchar('y', t)
        success, t = putchar('\n', t2)
def main(t1: Place) -> Place:
    IOExists1(Place)(lambda t2: (
        Requires(
            token(t1, 2) and matching_brackets(t1, t2) and MustTerminate(2)),
        Ensures(token(t2)),
    ))
    Open(matching_brackets(t1))
    Open(matching_brackets_helper(t1))
    success, t2 = putchar('(', t1)
    Open(matching_brackets(t2))
    t3 = NoOp(t2)
    success, t4 = putchar(')', t3)
    Open(matching_brackets(t4))
    t5 = NoOp(t4)
    return t5
示例#5
0
def main(t1: Place) -> Place:
    IOExists4(Place, Place, bool, bool)(
        lambda t2, t3, success1, success2: (
        Requires(
            token(t1, 2) and
            write_char_io(t1, stdout, 'h', success1, t2) and
            write_char_io(t2, stdout, 'i', success2, t3) and
            MustTerminate(2)
        ),
        Ensures(
            token(t3) and
            t3 == Result()
        )
    ))
    success, t2 = putchar('h', t1)
    success, t3 = putchar('i', t2)
    return t3
示例#6
0
def main(t1: Place) -> Place:
    IOExists1(Place)(lambda t2: (
        Requires(
            token(t1, 2) and output_anything(t1, t2) and MustTerminate(2)),
        Ensures(token(t2)),
    ))
    i = get_any_char()

    Open(output_anything(t1))
    t2 = SetVar(t1, i)
    success, t3 = putchar(i, t2)
    return t3
示例#7
0
def main(t1: Place) -> None:
    Requires(token(t1, 2) and infinite_counter_io(t1, 0))
    Ensures(False)

    count = 0
    t_cur = t1

    while True:
        Invariant(
            token(t_cur, 1) and infinite_counter_io(t_cur, count)
            and count >= 0)

        unary_count = 0

        Open(infinite_counter_io(t_cur, count))

        t1_unary = t_cur
        t_unary_end = GetGhostOutput(print_unary_io(t1_unary, count),
                                     't_end')  # type: Place

        while (unary_count != count):
            Invariant(
                token(t1_unary, 1)
                and print_unary_io(t1_unary, count - unary_count, t_unary_end)
                and unary_count <= count)

            Open(print_unary_io(t1_unary, count - unary_count))

            success, t1_unary = putchar('1', t1_unary)

            unary_count += 1

        Open(print_unary_io(t1_unary, 0))

        t2 = NoOp(t1_unary)

        success, t_cur = putchar('\n', t2)

        count = count + 1