示例#1
0
文件: mass.c 项目: starrify/cw4aai
static void mass_init(int argc, char **argv)
{
    option_init(argc, argv);

    if (!option_output_file)
        option_output_file = "a.out";

    if (!option_input_file)
    {
        errmsg("mass: error: no input file specified\n");
        exit(0);
    }

    FILE *tmp_in = fopen(option_input_file, "r");
    if (!tmp_in)
    {
        errmsg("mass: error: %s: %s\n", option_input_file, strerror(errno));
        exit(0);
    }
    yyset_in(tmp_in);

    symbol_table_init();
    buf_init();
    return;
}
示例#2
0
void t_setup() {
    token_index = 0;
    diff = 0;
    count = 0;
    symbol_table_init(&fix.table);
    fsm_init(&fix.fsm, &fix.table);
    ebnf_init_fsm(&fix.fsm);
}
示例#3
0
void t_setup(){
	input_init_buffer(&fix.input, buffer, strlen(buffer));
	symbol_table_init(&fix.table);
	ast_init(&fix.ast, &fix.input, &fix.table);
}
示例#4
0
static bool analyzer_first_pass_do(struct ast_node *n, void *user_arg)
{
    struct analyzer_traversal_ctx *ctx = user_arg;
    analyzer_traversal_ctx_push_parent(ctx, n);
    // act depending on the node type
    switch(n->type) {
        // nodes that change the current symbol table
    case AST_BLOCK:
        if (!ast_block_symbol_table_init(n, ctx->m)) {
            RF_ERROR("Could not initialize symbol table for block node");
            return false;
        }
        symbol_table_swap_current(&ctx->current_st, ast_block_symbol_table_get(n));
        break;
    case AST_MODULE:
        // input the module's name to the symbol table
        if (!analyzer_populate_symbol_module(ctx, n)) {
            return false;
        }
        symbol_table_swap_current(&ctx->current_st, ast_module_symbol_table_get(n));
        break;
    case AST_FUNCTION_DECLARATION:
        if (!analyzer_create_symbol_table_fndecl(ctx, n)) {
            return false;
        }
        symbol_table_swap_current(&ctx->current_st, ast_fndecl_symbol_table_get(n));
        symbol_table_set_fndecl(ctx->current_st, n);
        break;
    case AST_FUNCTION_IMPLEMENTATION:
        // function implementation symbol table should point to its decl table
        ast_fnimpl_symbol_table_set(n, ast_fndecl_symbol_table_get(n->fnimpl.decl));
        break;
    case AST_MATCH_CASE:
        // match case symbol table should point to its pattern typedesc table
        ast_matchcase_symbol_table_set(n, ast_typedesc_symbol_table_get(n->matchcase.pattern));
        break;
    case AST_TYPE_DESCRIPTION:
        // initialize the type description's symbol table
        if (!symbol_table_init(&n->typedesc.st, ctx->m)) {
            RF_ERROR("Could not initialize symbol table for top level type description node");
            return false;
        }
        symbol_table_swap_current(&ctx->current_st, ast_typedesc_symbol_table_get(n));
        // also populate the type description's symbol table
        if (!analyzer_populate_symbol_table_typedesc(ctx, n)) {
            RF_ERROR("Could not populate symbol table for top level type description node");
            return false;
        }
        break;
    case AST_TYPE_DECLARATION:
        if (!analyzer_populate_symbol_table_typedecl(ctx, n)) {
            return false;
        }
        break;

    // nodes that only contribute records to symbol tables
    case AST_VARIABLE_DECLARATION:
        if (!analyzer_populate_symbol_table_vardecl(ctx, n)) {
            RF_ERROR("Could not populate symbol table for variable declaration");
            return false;
        }
        break;
    case AST_IDENTIFIER:
        // create identifier hash and dissasociate from the file
        RF_ASSERT(n->state == AST_NODE_STATE_AFTER_PARSING,
                  "Attempting to create identifier hash for node in a wrong "
                  "state of processing");
        if (!ast_identifier_hash_create(n, ctx->m)) {
            return false;
        }
        break;
    case AST_STRING_LITERAL:
        // create literal hash and dissasociate from the file
        RF_ASSERT(n->state == AST_NODE_STATE_AFTER_PARSING,
                  "Attempting to create literal hash for node in a wrong state "
                  "of processing");
        if (!ast_string_literal_hash_create(n, ctx->m)) {
            return false;
        }
        break;
    default:
        // do nothing
        break;
    }

    // since this is the very first pass of the analyzer and should happen
    // only once, change node ownership here
    n->state = AST_NODE_STATE_ANALYZER_PASS1;
    return true;
}