⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ptables.c

📁 一个非常好的检索工具
💻 C
📖 第 1 页 / 共 2 页
字号:
        default_action = 0;        for (q = action_count[symbol]; q != NULL; q = q -> next)        {            if (q -> count > max_count)            {                max_count = q -> count;                default_action = q -> action;            }        }        gotodef[symbol] = default_action;        if (default_action > 0) /* A state number? */            goto_count += max_count;        else            goto_reduce_count += max_count;    }    /***********************************************************************/    /*   We now iterate over the automaton and eliminate all GOTO actions  */    /* for which there is a DEFAULT.                                       */    /***********************************************************************/    for ALL_STATES(state_no)    {        k = 0;        go_to = statset[state_no].go_to;        for (i = 1; i <= go_to.size; i++)        {            if (gotodef[GOTO_SYMBOL(go_to, i)] != GOTO_ACTION(go_to, i))            {                k++;                GOTO_SYMBOL(go_to, k) = GOTO_SYMBOL(go_to, i);                GOTO_ACTION(go_to, k) = GOTO_ACTION(go_to, i);            }        }        statset[state_no].go_to.size = k;   /* Readjust size */    }    sprintf(msg_line,            "Number of Goto entries saved by default: %d",            goto_count);    PRNT(msg_line);    sprintf(msg_line,            "Number of Goto/Reduce entries saved by default: %d",            goto_reduce_count);    PRNT(msg_line);    num_gotos -= goto_count;    num_goto_reduces -= goto_reduce_count;    num_entries = num_entries - goto_count - goto_reduce_count;    action_count += (num_terminals + 1);    ffree(action_count);    return;}/***********************************************************************//*                        PROCESS_TABLES:                              *//***********************************************************************//* Remap symbols, apply transition default actions  and call           *//* appropriate table compression routine.                              *//***********************************************************************/void process_tables(void){    int i,        j,        state_no,        rule_no,        symbol;    struct goto_header_type   go_to;    struct shift_header_type  sh;    struct reduce_header_type red;    /*******************************************************************/    /*        First, we decrease by 1 the constants NUM_SYMBOLS        */    /* and NUM_TERMINALS, remove the EMPTY symbol(1) and remap the     */    /* other symbols beginning at 1.  If default reduction is          */    /* requested, we assume a special DEFAULT_SYMBOL with number zero. */    /*******************************************************************/    eoft_image--;    accept_image--;    if (error_maps_bit)    {        error_image--;        eolt_image--;    }    num_terminals--;    num_symbols--;    /***************************************************************/    /* Remap all the symbols used in GOTO and REDUCE actions.      */    /* Remap all the symbols used in GD_RANGE.                     */    /* Remap all the symbols used in the range of SCOPE.           */    /* Release space trapped by the maps IN_STAT and FIRST.        */    /***************************************************************/    for ALL_STATES(state_no)    {        go_to = statset[state_no].go_to;        for (i = 1; i <= go_to.size; i++)            GOTO_SYMBOL(go_to, i)--;        red = reduce[state_no];        for (i = 1; i <= red.size; i++)            REDUCE_SYMBOL(red, i)--;    }    for ALL_LA_STATES(state_no)    {        red = lastats[state_no].reduce;        for (i = 1; i <= red.size; i++)            REDUCE_SYMBOL(red, i)--;    }    for (i = 1; i <= gotodom_size; i++)        gd_range[i]--;    for (i = 1; i <= num_scopes; i++)    {        scope[i].lhs_symbol--;        scope[i].look_ahead--;    }    for (i = 1; i <= scope_rhs_size; i++)    {        if (scope_right_side[i] != 0)            scope_right_side[i]--;    }    /*******************************************************************/    /* Remap all symbols in the domain of the Shift maps.              */    /*******************************************************************/    for (i = 1; i <= num_shift_maps; i++)    {        sh = shift[i];        for (j = 1; j <= sh.size; j++)            SHIFT_SYMBOL(sh, j)--;    }    /*******************************************************************/    /* Remap the left-hand side of all the rules.                      */    /*******************************************************************/    for ALL_RULES(rule_no)        rules[rule_no].lhs--;    /*******************************************************************/    /* Remap the dot symbols in ITEM_TABLE.                            */    /*******************************************************************/    if (error_maps_bit)    {        for ALL_ITEMS(i)            item_table[i].symbol--;    }    /*******************************************************************/    /* We update the SYMNO map.                                        */    /*******************************************************************/    for ALL_SYMBOLS(symbol)        symno[symbol] = symno[symbol + 1];    /*******************************************************************/    /* If Goto Default and/or Shift Default were requested, process    */    /* appropriately.                                                  */    /*******************************************************************/    if (shift_default_bit)        compute_shift_default();    if (goto_default_bit)        compute_goto_default();    /******************************************************************/    /* Release the pool of temporary space.                           */    /******************************************************************/    free_temporary_space();    /*****************************************************************/    /* We allocate the necessary structures, open the appropriate    */    /* output file and call the appropriate compression routine.     */    /*****************************************************************/    if (error_maps_bit)    {        naction_symbols = (SET_PTR)                          calloc(num_states + 1,                                 non_term_set_size * sizeof(BOOLEAN_CELL));        if (naction_symbols == NULL)            nospace(__FILE__, __LINE__);        action_symbols = (SET_PTR)                         calloc(num_states + 1,                                term_set_size * sizeof(BOOLEAN_CELL));        if (action_symbols == NULL)            nospace(__FILE__, __LINE__);    }    output_buffer = (char *) calloc(IOBUFFER_SIZE, sizeof(char));    if (output_buffer == NULL)        nospace(__FILE__, __LINE__);    if ((! c_bit) && (! cpp_bit) && (! java_bit))    {#if defined(C370) && !defined(CW)        int size;        size = PARSER_LINE_SIZE ;        if (record_format != 'F')            size += 4;        sprintf(msg_line, "w, recfm=%cB, lrecl=%d",                          record_format, size);        if((systab = fopen(tab_file, msg_line)) == NULL)#else        if((systab = fopen(tab_file, "w")) == NULL)#endif        {            fprintf(stderr,                    "***ERROR: Table file \"%s\" cannot be opened\n",                    tab_file);            exit(12);        }    }    if (table_opt == OPTIMIZE_SPACE)        cmprspa();    else if (table_opt == OPTIMIZE_TIME)        cmprtim();    if ((! c_bit) && (! cpp_bit) && (! java_bit))        fclose(systab);/*********************************************************************//* If printing of the states was requested,  print the new mapping   *//* of the states.                                                    *//*********************************************************************/    if (states_bit)    {        PR_HEADING;        fprintf(syslis,                "\nMapping of new state numbers into "                "original numbers:\n");        for ALL_STATES(i)             fprintf(syslis,                     "\n%5d  ==>>  %5d",ordered_state[i], state_list[i]);        fprintf(syslis,"\n");    }    return;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -