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

📄 timetab.c

📁 一个非常好的检索工具
💻 C
📖 第 1 页 / 共 3 页
字号:
        PRNT(msg_line);    }    sprintf(msg_line,"     Number of Gotos: %d",goto_count);    PRNT(msg_line);    sprintf(msg_line,            "     Number of Goto/Reduces: %d",goto_reduce_count);    PRNT(msg_line);    sprintf(msg_line,"     Number of Reduces: %d",reduce_count);    PRNT(msg_line);    sprintf(msg_line,"     Number of Defaults: %d",default_count);    PRNT(msg_line);/*********************************************************************//* Prepare Header with proper information, and write it out.         *//*********************************************************************/    output_buffer[0] = 'T';    output_buffer[1] = (goto_default_bit ? '1' : '0');    output_buffer[2] = (nt_check_bit ? '1' : '0');    output_buffer[3] = (read_reduce_bit ? '1' : '0');    output_buffer[4] = (single_productions_bit ? '1' : '0');    if (default_opt == 0)        output_buffer[5] = '0';    else if (default_opt == 1)        output_buffer[5] = '1';    else if (default_opt == 2)        output_buffer[5] = '2';    else if (default_opt == 3)        output_buffer[5] = '3';    else if (default_opt == 4)        output_buffer[5] = '4';    else        output_buffer[5] = '5';    output_buffer[6] = (rules[1].lhs == accept_image ? '1' : '0');    output_buffer[7] = (error_maps_bit ? '1' : '0');    output_buffer[8] = (byte_bit && last_symbol <= 255 ? '1' : '0');    output_buffer[9] = escape;    output_ptr = &output_buffer[0] + 10;    field(num_terminals, 5);    field(num_symbols, 5);    field(num_rules, 5);    field(num_states, 5);    field(table_size, 5);    field(action_size, 5);    field(state_index[1] + num_rules, 5);    field(eoft_image, 5);    field(accept_act, 5);    field(error_act, 5);    field(la_state_offset, 5);    field(lalr_level, 5);    *output_ptr++ = '\n';    /*********************************************************/    /* We write the terminal symbols map.                    */    /*********************************************************/    for (symbol = 1; symbol <= num_symbols; symbol++)    {        if (is_terminal[symbol_map[symbol]])        {            int len;            if (last_terminal < symbol_map[symbol])                last_terminal = symbol_map[symbol];            tok = RETRIEVE_STRING(symbol);            if (tok[0] == '\n')  /* We're dealing with special symbol?  */                tok[0] = escape; /* replace initial marker with escape. */            len = strlen(tok);            field(symbol_map[symbol], 4);            field(len, 4);            if (len <= 64)                strcpy(output_ptr, tok);            else            {                memcpy(output_ptr, tok, 64);                output_ptr += 64;                *output_ptr++ = '\n';                *output_ptr = '\0';                BUFFER_CHECK(systab);                tok += 64;                for (len = strlen(tok); len > 72; len = strlen(tok))                {                    memcpy(output_ptr, tok, 72);                    output_ptr += 72;                    *output_ptr++ = '\n';                    BUFFER_CHECK(systab);                    tok += 72;                }                memcpy(output_ptr, tok, len);            }            output_ptr += len;            *output_ptr++ = '\n';            BUFFER_CHECK(systab);        }    }    /*********************************************************/    /* We write the non-terminal symbols map.                */    /*********************************************************/    for (symbol = 1; symbol <= num_symbols; symbol++)    {        if (! is_terminal[symbol_map[symbol]])        {            int len;            if (last_non_terminal < symbol_map[symbol])                last_non_terminal = symbol_map[symbol];            tok = RETRIEVE_STRING(symbol);            if (tok[0] == '\n')  /* we're dealing with special symbol?  */                tok[0] = escape; /* replace initial marker with escape. */            len = strlen(tok);            field(symbol_map[symbol], 4);            field(len, 4);            if (len <= 64)                strcpy(output_ptr, tok);            else            {                memcpy(output_ptr, tok, 64);                output_ptr += 64;                *output_ptr++ = '\n';                BUFFER_CHECK(systab);                tok += 64;                for (len = strlen(tok); len > 72; len = strlen(tok))                {                    memcpy(output_ptr, tok, 72);                    output_ptr += 72;                    *output_ptr++ = '\n';                    BUFFER_CHECK(systab);                    tok += 72;                }                memcpy(output_ptr, tok, len);            }            output_ptr += len;            *output_ptr++ = '\n';            BUFFER_CHECK(systab);        }    }    /*********************************************************************/    /* Write size of right hand side of rules followed by CHECK table.   */    /*********************************************************************/    k = 0;    for (i = 1; i <= num_rules; i++)    {        field(RHS_SIZE(i), 4);        k++;        if (k == 18)        {            *output_ptr++ = '\n';            BUFFER_CHECK(systab);            k = 0;        }    }    for (i = 1; i <= (int) table_size; i++)    {        field(check[i], 4);        k++;        if (k == 18)        {            *output_ptr++ = '\n';            BUFFER_CHECK(systab);            k = 0;        }    }    if (k != 0)    {        *output_ptr++ = '\n';        BUFFER_CHECK(systab);    }    /*********************************************************************/    /* Write left hand side symbol of rules followed by ACTION table.    */    /*********************************************************************/    k = 0;    for (i = 1; i <= num_rules; i++)    {        field(symbol_map[rules[i].lhs], 6);        k++;        if (k == 12)        {            *output_ptr++ = '\n';            BUFFER_CHECK(systab);            k = 0;        }    }    for (i = 1; i <= (int) action_size; i++)    {        field(action[i], 6);        k++;        if (k == 12)        {            *output_ptr++ = '\n';            BUFFER_CHECK(systab);            k = 0;        }    }    if (k != 0)    {        *output_ptr++ = '\n';        BUFFER_CHECK(systab);    }    /******************************************************************/    /* If GOTO_DEFAULT is requested, we print out the GOTODEF vector  */    /* after rearranging its elements based on the new ordering of the*/    /* symbols.  The array TEMP is used to hold the GOTODEF values.   */    /******************************************************************/    if (goto_default_bit)    {        short *default_map;        default_map = Allocate_short_array(num_symbols + 1);        for (i = 0; i <= num_symbols; i++)           default_map[i] = error_act;        for ALL_NON_TERMINALS(symbol)        {            act = gotodef[symbol];            if (act < 0)                result_act = -act;            else if (act > 0)                result_act = state_index[act] + num_rules;            else                result_act = error_act;            default_map[symbol_map[symbol]] = result_act;        }        k = 0;        for (symbol = 1; symbol <= num_symbols; symbol++)        {            k++;            field(default_map[symbol], 6);            if (k == 12)            {                *output_ptr++ = '\n';                BUFFER_CHECK(systab);                k = 0;            }        }        if (k != 0)        {            *output_ptr++ = '\n';            BUFFER_CHECK(systab);        }    }/*********************************************************************//* We first sort the new state numbers.  A bucket sort technique     *//* is used using the ACTION vector as a base to simulate the         *//* buckets.  NOTE: the iteration over the buckets is done backward   *//* because we also construct a list of the original state numbers    *//* that reflects the permutation of the new state numbers.           *//* During the backward iteration,  we construct the list as a stack. *//*********************************************************************/    if (error_maps_bit || states_bit)    {        int max_indx;        max_indx = accept_act - num_rules - 1;        for (i = 1; i <= max_indx; i++)            action[i] = OMEGA;        for ALL_STATES(state_no)            action[state_index[state_no]] = state_no;        j = num_states + 1;        for (i = max_indx; i >= 1; i--)        {            state_no = action[i];            if (state_no != OMEGA)            {                j--;                ordered_state[j] = i + num_rules;                state_list[j] = state_no;            }        }    }    ffree(next);    ffree(previous);/*********************************************************************//* If ERROR_MAPS are requested, we print them out in the following   *//* order:                                                            *//*                                                                   *//*    1) The FOLLOW map (NEWFOLL)                                    *//*    2) The SORTED_STATE vector                                     *//*    3) The ORIGINAL_STATE vector                                   *//*    4) The map from states into valid symbols on which actions are *//*       defined within the state in question: ACTION_SYMBOLS        *//*    5) The map from each symbol into the set of states that can    *//*       possibly be reached after a transition on the symbol in     *//*       question: TRANSITION_STATES                                 *//*                                                                   *//*********************************************************************/    if (error_maps_bit)        process_error_maps();    fwrite(output_buffer, sizeof(char),           output_ptr - &output_buffer[0], systab);    return;}/*********************************************************************//*                            CMPRTIM:                               *//*********************************************************************//* In this routine we compress the State tables and write them out   *//* to a file.  The emphasis here is in generating tables that allow  *//* fast access. The terminal and non-terminal tables are compressed  *//* together, so as to achieve maximum speed efficiency.              *//* Otherwise, the compression technique used in this table is        *//* analoguous to the technique used in the routine CMPRSPA.          *//*********************************************************************/void cmprtim(void){    remap_symbols();    overlap_tables();    if (c_bit || cpp_bit || java_bit)        print_time_parser();    else        print_tables();    return;}

⌨️ 快捷键说明

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