from NonTerminal import *
from Object import *


def statement_list(ast, context, print_result=False):
    if len(ast) == 2 and print_result:
        ret = statement(ast[1], context)
        if ret is not None:
            print(ret)
    else:
        for i in range(1, len(ast)):
            statement(ast[i], context)
            if context.return_value is not None:
                break
    return context.return_value


from Expression import expression_no_in, variable_statement

controlEngine = None


def statement(ast, context):
    return controlEngine[ast[1][0]](ast[1], context)


def block(ast, context):
    if len(ast) == 4:
        statement_list(ast[2], context)


def empty_statement(ast, context):
    pass


def expression_no_in_statement(ast, context):
    return expression_no_in(ast[1], context)


def if_statement(ast, context):
    if expression_no_in(ast[3], context):
        statement(ast[5], context)
    else:
        if len(ast) == 8:
            statement(ast[7], context)


def iteration_statement(ast, context):
    controlEngine[ast[1][0]](ast[1], context)


def do_statement(ast, context):
    while True:
        statement(ast[2], context)
        if context.return_value is not None:
            break
        if not expression_no_in(ast[5], context):
            break


def while_statement(ast, context):
    while expression_no_in(ast[3], context):
        statement(ast[5], context)
        if context.return_value is not None:
            break


def origin_for_statement(ast, context):
    expression_no_in(ast[3], context)
    while expression_no_in(ast[5], context):
        statement(ast[9], context)
        if context.return_value is not None:
            break
        expression_no_in(ast[7], context)


def for_each_statement(ast, context):
    for context[ast[4][1]] in expression_no_in(ast[6], context):
        statement(ast[8], context)
        if context.return_value is not None:
            break


def return_statement(ast, context):
    if ast[len(ast) - 1] == ";":
        ast.pop()
    if len(ast) == 2:
        context.return_value = UNDEFINED
    elif len(ast) == 3:
        context.return_value = expression_no_in(ast[2], context)


def print_statement(ast, context):
    print(expression_no_in(ast[2], context))


def program(ast, context, print_result):
    return statement_list(ast[1], context, print_result)


# def source_elements(ast, context):
#     for i in range(1, len(ast)):
#         source_element(ast[i], context)


# def source_element(ast, context):
#     statement(ast[1], context)


controlEngine = {
    Block: block,
    VariableStatement: variable_statement,
    EmptyStatement: empty_statement,
    ExpressionNoInStatement: expression_no_in_statement,
    IfStatement: if_statement,
    IterationStatement: iteration_statement,
    DoStatement: do_statement,
    WhileStatement: while_statement,
    OriginForStatement: origin_for_statement,
    ForEachStatement: for_each_statement,
    ReturnStatement: return_statement,
    PrintStatement: print_statement
}


def main():
    pass


if __name__ == '__main__':
    main()

828b18431ea1037179bfb34c9d6ee94e60f457e0
<mask token>


def statement_list(ast, context, print_result=False):
    if len(ast) == 2 and print_result:
        ret = statement(ast[1], context)
        if ret is not None:
            print(ret)
    else:
        for i in range(1, len(ast)):
            statement(ast[i], context)
            if context.return_value is not None:
                break
    return context.return_value


<mask token>


def statement(ast, context):
    return controlEngine[ast[1][0]](ast[1], context)


def block(ast, context):
    if len(ast) == 4:
        statement_list(ast[2], context)


def empty_statement(ast, context):
    pass


def expression_no_in_statement(ast, context):
    return expression_no_in(ast[1], context)


def if_statement(ast, context):
    if expression_no_in(ast[3], context):
        statement(ast[5], context)
    elif len(ast) == 8:
        statement(ast[7], context)


def iteration_statement(ast, context):
    controlEngine[ast[1][0]](ast[1], context)


def do_statement(ast, context):
    while True:
        statement(ast[2], context)
        if context.return_value is not None:
            break
        if not expression_no_in(ast[5], context):
            break


def while_statement(ast, context):
    while expression_no_in(ast[3], context):
        statement(ast[5], context)
        if context.return_value is not None:
            break


def origin_for_statement(ast, context):
    expression_no_in(ast[3], context)
    while expression_no_in(ast[5], context):
        statement(ast[9], context)
        if context.return_value is not None:
            break
        expression_no_in(ast[7], context)


def for_each_statement(ast, context):
    for context[ast[4][1]] in expression_no_in(ast[6], context):
        statement(ast[8], context)
        if context.return_value is not None:
            break


def return_statement(ast, context):
    if ast[len(ast) - 1] == ';':
        ast.pop()
    if len(ast) == 2:
        context.return_value = UNDEFINED
    elif len(ast) == 3:
        context.return_value = expression_no_in(ast[2], context)


def print_statement(ast, context):
    print(expression_no_in(ast[2], context))


def program(ast, context, print_result):
    return statement_list(ast[1], context, print_result)


<mask token>


def main():
    pass


<mask token>

<mask token>


def statement_list(ast, context, print_result=False):
    if len(ast) == 2 and print_result:
        ret = statement(ast[1], context)
        if ret is not None:
            print(ret)
    else:
        for i in range(1, len(ast)):
            statement(ast[i], context)
            if context.return_value is not None:
                break
    return context.return_value


<mask token>


def statement(ast, context):
    return controlEngine[ast[1][0]](ast[1], context)


def block(ast, context):
    if len(ast) == 4:
        statement_list(ast[2], context)


def empty_statement(ast, context):
    pass


def expression_no_in_statement(ast, context):
    return expression_no_in(ast[1], context)


def if_statement(ast, context):
    if expression_no_in(ast[3], context):
        statement(ast[5], context)
    elif len(ast) == 8:
        statement(ast[7], context)


def iteration_statement(ast, context):
    controlEngine[ast[1][0]](ast[1], context)


def do_statement(ast, context):
    while True:
        statement(ast[2], context)
        if context.return_value is not None:
            break
        if not expression_no_in(ast[5], context):
            break


def while_statement(ast, context):
    while expression_no_in(ast[3], context):
        statement(ast[5], context)
        if context.return_value is not None:
            break


def origin_for_statement(ast, context):
    expression_no_in(ast[3], context)
    while expression_no_in(ast[5], context):
        statement(ast[9], context)
        if context.return_value is not None:
            break
        expression_no_in(ast[7], context)


def for_each_statement(ast, context):
    for context[ast[4][1]] in expression_no_in(ast[6], context):
        statement(ast[8], context)
        if context.return_value is not None:
            break


def return_statement(ast, context):
    if ast[len(ast) - 1] == ';':
        ast.pop()
    if len(ast) == 2:
        context.return_value = UNDEFINED
    elif len(ast) == 3:
        context.return_value = expression_no_in(ast[2], context)


def print_statement(ast, context):
    print(expression_no_in(ast[2], context))


def program(ast, context, print_result):
    return statement_list(ast[1], context, print_result)


<mask token>


def main():
    pass


if __name__ == '__main__':
    main()

<mask token>


def statement_list(ast, context, print_result=False):
    if len(ast) == 2 and print_result:
        ret = statement(ast[1], context)
        if ret is not None:
            print(ret)
    else:
        for i in range(1, len(ast)):
            statement(ast[i], context)
            if context.return_value is not None:
                break
    return context.return_value


<mask token>
controlEngine = None


def statement(ast, context):
    return controlEngine[ast[1][0]](ast[1], context)


def block(ast, context):
    if len(ast) == 4:
        statement_list(ast[2], context)


def empty_statement(ast, context):
    pass


def expression_no_in_statement(ast, context):
    return expression_no_in(ast[1], context)


def if_statement(ast, context):
    if expression_no_in(ast[3], context):
        statement(ast[5], context)
    elif len(ast) == 8:
        statement(ast[7], context)


def iteration_statement(ast, context):
    controlEngine[ast[1][0]](ast[1], context)


def do_statement(ast, context):
    while True:
        statement(ast[2], context)
        if context.return_value is not None:
            break
        if not expression_no_in(ast[5], context):
            break


def while_statement(ast, context):
    while expression_no_in(ast[3], context):
        statement(ast[5], context)
        if context.return_value is not None:
            break


def origin_for_statement(ast, context):
    expression_no_in(ast[3], context)
    while expression_no_in(ast[5], context):
        statement(ast[9], context)
        if context.return_value is not None:
            break
        expression_no_in(ast[7], context)


def for_each_statement(ast, context):
    for context[ast[4][1]] in expression_no_in(ast[6], context):
        statement(ast[8], context)
        if context.return_value is not None:
            break


def return_statement(ast, context):
    if ast[len(ast) - 1] == ';':
        ast.pop()
    if len(ast) == 2:
        context.return_value = UNDEFINED
    elif len(ast) == 3:
        context.return_value = expression_no_in(ast[2], context)


def print_statement(ast, context):
    print(expression_no_in(ast[2], context))


def program(ast, context, print_result):
    return statement_list(ast[1], context, print_result)


controlEngine = {Block: block, VariableStatement: variable_statement,
    EmptyStatement: empty_statement, ExpressionNoInStatement:
    expression_no_in_statement, IfStatement: if_statement,
    IterationStatement: iteration_statement, DoStatement: do_statement,
    WhileStatement: while_statement, OriginForStatement:
    origin_for_statement, ForEachStatement: for_each_statement,
    ReturnStatement: return_statement, PrintStatement: print_statement}


def main():
    pass


if __name__ == '__main__':
    main()

from NonTerminal import *
from Object import *


def statement_list(ast, context, print_result=False):
    if len(ast) == 2 and print_result:
        ret = statement(ast[1], context)
        if ret is not None:
            print(ret)
    else:
        for i in range(1, len(ast)):
            statement(ast[i], context)
            if context.return_value is not None:
                break
    return context.return_value


from Expression import expression_no_in, variable_statement
controlEngine = None


def statement(ast, context):
    return controlEngine[ast[1][0]](ast[1], context)


def block(ast, context):
    if len(ast) == 4:
        statement_list(ast[2], context)


def empty_statement(ast, context):
    pass


def expression_no_in_statement(ast, context):
    return expression_no_in(ast[1], context)


def if_statement(ast, context):
    if expression_no_in(ast[3], context):
        statement(ast[5], context)
    elif len(ast) == 8:
        statement(ast[7], context)


def iteration_statement(ast, context):
    controlEngine[ast[1][0]](ast[1], context)


def do_statement(ast, context):
    while True:
        statement(ast[2], context)
        if context.return_value is not None:
            break
        if not expression_no_in(ast[5], context):
            break


def while_statement(ast, context):
    while expression_no_in(ast[3], context):
        statement(ast[5], context)
        if context.return_value is not None:
            break


def origin_for_statement(ast, context):
    expression_no_in(ast[3], context)
    while expression_no_in(ast[5], context):
        statement(ast[9], context)
        if context.return_value is not None:
            break
        expression_no_in(ast[7], context)


def for_each_statement(ast, context):
    for context[ast[4][1]] in expression_no_in(ast[6], context):
        statement(ast[8], context)
        if context.return_value is not None:
            break


def return_statement(ast, context):
    if ast[len(ast) - 1] == ';':
        ast.pop()
    if len(ast) == 2:
        context.return_value = UNDEFINED
    elif len(ast) == 3:
        context.return_value = expression_no_in(ast[2], context)


def print_statement(ast, context):
    print(expression_no_in(ast[2], context))


def program(ast, context, print_result):
    return statement_list(ast[1], context, print_result)


controlEngine = {Block: block, VariableStatement: variable_statement,
    EmptyStatement: empty_statement, ExpressionNoInStatement:
    expression_no_in_statement, IfStatement: if_statement,
    IterationStatement: iteration_statement, DoStatement: do_statement,
    WhileStatement: while_statement, OriginForStatement:
    origin_for_statement, ForEachStatement: for_each_statement,
    ReturnStatement: return_statement, PrintStatement: print_statement}


def main():
    pass


if __name__ == '__main__':
    main()

from NonTerminal import *
from Object import *


def statement_list(ast, context, print_result=False):
    if len(ast) == 2 and print_result:
        ret = statement(ast[1], context)
        if ret is not None:
            print(ret)
    else:
        for i in range(1, len(ast)):
            statement(ast[i], context)
            if context.return_value is not None:
                break
    return context.return_value


from Expression import expression_no_in, variable_statement

controlEngine = None


def statement(ast, context):
    return controlEngine[ast[1][0]](ast[1], context)


def block(ast, context):
    if len(ast) == 4:
        statement_list(ast[2], context)


def empty_statement(ast, context):
    pass


def expression_no_in_statement(ast, context):
    return expression_no_in(ast[1], context)


def if_statement(ast, context):
    if expression_no_in(ast[3], context):
        statement(ast[5], context)
    else:
        if len(ast) == 8:
            statement(ast[7], context)


def iteration_statement(ast, context):
    controlEngine[ast[1][0]](ast[1], context)


def do_statement(ast, context):
    while True:
        statement(ast[2], context)
        if context.return_value is not None:
            break
        if not expression_no_in(ast[5], context):
            break


def while_statement(ast, context):
    while expression_no_in(ast[3], context):
        statement(ast[5], context)
        if context.return_value is not None:
            break


def origin_for_statement(ast, context):
    expression_no_in(ast[3], context)
    while expression_no_in(ast[5], context):
        statement(ast[9], context)
        if context.return_value is not None:
            break
        expression_no_in(ast[7], context)


def for_each_statement(ast, context):
    for context[ast[4][1]] in expression_no_in(ast[6], context):
        statement(ast[8], context)
        if context.return_value is not None:
            break


def return_statement(ast, context):
    if ast[len(ast) - 1] == ";":
        ast.pop()
    if len(ast) == 2:
        context.return_value = UNDEFINED
    elif len(ast) == 3:
        context.return_value = expression_no_in(ast[2], context)


def print_statement(ast, context):
    print(expression_no_in(ast[2], context))


def program(ast, context, print_result):
    return statement_list(ast[1], context, print_result)


# def source_elements(ast, context):
#     for i in range(1, len(ast)):
#         source_element(ast[i], context)


# def source_element(ast, context):
#     statement(ast[1], context)


controlEngine = {
    Block: block,
    VariableStatement: variable_statement,
    EmptyStatement: empty_statement,
    ExpressionNoInStatement: expression_no_in_statement,
    IfStatement: if_statement,
    IterationStatement: iteration_statement,
    DoStatement: do_statement,
    WhileStatement: while_statement,
    OriginForStatement: origin_for_statement,
    ForEachStatement: for_each_statement,
    ReturnStatement: return_statement,
    PrintStatement: print_statement
}


def main():
    pass


if __name__ == '__main__':
    main()
