📄 tabutil.c
字号:
/* $Id: tabutil.c,v 1.2 1999/11/04 14:02:23 shields Exp $ *//* This software is subject to the terms of the IBM Jikes Compiler License Agreement available at the following URL: http://www.ibm.com/research/jikes. Copyright (C) 1983, 1999, International Business Machines Corporation and others. All Rights Reserved. You must accept the terms of that agreement to use this software.*/static char hostfile[] = __FILE__;#include <string.h>#include "common.h"#include "header.h"static const char digits[] = "0123456789";/**************************************************************************//* PRNT_SHORTS: *//**************************************************************************/void prnt_shorts(char *title, int init, int bound, int perline, short *array){ int i, k; mystrcpy(title); padline(); k = 0; for (i = init; i <= bound; i++) { itoc(array[i]); *output_ptr++ = COMMA; k++; if (k == perline && i != bound) { *output_ptr++ = '\n'; BUFFER_CHECK(sysdcl); padline(); k = 0; } } if (k != 0) { *(output_ptr - 1) = '\n'; BUFFER_CHECK(sysdcl); } if (java_bit) mystrcpy(" };\n"); else mystrcpy(" };\n"); return;}/**************************************************************************//* PRNT_INTS: *//**************************************************************************/void prnt_ints(char *title, int init, int bound, int perline, int *array){ int i, k; mystrcpy(title); padline(); k = 0; for (i = init; i <= bound; i++) { itoc(array[i]); *output_ptr++ = COMMA; k++; if (k == perline && i != bound) { *output_ptr++ = '\n'; BUFFER_CHECK(sysdcl); padline(); k = 0; } } if (k != 0) { *(output_ptr - 1) = '\n'; BUFFER_CHECK(sysdcl); } if (java_bit) mystrcpy(" };\n"); else mystrcpy(" };\n"); return;}/***************************************************************************//* MYSTRCPY: *//***************************************************************************/void mystrcpy(char *str){ while (*str != '\0') *output_ptr++ = *str++; BUFFER_CHECK(sysdcl); return;}/***************************************************************************//* PADLINE: *//***************************************************************************/void padline(void){ register int i; for (i = 0; i < 12; i++) *output_ptr++ = ' '; return;}/***************************************************************************//* ITOC: *//***************************************************************************//* ITOC takes as arguments an integer NUM. NUM is an integer containing at *//* most 11 digits which is converted into a character string and placed in *//* the iobuffer. Leading zeros are eliminated and if the number is *//* negative, a leading "-" is added. *//***************************************************************************/void itoc(int num){ register int val; register char *p; char tmp[12]; val = ABS(num); tmp[11] = '\0'; p = &tmp[11]; do { p--; *p = digits[val % 10]; val /= 10; } while(val > 0); if (num < 0) { p--; *p = '-'; } while(*p != '\0') *(output_ptr++) = *(p++); return;}/***************************************************************************//* FIELD: *//***************************************************************************//* FIELD takes as arguments two integers: NUM and LEN. NUM is an integer *//* containing at most LEN digits which is converted into a character *//* string and placed in the iobuffer. *//* Leading zeros are replaced by blanks and if the number is negative, a *//* leading "-" is added. *//***************************************************************************/void field(int num, int len){ register int val; register char *p; val = ABS(num); p = output_ptr + len; do { p--; *p = digits[val % 10]; val /= 10; } while(val > 0 && p > output_ptr); if (num < 0 && p > output_ptr) { p--; *p = '-'; } while(p > output_ptr) { p--; *p = ' '; } output_ptr += len; return;}/***************************************************************************//* SORTDES: *//***************************************************************************//* SORTDES sorts the elements of ARRAY and COUNT in the range LOW..HIGH *//* based on the values of the elements of COUNT. Knowing that the maximum *//* value of the elements of count cannot exceed MAX and cannot be lower *//* than zero, we can use a bucket sort technique. *//***************************************************************************/void sortdes(short array[], short count[], int low, int high, int max){ short *bucket, *list; register int element, i, k; /*****************************************************************/ /* BUCKET is used to hold the roots of lists that contain the */ /* elements of each bucket. LIST is used to hold these lists. */ /*****************************************************************/ bucket = Allocate_short_array(max + 1); list = Allocate_short_array(high - low + 1); for (i = 0; i <= max; i++) bucket[i] = NIL;/*********************************************************************//* We now partition the elements to be sorted and place them in their*//* respective buckets. We iterate backward over ARRAY and COUNT to *//* keep the sorting stable since elements are inserted in the buckets*//* in stack-fashion. *//* *//* NOTE that it is known that the values of the elements of ARRAY *//* also lie in the range LOW..HIGH. *//*********************************************************************/ for (i = high; i >= low; i--) { k = count[i]; element = array[i]; list[element - low] = bucket[k]; bucket[k] = element; }/*********************************************************************//* Iterate over each bucket, and place elements in ARRAY and COUNT *//* in sorted order. The iteration is done backward because we want *//* the arrays sorted in descending order. *//*********************************************************************/ k = low; for (i = max; i >= 0; i--) { for (element = bucket[i]; element != NIL; element = list[element - low], k++) { array[k] = element; count[k] = i; } } ffree(bucket); ffree(list); return;}/***************************************************************************//* REALLOCATE: *//***************************************************************************//* This procedure is invoked when the TABLE being used is not large *//* enough. A new table is allocated, the information from the old table *//* is copied, and the old space is released. *//***************************************************************************/void reallocate(void){ int *n, *p; register int old_size, i; if (table_size == MAX_TABLE_SIZE) { sprintf(msg_line, "Table has exceeded maximum limit of %d", MAX_TABLE_SIZE); PRNTERR(msg_line); exit(12); } old_size = table_size; table_size = MIN(table_size + increment_size, MAX_TABLE_SIZE); if (verbose_bit) { if (table_opt == OPTIMIZE_TIME) { sprintf(msg_line, "Reallocating storage for TIME table, " "adding %d entries", table_size - old_size); } else { sprintf(msg_line, "Reallocating storage for SPACE table, " "adding %d entries", table_size - old_size); } PRNT(msg_line); } n = Allocate_int_array(table_size + 1); p = Allocate_int_array(table_size + 1); for (i = 1; i <= old_size; i++) /* Copy old information */ { n[i] = next[i]; p[i] = previous[i]; } ffree(next); ffree(previous); next = n; previous = p; if (first_index == NIL) { first_index = old_size + 1; previous[first_index] = NIL; } else { next[last_index] = old_size + 1; previous[old_size + 1] = last_index; } next[old_size + 1] = old_size + 2; for (i = old_size + 2; i < (int) table_size; i++) { next[i] = i + 1; previous[i] = i - 1; } last_index = table_size; next[last_index] = NIL; previous[last_index] = last_index - 1; return;}/*****************************************************************************//* PROCESS_ERROR_MAPS: *//*****************************************************************************//* 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 staes that can *//* possibly be reached after a transition on the symbol in *//* question: TRANSITION_STATES *//* *//*****************************************************************************/void process_error_maps(void){ short *state_start, *state_stack, *temp, *original = NULL, *symbol_root, *symbol_count, *term_list, *as_size, *action_symbols_range, *naction_symbols_range; int offset, item_no, lhs_symbol, state_no, symbol, max_len, i, k, terminal_ubound,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -