Example #1
0
/** execute_FOR  Executes for statement.
 *          initialize   condition     increment
 *      for(<statement>; <expression>; <expression>)
 *              <statement>;
 *
 * @param p_function_id
 */
void cx_executor::execute_FOR(cx_symtab_node * p_function_id) {

    bool condition = false;

    get_token(); // for
    // get the location of where to go to if <expr> is false.
    int break_point = get_location_marker();
    get_token();
    int statement_location = get_location_marker();
    get_token();
    int condition_marker = get_location_marker();
    get_token();
    int increment_marker = get_location_marker();


    get_token();

    // (
    get_token();

    if (token != tc_semicolon) {
        // declaration would go here //
        execute_assignment(p_node);
    }

    do {
        get_token(); //  ;
        if (token != tc_semicolon) {

            // expr 2
            execute_expression();
            get_token(); //  ;
        } else get_token();

        condition = top()->basic_types.bool__;
        pop();
        if (condition) {
            go_to(statement_location);
            get_token();
            execute_statement(p_function_id);
            if (break_loop) go_to(break_point);
        } else {
            go_to(break_point);
            get_token();
            break;
        }

        go_to(increment_marker);
        get_token();
        // expr 3
        execute_expression();

        go_to(condition_marker);
    } while (current_location() == condition_marker);

    break_loop = false;
}
Example #2
0
/** execute_statement   	Execute a Cx statement
 *
 * @param p_function_id : ptr to the routine symtab node
 */
void cx_executor::execute_statement(cx_symtab_node *p_function_id) {
    if (token != tc_left_bracket) {
        ++statement_count;
        trace_statement();
    }

    switch (token) {
        case tc_identifier:
        {
            if (p_node->defn.how == dc_function) {
                execute_function_call(p_node);
            } else {
                cx_symtab_node *p_var = p_node;
                get_token();
                if (token_in(token, tokenlist_assign_ops)) {
                    execute_assignment(p_var);
                } else {
                    execute_variable(p_var, false);
                    pop();
                }
            }
        }
            break;
        case tc_DO: execute_DO(p_function_id);
            break;
        case tc_WHILE: execute_WHILE(p_function_id);
            break;
        case tc_IF: execute_IF(p_function_id);
            break;
        case tc_FOR: execute_FOR(p_function_id);
            break;
        case tc_SWITCH: //parse_SWITCH();
            break;
        case tc_CASE:
        case tc_DEFAULT://parse_case_label();
            break;
        case tc_BREAK:
            get_token();
            break_loop = true;
            break;
        case tc_left_bracket: execute_compound(p_function_id);
            break;
        case tc_RETURN: execute_RETURN(p_function_id);
            break;
        default:
            break;
    }
}
Example #3
0
/** execute_RETURN	Assign a return value to the functions StackItem and
 *                      set current location to the return line of the caller.
 *
 *      return;
 *      return <expression>;
 *
 * @param p_function_id : ptr to the subroutine name's symtab node
 */
void cx_executor::execute_RETURN (cx_symtab_node * p_function_id) {
    execute_assignment(p_function_id);
    token = tc_dummy;
}