pkg://jikespg-1.2-1.src.rpm:192114/jikespg-1.2.tar.gz
info downloads
jikespg/ 40775 764 764 0 7010312223 11746 5 ustar shields shields jikespg/src/ 40775 764 764 0 7010312223 12535 5 ustar shields shields jikespg/src/Makefile 100664 764 764 4220 7010310755 14300 0 ustar shields shields # $Id: Makefile,v 1.2 1999/11/04 14:02:21 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.
# Makefile for aix for Jikes Parser Generator
CC = xlc -O
all: jikespg
jikespg: ctabs.o globals.o lpgparse.o lpgutil.o main.o \
mkfirst.o mkred.o mkstates.o partset.o prntstat.o produce.o \
ptables.o remsp.o resolve.o spacetab.o tabutil.o timetab.o
$(CC) -s -o jikespg ctabs.o globals.o lpgparse.o lpgutil.o main.o \
mkfirst.o mkred.o mkstates.o partset.o prntstat.o produce.o \
ptables.o remsp.o resolve.o spacetab.o tabutil.o timetab.o
lpgact.i: jikespg.g
lpg jikespg
rm jikespg.l
make
rm CRASH_THE_INITIAL_MAKE_COMMAND_TO_BREAK_OUT
main.o: main.c common.h
$(CC) -c main.c
globals.o: globals.c common.h
$(CC) -c globals.c
lpgparse.o: lpgprs.h lpgdcl.h lpgdef.h lpgact.h lpgact.i lpgsym.h \
common.h lpgparse.h lpgparse.c
$(CC) -c lpgparse.c
lpgutil.o: lpgutil.c common.h
$(CC) -c lpgutil.c
mkfirst.o: mkfirst.c common.h
$(CC) -c mkfirst.c
mkstates.o: mkstates.c common.h
$(CC) -c mkstates.c
prntstat.o: prntstat.c common.h
$(CC) -c prntstat.c
mkred.o: mkred.c common.h reduce.h
$(CC) -c mkred.c
remsp.o: remsp.c common.h reduce.h
$(CC) -c remsp.c
resolve.o: resolve.c common.h reduce.h
$(CC) -c resolve.c
ptables.o: ptables.c common.h
$(CC) -c ptables.c
spacetab.o: spacetab.c common.h space.h
$(CC) -c spacetab.c
timetab.o: timetab.c common.h
$(CC) -c timetab.c
tabutil.o: tabutil.c common.h
$(CC) -c tabutil.c
produce.o: produce.c common.h
$(CC) -c produce.c
partset.o: partset.c common.h
$(CC) -c partset.c
ctabs.o: ctabs.c common.h space.h
$(CC) -c ctabs.c
clean:
rm jikespg
rm ctabs.o
rm globals.o
rm lpgparse.o
rm lpgutil.o
rm main.o
rm mkfirst.o
rm mkred.o
rm mkstates.o
rm partset.o
rm prntstat.o
rm produce.o
rm ptables.o
rm remsp.o
rm resolve.o
rm spacetab.o
rm tabutil.o
rm timetab.o
jikespg/src/Makefile.am 100664 764 764 1536 6660400662 14712 0 ustar shields shields bin_PROGRAMS = jikespg
jikespg_SOURCES = ctabs.c \
globals.c \
lpgparse.c \
lpgutil.c \
main.c \
mkfirst.c \
mkred.c \
mkstates.c \
partset.c \
prntstat.c \
produce.c \
ptables.c \
remsp.c \
resolve.c \
spacetab.c \
tabutil.c \
timetab.c
noinst_HEADERS = c370.h \
common.h \
header.h \
lpgact.h \
lpgact.i \
lpgdcl.h \
lpgdef.h \
lpgparse.h \
lpgprs.h \
lpgsym.h \
reduce.h \
space.h
jikespg/src/c370.h 100664 764 764 23522 7010310755 13513 0 ustar shields shields /* $Id: c370.h,v 1.2 1999/11/04 14:02:21 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.
*/
#ifndef C370_INCLUDED
#define C370_INCLUDED
#if defined(C370) || defined(CW)
#define accept_act acc_act
#define accept_image accptimg
#define action_bit actn_bit
#define action_pool act_pool
#define action_size act_size
#define action_symbols actsymbs
#define action_symbols actsymbs
#define action_symbols_index_proc asiproc
#define adequate_item adqitem
#define allocate_boolean_array alcbooln
#define allocate_int_array alocint
#define allocate_short_array alocshrt
#define allocate_goto_map alcgotmp
#define allocate_node alocnode
#define allocate_reduce_map alcredmp
#define allocate_shift_map alcshfmp
#define allocate_sr_conflict_element alcsrcnf
#define allocate_rr_conflict_element alcrrcnf
#define automatic_scope_procs autoscpr
#define byte_terminal_range bytterg
#define check_size chksize
#define compute_action_symbols_range compasr
#define compute_closure compclo
#define compute_first compfrst
#define compute_follow compfoll
#define compute_goto_default c_goto_def
#define compute_la cmpt_la
#define compute_naction_symbols_range compnasr
#define compute_next_conflict_set cnc_set
#define compute_next_conflict_source cncsrce
#define compute_next_la c_nxt_la
#define compute_shift_default cmp_shift_def
#define conflict_pool cnflpool
#define conflicts_bit conflbit
#define conflicts_initialization_done cid
#define debug_bit dbugbit
#define declarations declratn
#define default_opt def_opt
#define deferred_bit dfrdbit
#define deferred_parser_loop defprslp
#define deferred_recovery_proc defreclp
#define dump_tables dumptabs
#define eoft_conflict_trace eoftctr
#define eoft_image eoftimge
#define eolt_image eolimag
#define error_act er_act
#define error_image errorimg
#define error_maps_bit errmpbit
#define error_procs errprocs
#define exit_lalrk_process exitlak
#define init_lalrk_process initlak
#define init_rmpself initrmp
#define file_prefix flprefx
#define first_bit firstbit
#define first_index frstindx
#define follow_bit follwbit
#define free_conflict_space freecsp
#define free_nodes freenode
#define free_temporary_space freetspa
#define global_declarations globldcl
#define global_space_allocated gspalloc
#define global_space_used gspausd
#define goto_default_bit gdefbit
#define goto_size gotosize
#define gotodom_size godm_sze
#define hact_file hactfile
#define highest_level highstlv
#define increment incremt
#define increment_size incrsze
#define item_list itemlist
#define item_table itemtabl
#define la_offset laoffset
#define la_state_root lastatrt
#define la_traverse latravrs
#define lalr_level lalrlevl
#define last_index lastindx
#define last_non_terminal lstnontr
#define last_symbol lastsymb
#define last_terminal lastterm
#define lpgaccess laccess
#define macro_declarations macrdecl
#define manual_scope_procs manlscpr
#define max_la_state mxlastat
#define max_name_length maxnmlen
#define maximum_distance maxdist
#define minimum_distance mindist
#define naction_symbols nactnsym
#define naction_symbols nactnsym
#define naction_symbols_index_proc nasiproc
#define names_opt namesopt
#define new_state_element newstelm
#define new_state_elemt nwstelmt
#define no_error_procs noerprcs
#define non_term_set_size ntsetsiz
#define nt_check_bit ntchkbit
#define num_entries n_entrys
#define num_error_rules nerrule
#define num_first_sets nfrstset
#define num_goto_reduces n_gotord
#define num_gotos numgotos
#define num_items n_items
#define num_names n_names
#define num_non_terminals n_nontml
#define num_reductions n_redctn
#define num_rr_conflicts n_rrcnfl
#define num_rules n_rules
#define num_scopes numscps
#define num_shift_maps nshftmap
#define num_shift_reduces n_shred
#define num_shifts n_shifts
#define num_single_productions n_sngprd
#define num_sr_conflicts n_sr_cnf
#define num_states n_states
#define num_symbols n_syms
#define num_table_entries ntabentr
#define num_terminal_states nterm_st
#define num_terminals n_termnl
#define number_len numlen
#define ordered_state ordstat
#define output_buffer outbuf
#define output_line_no oplnnum
#define output_ptr outptr
#define output_size outptsz
#define overlap_nt_rows ovrlntrw
#define overlap_t_rows ovrlptrw
#define overlap_tables ovrltabl
#define overlay_sim_t_rows ostermrw
#define parser_loop prsrloop
#define previous prevs
#define primary_threshold primthr
#define print_space_parser prcsppr
#define print_time_parser prctimp
#define print_item prntitem
#define print_large_token prlrgtok
#define print_relevant_slr_items prslritm
#define print_state pr_state
#define process_conflicts pcnflcts
#define process_error_maps perrmps
#define process_input prc_inpt
#define process_tables p_tables
#define read_input readinpt
#define read_reduce_bit rdredbit
#define real_shift_number rshifnm
#define reallocate rallcte
#define record_format recrdfmt
#define reduce_list red_lst
#define reduce_root red_root
#define reduce_size redcesz
#define remove_single_productions remsp
#define reset_temporary_space resettsp
#define resolve_conflicts rslvconf
#define restore_symbol restsym
#define rr_conflict_root rrcnflrt
#define scope_rhs_size scrhssz
#define scope_right_side scrtsde
#define scope_state scpstat
#define scope_state_size scstsze
#define scopes_bit scpbit
#define secondary_threshold secthrd
#define shift_check_index shchindx
#define shift_check_size shchksz
#define shift_default_bit shdefbit
#define shift_domain_count shdmn_ct
#define shift_image shimage
#define shift_size shftsize
#define single_productions_bit sp_bit
#define sr_conflict_root srcnflrt
#define stack_size stksize
#define stat_list statlist
#define state_index statindx
#define state_list statelst
#define state_set_size ssetsiz
#define states_bit statesbt
#define states_of st_of
#define string_offset stroffst
#define string_size strsize
#define string_table s_tab
#define symbol_map symbmap
#define symno_size symno_sz
#define table_opt tab_opt
#define table_size tab_size
#define temporary_space_allocated tspalloc
#define temporary_space_used tspausd
#define term_action_size t_act_sz
#define term_check_size t_ch_sze
#define term_set_size tsetsiz
#define term_state_index tstindx
#define trace_access traceac
#define trace_opt trce_opt
#define trace_pool trace_pl
#define translate trnslte
#define verbose_bit verb_bit
#define warnings_bit warnbit
#endif
#endif /* C370_INCLUDED */
jikespg/src/common.h 100664 764 764 100046 7010310755 14344 0 ustar shields shields /* $Id: common.h,v 1.2 1999/11/04 14:02:21 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.
*/
#ifndef COMMON_INCLUDED
#define COMMON_INCLUDED
/*******************************************************************/
/* One of the switches below may have to be set prior to building */
/* JIKES PG. OS2 is for all C compilers running under OS2. DOS is */
/* for all C compilers running under DOS. Note that to run under */
/* DOS, the compiler used must support the Huge model (32-bit ptr */
/* simulation). C370 is for the IBM C compiler running under CMS */
/* or MVS. CW is for the Waterloo C compiler running under VM/CMS. */
/* */
/* This system was built to run on a vanilla Unix or AIX system. */
/* No switch need to be set for such an environment. Set other */
/* switch(es) as needed. Note that the switch C370 should always */
/* be accompanied by either the switch VM or the switch MVS. */
/* */
/*******************************************************************/
/*
#define DOS
#define OS2
#define MVS
#define CW
#define C370
#define VM
*/
#include <assert.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include "c370.h"
/*******************************************************************/
/*******************************************************************/
/** **/
/** GLOBAL CONSTANTS **/
/** **/
/*******************************************************************/
/*******************************************************************/
#define PR_HEADING \
{ \
fprintf(syslis, "\f\n\n %-39s%s %-30.24s Page %d\n\n",\
HEADER_INFO, VERSION, timeptr, ++page_no);\
output_line_no = 4;\
}
#define MAX_PARM_SIZE 22
#define SYMBOL_SIZE 256
#define MAX_MSG_SIZE (256 + SYMBOL_SIZE)
#define PRINT_LINE_SIZE 80
#define PARSER_LINE_SIZE 80
#define MAX_LINE_SIZE 256
#undef PAGE_SIZE
#define PAGE_SIZE 55
#define OPTIMIZE_TIME 1
#define OPTIMIZE_SPACE 2
#define MINIMUM_NAMES 1
#define MAXIMUM_NAMES 2
#define OPTIMIZE_PHRASES 3
#define NOTRACE 0
#define TRACE_CONFLICTS 1
#define TRACE_FULL 2
#define STATE_TABLE_UBOUND 1020
#define STATE_TABLE_SIZE (STATE_TABLE_UBOUND + 1) /* 1021 is a prime */
#define SHIFT_TABLE_UBOUND 400
#define SHIFT_TABLE_SIZE (SHIFT_TABLE_UBOUND + 1) /* 401 is a prime */
#define SCOPE_UBOUND 100
#define SCOPE_SIZE (SCOPE_UBOUND + 1) /* 101 is prime */
#undef FALSE
#undef TRUE
#define FALSE 0
#define TRUE 1
#define IS_A_TERMINAL <= num_terminals
#define IS_A_NON_TERMINAL > num_terminals
#define SPACE ' '
#define COMMA ','
#define INFINITY ((short) SHRT_MAX)
#define OMEGA ((short) SHRT_MIN)
#define NIL ((short) SHRT_MIN + 1)
#define DEFAULT_SYMBOL 0
/*******************************************************************/
/*******************************************************************/
/** **/
/** ALLOCATE/FREE MACROS **/
/** **/
/*******************************************************************/
/*******************************************************************/
/* The following macro definitions are used to preprocess calls to */
/* allocate routines that require locations. The FFREE macro is */
/* normally an invocation to the FREE routine. It is encoded as */
/* a macro here in case we need to do some debugging on dynamic */
/* storage. */
/*******************************************************************/
#define Allocate_node() allocate_node(hostfile, __LINE__)
#define Allocate_int_array(n) allocate_int_array(n, hostfile, __LINE__)
#define Allocate_short_array(n) allocate_short_array(n, hostfile, __LINE__)
#define Allocate_boolean_array(n) allocate_boolean_array(n, hostfile, __LINE__)
#define Allocate_goto_map(n) allocate_goto_map(n, hostfile, __LINE__)
#define Allocate_shift_map(n) allocate_shift_map(n, hostfile, __LINE__)
#define Allocate_reduce_map(n) allocate_reduce_map(n, hostfile, __LINE__)
#define ffree(x) free(x) /* { free(x); x = (void *) ULONG_MAX; } */
/*******************************************************************/
/*******************************************************************/
/** **/
/** PARSING MACROS **/
/** **/
/*******************************************************************/
/*******************************************************************/
/* The following macro definitions are used only in processing the */
/* input source. */
/*******************************************************************/
#define EQUAL_STRING(symb, p) \
(strcmp((symb), string_table + (p) -> st_ptr) == 0)
#define EXTRACT_STRING(indx) (&string_table[indx])
#define HT_SIZE 701 /* 701 is a prime */
#define RULEHDR_INCREMENT 1024
#define ACTELMT_INCREMENT 1024
#define DEFELMT_INCREMENT 16
#ifdef DOS
#define IOBUFFER_SIZE 8192
#else
#define IOBUFFER_SIZE 65536
#endif
/*******************************************************************/
/*******************************************************************/
/** **/
/** BIT SET MACROS **/
/** **/
/*******************************************************************/
/*******************************************************************/
/* The following macros are used to define operations on sets that */
/* are represented as bit-strings. BOOLEAN_CELL is a type that is */
/* used as the elemental unit used to construct the sets. For */
/* example, if BOOLEAN_CELL consists of four bytes and assumming */
/* that each byte contains 8 bits then the constant SIZEOF_BC */
/* represents the total number of bits that is contained in each */
/* elemental unit. */
/* */
/* In general, a parameter called "set" or "set"i, where i is an */
/* integer, is a pointer to a set or array of sets; a parameter */
/* called "i" or "j" represents an index in an array of sets; a */
/* parameter called "b" represents a particular element (or bit) */
/* within a set. */
/* */
/*******************************************************************/
#define SIZEOF_BC (sizeof(BOOLEAN_CELL) * CHAR_BIT)
#define BC_OFFSET (SIZEOF_BC - 1)
/*******************************************************************/
/* This macro takes as argument an array of bit sets called "set", */
/* an integer "nt" indicating the index of a particular set in the */
/* array and an integer "t" indicating a particular element within */
/* the set. IS_IN_SET check whether ot not the element "t" is in */
/* the set "set(nt)". */
/* */
/* The value (nt*term_set_size) is used to determine the starting */
/* address of the set element in question. The value */
/* (??? / SIZEOF_BC) is used to determine the actual BOOLEAN_CELL */
/* containing the bit in question. Finally, the value */
/* (SIZEOF_BC - (t % SIZEOF_BC)) identifies the actual bit in the */
/* unit. The bit in question is pushed to the first position and */
/* and-ed with the value 01. This operation yields the value TRUE */
/* if the bit is on. Otherwise, the value FALSE is obtained. */
/* Recall that in C, one cannot shift (left or right) by 0. This */
/* is why the ? is used here. */
/*******************************************************************/
#define IS_IN_SET(set, i, b) /* is b in set[i] ? */ \
((set)[(i) * term_set_size + (((b) - 1) / SIZEOF_BC)] & \
(((b) + BC_OFFSET) % SIZEOF_BC ? \
(BOOLEAN_CELL) 1 << (((b) + BC_OFFSET) % SIZEOF_BC) : \
(BOOLEAN_CELL) 1))
/*******************************************************************/
/* The macro SET_UNION takes as argument two arrays of sets: */
/* "set1" and "set2", and two integers "i" and "j" which are */
/* indices to be used to access particular sets in "set1" and */
/* "set2", respectively. SET_UNION computes the union of the two */
/* sets in question and places the result in the relevant set in */
/* "set1". */
/* */
/* The remaining macros are either analoguous to IS_IN_SET or */
/* SET_UNION. */
/* */
/* Note that a macro with the variable "kji" declared in its body */
/* should not be invoked with a parameter of the same name. */
/* */
/*******************************************************************/
#define SET_UNION(set1, i, set2, j) /* set[i] union set2[j] */ \
{ \
register int kji; \
for (kji = 0; kji < term_set_size; kji++) \
(set1)[(i) * term_set_size + kji] |= \
(set2)[(j) * term_set_size + kji]; \
}
#define INIT_SET(set) /* set = {} */ \
{ \
register int kji; \
for (kji = 0; kji < term_set_size; kji++) \
(set)[kji] = 0; \
}
#define ASSIGN_SET(set1, i, set2, j) /* set1[i] = set2[j] */ \
{ \
register int kji; \
for (kji = 0; kji < term_set_size; kji++) \
(set1)[(i) * term_set_size + kji] = \
(set2)[(j) * term_set_size + kji]; \
}
#define SET_BIT_IN(set, i, b) /* set[i] = set[i] with b; */ \
(set)[(i) * term_set_size + (((b) - 1) / SIZEOF_BC)] |= \
(((b) + BC_OFFSET) % SIZEOF_BC ? \
(BOOLEAN_CELL) 1 << (((b) + BC_OFFSET) % SIZEOF_BC) : \
(BOOLEAN_CELL) 1);
#define RESET_BIT_IN(set, i, b) /* set[i] = set[i] less b; */ \
(set)[(i) * term_set_size + (((b) - 1) / SIZEOF_BC)] &= \
~(((b) + BC_OFFSET) % SIZEOF_BC ? \
(BOOLEAN_CELL) 1 << (((b) + BC_OFFSET) % SIZEOF_BC): \
(BOOLEAN_CELL) 1);
/*******************************************************************/
/* The following macros are analogous to the ones above, except */
/* that they deal with sets of non-terminals instead of sets of */
/* terminals. */
/*******************************************************************/
#define IS_IN_NTSET(set, i, b) /* is b in set[i] ? */ \
((set)[(i) * non_term_set_size + (((b) - 1) / SIZEOF_BC)] & \
(((b) + BC_OFFSET) % SIZEOF_BC ? \
(BOOLEAN_CELL) 1 << (((b) + BC_OFFSET) % SIZEOF_BC) : \
(BOOLEAN_CELL) 1))
#define NTSET_UNION(set1, i, set2, j) /* set1[i] union set2[j] */ \
{ \
register int kji; \
for (kji = 0; kji < non_term_set_size; kji++) \
(set1)[(i) * non_term_set_size + kji] |= \
(set2)[(j) * non_term_set_size + kji]; \
}
#define INIT_NTSET(set) /* set = {} */ \
{ \
register int kji; \
for (kji = 0; kji < non_term_set_size; kji++) \
(set)[kji] = 0; \
}
#define ASSIGN_NTSET(set1, i, set2, j) /* set1[i] = set2[j] */ \
{ \
register int kji; \
for (kji = 0; kji < non_term_set_size; kji++) \
(set1)[(i) * non_term_set_size + kji] = \
(set2)[(j) * non_term_set_size + kji]; \
}
#define NTSET_BIT_IN(set, i, b) /* set[i] = set[i] with b; */ \
(set)[(i) * non_term_set_size + (((b) - 1) / SIZEOF_BC)] |= \
(((b) + BC_OFFSET) % SIZEOF_BC ? \
(BOOLEAN_CELL) 1 << (((b) + BC_OFFSET) % SIZEOF_BC) : \
(BOOLEAN_CELL) 1);
#define NTRESET_BIT_IN(set, i, b) /* set[i] = set[i] less b; */ \
(set)[(i) * non_term_set_size + (((b) - 1) / SIZEOF_BC)] &= \
~(((b) + BC_OFFSET) % SIZEOF_BC ? \
(BOOLEAN_CELL) 1 << (((b) + BC_OFFSET) % SIZEOF_BC): \
(BOOLEAN_CELL) 1);
/*******************************************************************/
/* The following macros are analogous to the ones above, except */
/* that they deal with sets of states instead of sets of terminals */
/* or non-terminals. */
/*******************************************************************/
#define SET_COLLECTION_BIT(i, b) \
collection[(i) * state_set_size + (((b) - 1) / SIZEOF_BC)] |= \
(((b) + BC_OFFSET) % SIZEOF_BC ? \
(BOOLEAN_CELL) 1 << (((b) + BC_OFFSET) % SIZEOF_BC) : \
(BOOLEAN_CELL) 1);
#define EMPTY_COLLECTION_SET(i) \
{ \
register int kji; \
for (kji = 0; kji < state_set_size; kji++) \
collection[(i) * state_set_size + kji] = 0; \
}
/*******************************************************************/
/* The following macros can be used to check, set, or reset a bit */
/* in a bit-string of any length. */
/*******************************************************************/
#define SET_BIT(set, b) \
(set)[((b) - 1) / SIZEOF_BC] |= \
(((b) + BC_OFFSET) % SIZEOF_BC ? \
(BOOLEAN_CELL) 1 << (((b) + BC_OFFSET) % SIZEOF_BC) : \
(BOOLEAN_CELL) 1);
#define RESET_BIT(set, b) \
(set)[((b) - 1) / SIZEOF_BC] &= \
~(((b) + BC_OFFSET) % SIZEOF_BC ? \
(BOOLEAN_CELL) 1 << (((b) + BC_OFFSET) % SIZEOF_BC): \
(BOOLEAN_CELL) 1);
#define IS_ELEMENT(set, b) /* is b in set ? */ \
((set)[((b) - 1) / SIZEOF_BC] & \
(((b) + BC_OFFSET) % SIZEOF_BC ? \
(BOOLEAN_CELL) 1 << (((b) + BC_OFFSET) % SIZEOF_BC) : \
(BOOLEAN_CELL) 1))
/*******************************************************************/
/*******************************************************************/
/** **/
/** ITERATION MACROS **/
/** **/
/*******************************************************************/
/*******************************************************************/
/* The following macros (ALL_) are used to iterate over a sequence.*/
/*******************************************************************/
#define ALL_LA_STATES(indx) \
(indx = num_states + 1; indx <= (int) max_la_state; indx++)
#define ALL_TERMINALS(indx) \
(indx = 1; indx <= num_terminals; indx++)
#define ALL_TERMINALS_BACKWARDS(indx) \
(indx = num_terminals; indx >= 1; indx--)
#define ALL_NON_TERMINALS(indx) \
(indx = num_terminals + 1; indx <= num_symbols; indx++)
#define ALL_NON_TERMINALS_BACKWARDS(indx) \
(indx = num_symbols; indx >= num_terminals + 1; indx--)
#define ALL_SYMBOLS(indx) (indx = 1; indx <= num_symbols; indx++)
#define ALL_ITEMS(indx) (indx = 1; indx <= (int) num_items; indx++)
#define ALL_STATES(indx) (indx = 1; indx <= (int) num_states; indx++)
#define ALL_RULES(indx) (indx = 0; indx <= num_rules; indx++)
#define ALL_RULES_BACKWARDS(indx) \
(indx = num_rules; indx >= 0; indx--)
#define ENTIRE_RHS(indx, rule_no) (indx = rules[rule_no].rhs;\
indx < rules[(rule_no) + 1].rhs;\
indx++)
#define RHS_SIZE(rule_no) (rules[(rule_no) + 1].rhs - rules[rule_no].rhs)
#define RETRIEVE_STRING(indx) (&string_table[symno[indx].ptr])
#define RETRIEVE_NAME(indx) (&string_table[name[indx]])
/*******************************************************************/
/*******************************************************************/
/** **/
/** MISCELLANEOUS MACROS **/
/** **/
/*******************************************************************/
/*******************************************************************/
#define TOUPPER(c) (islower(c) ? toupper(c) : c)
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define ABS(x) (((x) < 0) ? -(x) : (x))
#define NOT(item) (! item)
/**********************************************************************/
/* The following two macros check whether or not the value of an */
/* integer variable exceeds the maximum limit for a short or a long */
/* integer, respectively. Note that the user should declare the */
/* variable in question as a long integer. In the case of INT_CHECK, */
/* this check is meaningful only if INT and SHORT are the same size. */
/* Otherwise, if INT and LONG are of the same size, as is usually the */
/* case on large systems, this check is meaningless - too late !!! */
/**********************************************************************/
#define SHORT_CHECK(var) \
if (var > SHRT_MAX) \
{ \
PRNTERR("The limit of a short int value" \
" has been exceeded by " #var); \
exit(12); \
}
#define INT_CHECK(var) \
if (var > INT_MAX) \
{ \
PRNTERR("The limit of an int value" \
" has been exceeded by " #var); \
exit(12); \
}
#define ENDPAGE_CHECK if (++output_line_no >= PAGE_SIZE) \
PR_HEADING
#define PRNT(msg) \
{ \
printf("%s\n",msg); \
fprintf(syslis,"%s\n",msg); \
ENDPAGE_CHECK; \
}
#define PRNTWNG(msg) \
{ \
printf("***WARNING: %s\n",msg);\
fprintf(syslis,"***WARNING: %s\n",msg);\
ENDPAGE_CHECK; \
}
#define PRNTERR(msg) \
{ \
printf("***ERROR: %s\n",msg);\
fprintf(syslis,"***ERROR: %s\n",msg);\
ENDPAGE_CHECK; \
}
/*******************************************************************/
/*******************************************************************/
/** **/
/** MACROS FOR DEREFERENCING AUTOMATON HEADER STRUCTURES **/
/** **/
/*******************************************************************/
/*******************************************************************/
#define SHIFT_SYMBOL(hdr, indx) (((hdr).map)[indx].symbol)
#define SHIFT_ACTION(hdr, indx) (((hdr).map)[indx].action)
#define GOTO_SYMBOL(hdr, indx) (((hdr).map)[indx].symbol)
#define GOTO_ACTION(hdr, indx) (((hdr).map)[indx].action)
#define GOTO_LAPTR(hdr, indx) (((hdr).map)[indx].laptr)
#define REDUCE_SYMBOL(hdr, indx) (((hdr).map)[indx].symbol)
#define REDUCE_RULE_NO(hdr, indx) (((hdr).map)[indx].rule_number)
/*******************************************************************/
/*******************************************************************/
/** **/
/** OUTPUT MACROS **/
/** **/
/*******************************************************************/
/*******************************************************************/
/* The following macro definitions are used only in processing the */
/* output. */
/*******************************************************************/
#define BUFFER_CHECK(file) \
if ((IOBUFFER_SIZE - (output_ptr - &output_buffer[0])) < 73) \
{ \
fwrite(output_buffer, sizeof(char), \
output_ptr - &output_buffer[0], file); \
output_ptr = &output_buffer[0]; \
}
/*******************************************************************/
/*******************************************************************/
/** **/
/** GLOBAL DECLARATIONS **/
/** **/
/*******************************************************************/
/*******************************************************************/
typedef unsigned int BOOLEAN_CELL; /* Basic unit used to represent */
/* Bit sets */
typedef BOOLEAN_CELL *SET_PTR;
typedef char BOOLEAN;
extern const char HEADER_INFO[];
extern const char VERSION[];
extern const char BLANK[];
extern const long MAX_TABLE_SIZE;
struct node
{
struct node *next;
int value;
};
/*******************************************************************/
/* RULES is the structure that contain the rules of the grammar. */
/* Every rule of the grammar is mapped into an integer, and given */
/* rule, and we have access to a value RHS which is the index */
/* location in the vector RHS where the right-hand-side of the rule*/
/* begins. The right hand side of a certain rule represented by an*/
/* integer I starts at index location RULES[I].RHS in RHS, and */
/* ends at index location RULES[I + 1].RHS - 1. An extra */
/* NUM_RULES + 1 element is used as a "fence" for the last rule. */
/* The RHS vector as mentioned above is used to hold a complete */
/* list of allthe right-hand-side symbols specified in the grammar.*/
/*******************************************************************/
struct ruletab_type
{
short lhs,
rhs;
BOOLEAN sp;
};
struct shift_type
{
short symbol,
action;
};
struct shift_header_type
{
struct shift_type *map;
short size;
};
struct reduce_type
{
short symbol,
rule_number;
};
struct reduce_header_type
{
struct reduce_type *map;
short size;
};
struct goto_type
{
int laptr;
short symbol,
action;
};
struct goto_header_type
{
struct goto_type *map;
short size;
};
struct lastats_type
{
struct reduce_header_type reduce;
short shift_number,
in_state;
};
struct statset_type
{
struct node *kernel_items,
*complete_items;
struct goto_header_type go_to;
short shift_number;
};
extern char *timeptr;
extern long output_line_no;
extern char grm_file[],
lis_file[],
act_file[],
hact_file[],
tab_file[],
prs_file[],
sym_file[],
def_file[],
dcl_file[],
file_prefix[],
prefix[],
suffix[],
parm[],
msg_line[];
extern FILE *syslis,
*sysgrm,
*sysact,
*syshact,
*systab,
*syssym,
*sysprs,
*sysdcl,
*sysprs,
*sysdef;
/******************************************************/
/* The variables below are global counters. */
/******************************************************/
extern long num_items,
num_states,
max_la_state;
extern int num_symbols,
symno_size, /* NUM_SYMBOLS + 1 */
num_names,
num_terminals,
num_non_terminals,
num_rules,
num_conflict_elements,
num_single_productions,
gotodom_size;
/******************************************************/
/* The variables below are used for options setting. */
/******************************************************/
extern BOOLEAN list_bit,
slr_bit,
verbose_bit,
first_bit,
follow_bit,
action_bit,
edit_bit,
states_bit,
xref_bit,
nt_check_bit,
conflicts_bit,
read_reduce_bit,
goto_default_bit,
shift_default_bit,
byte_bit,
warnings_bit,
single_productions_bit,
error_maps_bit,
debug_bit,
deferred_bit,
c_bit,
cpp_bit,
java_bit,
scopes_bit;
extern int lalr_level,
default_opt,
trace_opt,
table_opt,
names_opt,
increment,
maximum_distance,
minimum_distance,
stack_size;
extern char escape,
ormark,
record_format;
extern char blockb[],
blocke[],
hblockb[],
hblocke[],
errmsg[],
gettok[],
smactn[],
tkactn[];
/*********************************************************************/
/* The variables below are used to hold information about special */
/* grammar symbols. */
/*********************************************************************/
extern short accept_image,
eoft_image,
eolt_image,
empty,
error_image;
/* Miscellaneous counters. */
extern int num_first_sets,
num_shift_maps,
page_no;
extern long string_offset,
string_size,
num_shifts,
num_shift_reduces,
num_gotos,
num_goto_reduces,
num_reductions,
num_sr_conflicts,
num_rr_conflicts,
num_entries;
extern char *string_table;
extern short *rhs_sym;
extern struct ruletab_type *rules;
/***********************************************************************/
/* CLOSURE is a mapping from non-terminal to a set (linked-list) of */
/* non-terminals. The set consists of non-terminals that are */
/* automatically introduced via closure when the original non-terminal */
/* is introduced. */
/* CL_ITEMS is a mapping from each non-terminal to a set (linked list) */
/* of items which are the first item of the rules generated by the */
/* non-terminal in question. ADEQUATE_ITEM is a mapping from each rule */
/* to the last (complete) item produced by that rule. */
/* ITEM_TABLE is used to map each item into a number. Given that */
/* number one can retrieve the rule the item belongs to, the position */
/* of the dot, the symbol following the dot, and FIRST of the suffix */
/* following the "dot symbol". */
/***********************************************************************/
extern struct node **closure,
**clitems,
**adequate_item;
extern struct itemtab
{
short symbol,
rule_number,
suffix_index,
dot;
} *item_table;
/***********************************************************************/
/* SYMNO is an array that maps symbol numbers to actual symbols. */
/***********************************************************************/
extern struct symno_type
{
int ptr,
name_index;
} *symno;
/***********************************************************************/
/* These variables hold the number of BOOLEAN_CELLS required to form a */
/* set of terminals, non-terminals and states, respectively. */
/***********************************************************************/
extern int term_set_size,
non_term_set_size,
state_set_size;
/***********************************************************************/
/* NULL_NT is a boolean vector that indicates whether or not a given */
/* non-terminal is nullable. */
/***********************************************************************/
extern BOOLEAN *null_nt;
/***********************************************************************/
/* FOLLOW is a mapping from non-terminals to a set of terminals that */
/* may appear immediately after the non-terminal. */
/***********************************************************************/
extern SET_PTR nt_first,
first,
follow;
/***********************************************************************/
/* NAME is an array containing names to be associated with symbols. */
/* REDUCE is a mapping from each state to reduce actions in that state.*/
/* SHIFT is an array used to hold the complete set of all shift maps */
/* needed to construct the state automaton. Though its size is */
/* NUM_STATES, the actual number of elements used in it is indicated */
/* by the integer NUM_SHIFT_MAPS. NUM_STATES elements were allocated, */
/* because if the user requests that certain single productions be */
/* removed, a Shift map containing actions involving such productions */
/* cannot be shared. */
/***********************************************************************/
extern struct shift_header_type *shift;
extern struct reduce_header_type *reduce;
extern short *gotodef,
*shiftdf,
*gd_index,
*gd_range;
extern int *name;
/***********************************************************************/
/* STATSET is a mapping from state number to state information. */
/* LASTATS is a similar mapping for look-ahead states. */
/* IN_STAT is a mapping from each state to the set of states that have */
/* a transition into the state in question. */
/***********************************************************************/
extern struct statset_type *statset;
extern struct lastats_type *lastats;
extern struct node **in_stat;
extern int num_scopes,
scope_rhs_size,
scope_state_size,
num_error_rules;
extern struct scope_type
{
short prefix,
suffix,
lhs_symbol,
look_ahead,
state_set;
} *scope;
extern short *scope_right_side,
*scope_state;
/*******************************************************************/
/*******************************************************************/
/** **/
/** OUTPUT DECLARATIONS **/
/** **/
/*******************************************************************/
/*******************************************************************/
/* The following external variables are used only in processing */
/* output. */
/*******************************************************************/
extern char *output_ptr,
*output_buffer;
extern short *symbol_map,
*ordered_state,
*state_list;
extern int *next,
*previous,
*state_index;
extern long table_size,
action_size,
increment_size;
extern short last_non_terminal,
last_terminal;
extern int accept_act,
error_act,
first_index,
last_index,
last_symbol,
max_name_length;
extern SET_PTR naction_symbols,
action_symbols;
extern BOOLEAN byte_terminal_range;
#endif /* COMMON_INCLUDED */
jikespg/src/ctabs.c 100664 764 764 326640 7010310755 14155 0 ustar shields shields /* $Id: ctabs.c,v 1.2 1999/11/04 14:02:21 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 "space.h"
#include "header.h"
static char dcl_tag[SYMBOL_SIZE],
sym_tag[SYMBOL_SIZE],
def_tag[SYMBOL_SIZE],
prs_tag[SYMBOL_SIZE];
static int byte_check_bit = 1;
/*********************************************************************/
/* NON_TERMINAL_TIME_ACTION: */
/*********************************************************************/
static void non_terminal_time_action(void)
{
if (c_bit)
fprintf(sysprs,
"#define nt_action(state, sym) \\\n"
" ((check[state+sym] == sym) ? \\\n"
" action[state + sym] : "
"default_goto[sym])\n\n");
else if (cpp_bit)
fprintf(sysprs,
" static int nt_action(int state, int sym)\n"
" {\n"
" return (check[state + sym] == sym)\n"
" ? action[state + sym]\n"
" : default_goto[sym];\n"
" }\n\n");
else if (java_bit)
fprintf(sysprs,
" public final static int nt_action(int state, int sym)\n"
" {\n"
" return (check(state + sym) == sym)\n"
" ? action[state + sym]\n"
" : default_goto[sym];\n"
" }\n\n");
return;
}
/*********************************************************************/
/* NON_TERMINAL_NO_GOTO_DEFAULT_TIME_ACTION: */
/*********************************************************************/
static void non_terminal_no_goto_default_time_action(void)
{
if (c_bit)
fprintf(sysprs,
"#define nt_action(state, sym) action[state + sym]\n\n");
else if (cpp_bit)
fprintf(sysprs,
" static int nt_action(int state, int sym)\n"
" {\n return action[state + sym];\n }\n\n");
else if (java_bit)
fprintf(sysprs,
" public final static int nt_action(int state, int sym)\n"
" {\n return action[state + sym];\n }\n\n");
return;
}
/*********************************************************************/
/* NON_TERMINAL_SPACE_ACTION: */
/*********************************************************************/
static void non_terminal_space_action(void)
{
if (c_bit)
fprintf(sysprs,
"#define nt_action(state, sym) \\\n"
" ((base_check[state + sym] == sym) ? \\\n"
" base_action[state + sym] : "
"default_goto[sym])\n\n");
else if (cpp_bit)
fprintf(sysprs,
" static int nt_action(int state, int sym)\n"
" {\n"
" return (base_check[state + sym] == sym)\n"
" ? base_action[state + sym]\n"
" : default_goto[sym];\n"
" }\n\n");
else if (java_bit)
fprintf(sysprs,
" public final static int nt_action(int state, int sym)\n"
" {\n"
" return (base_check(state + sym) == sym)\n"
" ? base_action[state + sym]\n"
" : default_goto[sym];\n"
" }\n\n");
return;
}
/*********************************************************************/
/* NON_TERMINAL_NO_GOTO_DEFAULT_SPACE_ACTION: */
/*********************************************************************/
static void non_terminal_no_goto_default_space_action(void)
{
if (c_bit)
fprintf(sysprs,
"#define nt_action(state, sym) "
"base_action[state + sym]\n\n");
else if (cpp_bit)
fprintf(sysprs,
" static int nt_action(int state, int sym)\n"
" {\n return base_action[state + sym];\n }\n\n");
else if (java_bit)
fprintf(sysprs,
" public final static int nt_action(int state, int sym)\n"
" {\n return base_action[state + sym];\n }\n\n");
return;
}
/*********************************************************************/
/* TERMINAL_TIME_ACTION: */
/*********************************************************************/
static void terminal_time_action(void)
{
if (c_bit)
fprintf(sysprs,
"#define t_action(state, sym, next_tok) \\\n"
" action[check[state + sym] == sym ? state + sym : state]\n\n");
else if (cpp_bit)
fprintf(sysprs,
" static int t_action(int state, int sym, LexStream *stream)\n"
" {\n"
" return action[check[state + sym] == sym"
" ? state + sym : state];\n"
" }\n");
else if (java_bit)
fprintf(sysprs,
" public final static int t_action(int state, int sym, LexStream stream)\n"
" {\n"
" return action[check(state + sym) == sym"
" ? state + sym : state];\n"
" }\n");
return;
}
/*********************************************************************/
/* TERMINAL_SPACE_ACTION: */
/*********************************************************************/
static void terminal_space_action(void)
{
if (c_bit)
fprintf(sysprs,
"#define t_action(state, sym, next_tok) \\\n"
" term_action[term_check[base_action[state]+sym] == sym ? \\\n"
" base_action[state] + sym : base_action[state]]\n\n");
else if (cpp_bit)
fprintf(sysprs,
" static int t_action(int state, int sym, LexStream *stream)\n"
" {\n"
" return term_action[term_check[base_action[state]"
"+sym] == sym\n"
" ? base_action[state] + sym\n"
" : base_action[state]];\n"
" }\n");
else if (java_bit)
fprintf(sysprs,
" public final static int t_action(int state, int sym, LexStream stream)\n"
" {\n"
" return term_action[term_check[base_action[state]"
"+sym] == sym\n"
" ? base_action[state] + sym\n"
" : base_action[state]];\n"
" }\n");
return;
}
/*********************************************************************/
/* TERMINAL_SHIFT_DEFAULT_SPACE_ACTION: */
/*********************************************************************/
static void terminal_shift_default_space_action(void)
{
if (c_bit)
fprintf(sysprs,
"static int t_action(int state, int sym, TokenObject next_tok)\n"
"{\n"
" int i;\n\n"
" if (sym == 0)\n"
" return ERROR_ACTION;\n"
" i = base_action[state];\n"
" if (term_check[i + sym] == sym)\n"
" return term_action[i + sym];\n"
" i = term_action[i];\n"
" return ((shift_check[shift_state[i] + sym] == sym) ?\n"
" default_shift[sym] : default_reduce[i]);\n"
"}\n\n");
else if (cpp_bit)
fprintf(sysprs,
" static int t_action(int state, int sym, LexStream *stream)\n"
" {\n"
" if (sym == 0)\n"
" return ERROR_ACTION;\n"
" int i = base_action[state];\n"
" if (term_check[i + sym] == sym)\n"
" return term_action[i + sym];\n"
" i = term_action[i];\n"
" return ((shift_check[shift_state[i] + sym] == sym) ?\n"
" default_shift[sym] : default_reduce[i]);\n"
" }\n");
else if (java_bit)
fprintf(sysprs,
" public final static int t_action(int state, int sym, LexStream stream)\n"
" {\n"
" if (sym == 0)\n"
" return ERROR_ACTION;\n"
" int i = base_action[state];\n"
" if (term_check[i + sym] == sym)\n"
" return term_action[i + sym];\n"
" i = term_action[i];\n"
" return ((shift_check[shift_state[i] + sym] == sym) ?\n"
" default_shift[sym] : default_reduce[i]);\n"
" }\n");
return;
}
/*********************************************************************/
/* TERMINAL_TIME_LALR_K: */
/*********************************************************************/
static void terminal_time_lalr_k(void)
{
if (c_bit)
fprintf(sysprs,
"static int t_action(int act, int sym, TokenObject next_tok)\n"
"{\n"
" int i = act + sym;\n\n"
" act = action[check[i] == sym ? i : act];\n\n"
" if (act > LA_STATE_OFFSET)\n"
" {\n"
" for (;;)\n"
" {\n"
" act -= ERROR_ACTION;\n"
" sym = Class(next_tok);\n"
" i = act + sym;\n"
" act = action[check[i] == sym ? i : act];\n"
" if (act <= LA_STATE_OFFSET)\n"
" break;\n"
" next_tok = Next(next_tok);\n"
" }\n"
" }\n\n"
" return act;\n"
"}\n\n");
else if (cpp_bit)
fprintf(sysprs,
" static int t_action(int act, int sym, LexStream *stream)\n"
" {\n"
" int i = act + sym;\n\n"
" act = action[check[i] == sym ? i : act];\n\n"
" if (act > LA_STATE_OFFSET)\n"
" {\n"
" for (TokenObject tok = stream -> Peek();\n"
" ;\n"
" tok = stream -> Next(tok))\n"
" {\n"
" act -= ERROR_ACTION;\n"
" sym = stream -> Kind(tok);\n"
" i = act + sym;\n"
" act = action[check[i] == sym ? i : act];\n"
" if (act <= LA_STATE_OFFSET)\n"
" break;\n"
" }\n"
" }\n\n"
" return act;\n"
" }\n\n");
else if (java_bit)
fprintf(sysprs,
" public final static int t_action(int act, int sym, LexStream stream)\n"
" {\n"
" int i = act + sym;\n\n"
" act = action[check(i) == sym ? i : act];\n\n"
" if (act > LA_STATE_OFFSET)\n"
" {\n"
" for (int tok = stream.Peek();\n"
" ;\n"
" tok = stream.Next(tok))\n"
" {\n"
" act -= ERROR_ACTION;\n"
" sym = stream.Kind(tok);\n"
" i = act + sym;\n"
" act = action[check(i) == sym ? i : act];\n"
" if (act <= LA_STATE_OFFSET)\n"
" break;\n"
" }\n"
" }\n\n"
" return act;\n"
" }\n\n");
return;
}
/*********************************************************************/
/* TERMINAL_SPACE_LALR_K: */
/*********************************************************************/
static void terminal_space_lalr_k(void)
{
if (c_bit)
fprintf(sysprs,
"static int t_action(int state, int sym, TokenObject next_tok)\n"
"{\n"
" int act = base_action[state],\n"
" i = act + sym;\n\n"
" act = term_action[term_check[i] == sym ? i : act];\n\n"
" if (act > LA_STATE_OFFSET)\n"
" {\n"
" for (;;)\n"
" {\n"
" act -= LA_STATE_OFFSET;\n"
" sym = Class(next_tok);\n"
" i = act + sym;\n"
" act = term_action[term_check[i] == sym ? i : act];\n"
" if (act <= LA_STATE_OFFSET)\n"
" break;\n"
" next_tok = Next(next_tok);\n"
" }\n"
" }\n\n"
" return act;\n"
"}\n\n");
else if (cpp_bit)
fprintf(sysprs,
" static int t_action(int act, int sym, LexStream *stream)\n"
" {\n"
" act = base_action[act];\n"
" int i = act + sym;\n\n"
" act = term_action[term_check[i] == sym ? i : act];\n\n"
" if (act > LA_STATE_OFFSET)\n"
" {\n"
" for (TokenObject tok = stream -> Peek();\n"
" ;\n"
" tok = stream -> Next(tok))\n"
" {\n"
" act -= LA_STATE_OFFSET;\n"
" sym = stream -> Kind(tok);\n"
" i = act + sym;\n"
" act = term_action[term_check[i] == sym ? i : act];\n"
" if (act <= LA_STATE_OFFSET)\n"
" break;\n"
" } \n"
" }\n\n"
" return act;\n"
" }\n");
else if (java_bit)
fprintf(sysprs,
" public final static int t_action(int act, int sym, LexStream stream)\n"
" {\n"
" act = base_action[act];\n"
" int i = act + sym;\n\n"
" act = term_action[term_check[i] == sym ? i : act];\n\n"
" if (act > LA_STATE_OFFSET)\n"
" {\n"
" for (int tok = stream.Peek();\n"
" ;\n"
" tok = stream.Next(tok))\n"
" {\n"
" act -= LA_STATE_OFFSET;\n"
" sym = stream.Kind(tok);\n"
" i = act + sym;\n"
" act = term_action[term_check[i] == sym ? i : act];\n"
" if (act <= LA_STATE_OFFSET)\n"
" break;\n"
" } \n"
" }\n\n"
" return act;\n"
" }\n");
return;
}
/*********************************************************************/
/* TERMINAL_SHIFT_DEFAULT_SPACE_LALR_K: */
/*********************************************************************/
static void terminal_shift_default_space_lalr_k(void)
{
if (c_bit)
fprintf(sysprs,
"static int t_action(int state, int sym, TokenObject next_tok)\n"
"{\n"
" int act = base_action[state],\n"
" i = act + sym;\n\n"
" if (sym == 0)\n"
" act = ERROR_ACTION;\n"
" else if (term_check[i] == sym)\n"
" act = term_action[i];\n"
" else\n"
" {\n"
" act = term_action[act];\n"
" i = shift_state[act] + sym;\n"
" act = (shift_check[i] == sym ? default_shift[sym]\n"
" : default_reduce[act]);\n"
" }\n\n"
" while (act > LA_STATE_OFFSET)\n"
" {\n"
" act -= LA_STATE_OFFSET;\n"
" sym = Class(next_tok);\n"
" i = act + sym;\n"
" if (term_check[i] == sym)\n"
" act = term_action[i];\n"
" else\n"
" {\n"
" act = term_action[act];\n"
" i = shift_state[act] + sym;\n"
" act = (shift_check[i] == sym\n"
" ? default_shift[sym]\n"
" : default_reduce[act]);\n"
" }\n"
" if (act <= LA_STATE_OFFSET)\n"
" break;\n"
" next_tok = Next(next_tok);\n"
" }\n\n"
" return act;\n"
"}\n\n");
else if (cpp_bit)
fprintf(sysprs,
" static int t_action(int act, int sym, LexStream *stream)\n"
" {\n"
" act = base_action[act];\n"
" int i = act + sym;\n\n"
" if (sym == 0)\n"
" act = ERROR_ACTION;\n"
" else if (term_check[i] == sym)\n"
" act = term_action[i];\n"
" else\n"
" {\n"
" act = term_action[act];\n"
" i = shift_state[act] + sym;\n"
" act = (shift_check[i] == sym ? default_shift[sym]\n"
" : default_reduce[act]);\n"
" }\n\n"
" if (act > LA_STATE_OFFSET)\n"
" {\n"
" for (TokenObject tok = stream -> Peek();\n"
" ;\n"
" tok = stream -> Next(tok))\n"
" {\n"
" act -= LA_STATE_OFFSET;\n"
" sym = stream -> Kind(tok);\n"
" i = act + sym;\n"
" if (term_check[i] == sym)\n"
" act = term_action[i];\n"
" else\n"
" {\n"
" act = term_action[act];\n"
" i = shift_state[act] + sym;\n"
" act = (shift_check[i] == sym\n"
" ? default_shift[sym]\n"
" : default_reduce[act]);\n"
" }\n"
" if (act <= LA_STATE_OFFSET)\n"
" break;\n"
" }\n"
" }\n\n"
" return act;\n"
" }\n");
else if (java_bit)
fprintf(sysprs,
" public final static int t_action(int act, int sym, LexStream stream)\n"
" {\n"
" act = base_action[act];\n"
" int i = act + sym;\n\n"
" if (sym == 0)\n"
" act = ERROR_ACTION;\n"
" else if (term_check[i] == sym)\n"
" act = term_action[i];\n"
" else\n"
" {\n"
" act = term_action[act];\n"
" i = shift_state[act] + sym;\n"
" act = (shift_check[i] == sym ? default_shift[sym]\n"
" : default_reduce[act]);\n"
" }\n\n"
" if (act > LA_STATE_OFFSET)\n"
" {\n"
" for (int tok = stream.Peek();\n"
" ;\n"
" tok = stream.Next(tok))\n"
" {\n"
" act -= LA_STATE_OFFSET;\n"
" sym = stream.Kind(tok);\n"
" i = act + sym;\n"
" if (term_check[i] == sym)\n"
" act = term_action[i];\n"
" else\n"
" {\n"
" act = term_action[act];\n"
" i = shift_state[act] + sym;\n"
" act = (shift_check[i] == sym\n"
" ? default_shift[sym]\n"
" : default_reduce[act]);\n"
" }\n"
" if (act <= LA_STATE_OFFSET)\n"
" break;\n"
" }\n"
" }\n\n"
" return act;\n"
" }\n");
return;
}
/*********************************************************************/
/* INIT_FILE: */
/*********************************************************************/
static void init_file(FILE **file, char *file_name, char *file_tag)
{
char *p;
#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);
p = strchr(file_name, '.');
if ((*file = fopen(file_name, msg_line)) == NULL)
#else
p = strrchr(file_name, '.');
if ((*file = fopen(file_name, "w")) == NULL)
#endif
{
fprintf(stderr,
"***ERROR: Symbol file \"%s\" cannot be opened\n",
file_name);
exit(12);
}
memcpy(file_tag, file_name, p - file_name);
file_tag[p - file_name] = '\0';
if (c_bit || cpp_bit)
{
fprintf(*file, "#ifndef %s_INCLUDED\n", file_tag);
fprintf(*file, "#define %s_INCLUDED\n\n", file_tag);
}
return;
}
/*********************************************************************/
/* INIT_PARSER_FILES: */
/*********************************************************************/
static void init_parser_files(void)
{
init_file(&sysdcl, dcl_file, dcl_tag);
init_file(&syssym, sym_file, sym_tag);
init_file(&sysdef, def_file, def_tag);
init_file(&sysprs, prs_file, prs_tag);
return;
}
/*********************************************************************/
/* EXIT_PRS_FILE: */
/*********************************************************************/
static void exit_parser_files(void)
{
if (c_bit || cpp_bit)
{
fprintf(sysdcl, "\n#endif /* %s_INCLUDED */\n", dcl_tag);
fprintf(syssym, "\n#endif /* %s_INCLUDED */\n", sym_tag);
fprintf(sysdef, "\n#endif /* %s_INCLUDED */\n", def_tag);
fprintf(sysprs, "\n#endif /* %s_INCLUDED */\n", prs_tag);
}
fclose(sysdcl);
fclose(syssym);
fclose(sysdef);
fclose(sysprs);
return;
}
/**************************************************************************/
/* PRINT_C_NAMES: */
/**************************************************************************/
static void print_c_names(void)
{
char tok[SYMBOL_SIZE + 1];
short *name_len = Allocate_short_array(num_names + 1);
long num_bytes = 0;
int i, j, k, n;
max_name_length = 0;
mystrcpy("\nconst char CLASS_HEADER string_buffer[] = {0,\n");
n = 0;
j = 0;
padline();
for (i = 1; i <= num_names; i++)
{
strcpy(tok, RETRIEVE_NAME(i));
name_len[i] = strlen(tok);
num_bytes += name_len[i];
if (max_name_length < name_len[i])
max_name_length = name_len[i];
k = 0;
for (j = 0; j < name_len[i]; j++)
{
*output_ptr++ = '\'';
if (tok[k] == '\'' || tok[k] == '\\')
*output_ptr++ = '\\';
if (tok[k] == '\n')
*output_ptr++ = escape;
else
*output_ptr++ = tok[k];
k++;
*output_ptr++ = '\'';
*output_ptr++ = ',';
n++;
if (n == 10 && ! (i == num_names && j == name_len[i] - 1))
{
n = 0;
*output_ptr++ = '\n';
BUFFER_CHECK(sysdcl);
padline();
}
}
}
*(output_ptr - 1) = '\n'; /*overwrite last comma*/
BUFFER_CHECK(sysdcl);
if (java_bit)
mystrcpy(" };\n");
else mystrcpy(" };\n");
/*****************************************************************/
/* Compute and list space required for STRING_BUFFER map. */
/*****************************************************************/
sprintf(msg_line,
" Storage required for STRING_BUFFER map: %d Bytes",
num_bytes);
PRNT(msg_line);
/******************************/
/* Write out NAME_START array */
/******************************/
mystrcpy("\nconst unsigned short CLASS_HEADER name_start[] = {0,\n");
padline();
j = 1;
k = 0;
for (i = 1; i <= num_names; i++)
{
itoc(j);
*output_ptr++ = COMMA;
j += name_len[i];
k++;
if (k == 10 && i != num_names)
{
*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");
/*****************************************************************/
/* Compute and list space required for NAME_START map. */
/*****************************************************************/
sprintf(msg_line,
" Storage required for NAME_START map: %d Bytes",
(2 * num_names));
PRNT(msg_line);
/*******************************/
/* Write out NAME_LENGTH array */
/*******************************/
prnt_shorts("\nconst unsigned char CLASS_HEADER name_length[] = {0,\n",
1, num_names, 10, name_len);
/*****************************************************************/
/* Compute and list space required for NAME_LENGTH map. */
/*****************************************************************/
sprintf(msg_line,
" Storage required for NAME_LENGTH map: %d Bytes",
num_names);
PRNT(msg_line);
ffree(name_len);
return;
}
/**************************************************************************/
/* PRINT_JAVA_NAMES: */
/**************************************************************************/
static void print_java_names(void)
{
char tok[SYMBOL_SIZE + 1];
long num_bytes = 0;
int i, j, k;
max_name_length = 0;
mystrcpy("\n public final static String name[] = { null,\n");
for (i = 1; i <= num_names; i++)
{
int len;
strcpy(tok, RETRIEVE_NAME(i));
len = strlen(tok);
num_bytes += (len * 2);
if (max_name_length < len)
max_name_length = len;
padline();
*output_ptr++ = '\"';
k = 0;
for (j = 0; j < len; j++)
{
if (tok[j] == '\"' || tok[j] == '\\')
*output_ptr++ = '\\';
if (tok[j] == '\n')
*output_ptr++ = escape;
else
*output_ptr++ = tok[j];
k++;
if (k == 30 && (! (j == len - 1)))
{
k = 0;
*output_ptr++ = '\"';
*output_ptr++ = ' ';
*output_ptr++ = '+';
*output_ptr++ = '\n';
BUFFER_CHECK(sysdcl);
padline();
*output_ptr++ = '\"';
}
}
*output_ptr++ = '\"';
if (i < num_names)
*output_ptr++ = ',';
*output_ptr++ = '\n';
}
BUFFER_CHECK(sysdcl);
if (java_bit)
mystrcpy(" };\n");
else mystrcpy(" };\n");
/*****************************************************************/
/* Compute and list space required for STRING_BUFFER map. */
/*****************************************************************/
sprintf(msg_line,
" Storage required for STRING_BUFFER map: %d Bytes",
num_bytes);
PRNT(msg_line);
return;
}
/**************************************************************************/
/* PRINT_ERROR_MAPS: */
/**************************************************************************/
static void print_error_maps(void)
{
short *state_start,
*state_stack,
*temp,
*original,
*as_size,
*action_symbols_base,
*action_symbols_range,
*naction_symbols_base,
*naction_symbols_range;
int i,
j,
k,
n,
offset,
state_no,
symbol;
long num_bytes;
state_start = Allocate_short_array(num_states + 2);
state_stack = Allocate_short_array(num_states + 1);
PRNT("\nError maps storage:");
/********************************************************************/
/* We now construct a bit map for the set of terminal symbols that */
/* may appear in each state. Then, we invoke PARTSET to apply the */
/* Partition Heuristic and print it. */
/********************************************************************/
as_size = Allocate_short_array(num_states + 1);
if (table_opt == OPTIMIZE_TIME)
{
original = Allocate_short_array(num_symbols + 1);
/*************************************************************/
/* In a compressed TIME table, the terminal and non-terminal */
/* symbols are mixed together when they are remapped. */
/* We shall now recover the original number associated with */
/* each terminal symbol since it lies very nicely in the */
/* range 1..NUM_TERMINALS. This will save a considerable */
/* amount of space in the bit_string representation of sets */
/* as well as time when operations are performed on those */
/* bit-strings. */
/*************************************************************/
for ALL_TERMINALS(symbol)
original[symbol_map[symbol]] = symbol;
}
for ALL_STATES(state_no)
{
struct shift_header_type sh;
struct reduce_header_type red;
sh = shift[statset[state_no].shift_number];
as_size[state_no] = sh.size;
for (i = 1; i <= sh.size; i++)
{
if (table_opt == OPTIMIZE_TIME)
symbol = original[SHIFT_SYMBOL(sh, i)];
else
symbol = SHIFT_SYMBOL(sh, i);
SET_BIT_IN(action_symbols, state_no, symbol);
}
red = reduce[state_no];
as_size[state_no] += red.size;
for (i = 1; i <= red.size; i++)
{
if (table_opt == OPTIMIZE_TIME)
symbol = original[REDUCE_SYMBOL(red, i)];
else
symbol = REDUCE_SYMBOL(red, i);
SET_BIT_IN(action_symbols, state_no, symbol);
}
}
partset(action_symbols, as_size, state_list, state_start,
state_stack, num_terminals);
ffree(action_symbols);
/*************************************************************/
/* Compute and write out the base of the ACTION_SYMBOLS map. */
/*************************************************************/
action_symbols_base = Allocate_short_array(num_states + 1);
for ALL_STATES(i)
action_symbols_base[state_list[i]] =
ABS(state_start[state_list[i]]);
if (java_bit)
{
prnt_shorts("\n public final static char asb[] = {0,\n",
1, num_states, 10, action_symbols_base);
}
else
{
prnt_shorts("\nconst unsigned short CLASS_HEADER asb[] = {0,\n",
1, num_states, 10, action_symbols_base);
}
ffree(action_symbols_base);
/**************************************************************/
/* Compute and write out the range of the ACTION_SYMBOLS map. */
/**************************************************************/
offset = state_start[num_states + 1];
action_symbols_range = Allocate_short_array(offset);
compute_action_symbols_range(state_start, state_stack,
state_list, action_symbols_range);
for (i = 0; i < (offset - 1); i++)
{
if (action_symbols_range[i] > (java_bit ? 127 : 255))
{
byte_terminal_range = 0;
break;
}
}
if (byte_terminal_range)
{
if (java_bit)
{
prnt_shorts("\n public final static byte asr[] = {0,\n",
0, offset - 2, 10, action_symbols_range);
}
else
{
prnt_shorts("\nconst unsigned char CLASS_HEADER asr[] = {0,\n",
0, offset - 2, 10, action_symbols_range);
}
}
else
{
if (java_bit)
{
prnt_shorts("\n public final static char asr[] = {0,\n",
0, offset - 2, 10, action_symbols_range);
}
else
{
prnt_shorts("\nconst unsigned short CLASS_HEADER asr[] = {0,\n",
0, offset - 2, 10, action_symbols_range);
}
}
num_bytes = 2 * num_states;
sprintf(msg_line,
" Storage required for ACTION_SYMBOLS_BASE map: "
"%ld Bytes", num_bytes);
PRNT(msg_line);
if ((table_opt == OPTIMIZE_TIME) && (last_terminal <= (java_bit ? 127 : 255)))
num_bytes = offset - 1;
else if ((table_opt != OPTIMIZE_TIME) && (num_terminals <= (java_bit ? 127 : 255)))
num_bytes = offset - 1;
else
num_bytes = 2 * (offset - 1);
sprintf(msg_line,
" Storage required for ACTION_SYMBOLS_RANGE map: "
"%ld Bytes", num_bytes);
PRNT(msg_line);
ffree(action_symbols_range);
/***********************************************************************/
/* We now repeat the same process for the domain of the GOTO table. */
/***********************************************************************/
for ALL_STATES(state_no)
{
as_size[state_no] = gd_index[state_no + 1] - gd_index[state_no];
for (i = gd_index[state_no]; i <= gd_index[state_no + 1] - 1; i++)
{
symbol = gd_range[i] - num_terminals;
NTSET_BIT_IN(naction_symbols, state_no, symbol);
}
}
partset(naction_symbols, as_size, state_list, state_start,
state_stack, num_non_terminals);
ffree(as_size);
ffree(naction_symbols);
for (i = 1; i <= gotodom_size; i++) /* Remap non-terminals */
{
if (table_opt == OPTIMIZE_SPACE)
gd_range[i] = symbol_map[gd_range[i]] - num_terminals;
else
gd_range[i] = symbol_map[gd_range[i]];
}
/*************************************************************/
/* Compute and write out the base of the NACTION_SYMBOLS map.*/
/*************************************************************/
naction_symbols_base = Allocate_short_array(num_states + 1);
for ALL_STATES(i)
naction_symbols_base[state_list[i]] =
ABS(state_start[state_list[i]]);
if (java_bit)
{
prnt_shorts("\n public final static char nasb[] = {0,\n",
1, num_states, 10, naction_symbols_base);
}
else
{
prnt_shorts("\nconst unsigned short CLASS_HEADER nasb[] = {0,\n",
1, num_states, 10, naction_symbols_base);
}
ffree(naction_symbols_base);
/**************************************************************/
/* Compute and write out the range of the NACTION_SYMBOLS map.*/
/**************************************************************/
offset = state_start[num_states + 1];
naction_symbols_range = Allocate_short_array(offset);
compute_naction_symbols_range(state_start, state_stack,
state_list, naction_symbols_range);
if (java_bit)
{
prnt_shorts("\n public final static char nasr[] = {0,\n",
0, offset - 2, 10, naction_symbols_range);
}
else
{
prnt_shorts("\nconst unsigned short CLASS_HEADER nasr[] = {0,\n",
0, offset - 2, 10, naction_symbols_range);
}
num_bytes = 2 * num_states;
sprintf(msg_line,
" Storage required for NACTION_SYMBOLS_BASE map: "
"%ld Bytes", num_bytes);
PRNT(msg_line);
num_bytes = 2 * (offset - 1);
sprintf(msg_line,
" Storage required for NACTION_SYMBOLS_RANGE map: "
"%ld Bytes", ((long) 2 * (offset - 1)));
PRNT(msg_line);
ffree(naction_symbols_range);
/*********************************************************************/
/* We write the name_index of each terminal symbol. The array TEMP */
/* is used to remap the NAME_INDEX values based on the new symbol */
/* numberings. If time tables are requested, the terminals and non- */
/* terminals are mixed together. */
/*********************************************************************/
temp = Allocate_short_array(num_symbols + 1);
if (table_opt == OPTIMIZE_SPACE)
{
for ALL_TERMINALS(symbol)
temp[symbol_map[symbol]] = symno[symbol].name_index;
if (num_names <= (java_bit ? 127 : 255))
{
if (java_bit)
{
prnt_shorts
("\n public final static byte terminal_index[] = {0,\n",
1, num_terminals, 10, temp);
}
else
{
prnt_shorts
("\nconst unsigned char CLASS_HEADER terminal_index[] = {0,\n",
1, num_terminals, 10, temp);
}
num_bytes = num_terminals;
}
else
{
if (java_bit)
{
prnt_shorts
("\n public final static char terminal_index[] = {0,\n",
1, num_terminals, 10, temp);
}
else
{
prnt_shorts
("\nconst unsigned short CLASS_HEADER terminal_index[] = {0,\n",
1, num_terminals, 10, temp);
}
num_bytes = 2 * num_terminals;
}
/*****************************************************************/
/* Compute and list space required for TERMINAL_INDEX map. */
/*****************************************************************/
sprintf(msg_line,
" Storage required for TERMINAL_INDEX map: %d Bytes",
num_bytes);
PRNT(msg_line);
/******************************************************************/
/* We write the name_index of each non_terminal symbol. The array */
/* TEMP is used to remap the NAME_INDEX values based on the new */
/* symbol numberings. */
/******************************************************************/
for ALL_NON_TERMINALS(symbol)
temp[symbol_map[symbol]] = symno[symbol].name_index;
if (num_names <= (java_bit ? 127 : 255))
{
if (java_bit)
{
prnt_shorts
("\n public final static byte "
"non_terminal_index[] = {0,\n",
num_terminals + 1, num_symbols, 10, temp);
}
else
{
prnt_shorts
("\nconst unsigned char CLASS_HEADER "
"non_terminal_index[] = {0,\n",
num_terminals + 1, num_symbols, 10, temp);
}
num_bytes = num_non_terminals;
}
else
{
if (java_bit)
{
prnt_shorts
("\n public final static char "
"non_terminal_index[] = {0,\n",
num_terminals + 1, num_symbols, 10, temp);
}
else
{
prnt_shorts
("\nconst unsigned short CLASS_HEADER "
"non_terminal_index[] = {0,\n",
num_terminals + 1, num_symbols, 10, temp);
}
num_bytes = 2 * num_non_terminals;
}
/*****************************************************************/
/* Compute and list space required for NON_TERMINAL_INDEX map. */
/*****************************************************************/
sprintf(msg_line,
" Storage required for NON_TERMINAL_INDEX map: %d Bytes",
num_bytes);
PRNT(msg_line);
}
else
{
for ALL_SYMBOLS(symbol)
temp[symbol_map[symbol]] = symno[symbol].name_index;
if (num_names <= (java_bit ? 127 : 255))
{
if (java_bit)
{
prnt_shorts
("\n public final static byte symbol_index[] = {0,\n",
1, num_symbols, 10, temp);
mystrcpy(" public final static byte terminal_index[] = "
"symbol_index;\n");
mystrcpy(" public final static byte non_terminal_index[] = "
"symbol_index;\n");
}
else
{
prnt_shorts
("\nconst unsigned char CLASS_HEADER symbol_index[] = {0,\n",
1, num_symbols, 10, temp);
mystrcpy("const unsigned char *CLASS_HEADER terminal_index[] = "
"&(symbol_index[0]);\n");
mystrcpy("const unsigned char *CLASS_HEADER non_terminal_index[] = "
"&(symbol_index[0]);\n");
}
num_bytes = num_symbols;
}
else
{
if (java_bit)
{
prnt_shorts
("\n public final static char symbol_index[] = {0,\n",
1, num_symbols, 10, temp);
mystrcpy(" public final static char terminal_index[] = "
"symbol_index[0];\n");
mystrcpy(" public final static char non_terminal_index[] = "
"symbol_index;\n");
}
else
{
prnt_shorts
("\nconst unsigned short CLASS_HEADER symbol_index[] = {0,\n",
1, num_symbols, 10, temp);
mystrcpy("const unsigned short *CLASS_HEADER terminal_index[] = "
"&(symbol_index[0]);\n");
mystrcpy("const unsigned short *CLASS_HEADER non_terminal_index[] = "
"&(symbol_index[0]);\n");
}
num_bytes = 2 * num_symbols;
}
/*****************************************************************/
/* Compute and list space required for SYMBOL_INDEX map. */
/*****************************************************************/
sprintf(msg_line,
" Storage required for SYMBOL_INDEX map: %d Bytes",
num_bytes);
PRNT(msg_line);
}
if (num_scopes > 0)
{
short root = 0;
short *list;
list = Allocate_short_array(scope_rhs_size + 1);
for (i = 1; i <= scope_rhs_size; i++)
{
if (scope_right_side[i] != 0)
scope_right_side[i] = symbol_map[scope_right_side[i]];
}
for (i = 1; i <= num_scopes; i++)
{
scope[i].look_ahead = symbol_map[scope[i].look_ahead];
if (table_opt == OPTIMIZE_SPACE)
scope[i].lhs_symbol = symbol_map[scope[i].lhs_symbol]
- num_terminals;
else
scope[i].lhs_symbol = symbol_map[scope[i].lhs_symbol];
}
/****************************************/
/* Mark all elements of prefix strings. */
/****************************************/
for (i=1; i <= scope_rhs_size; i++)
list[i] = -1;
for (i = 1; i <= num_scopes; i++)
{
if (list[scope[i].suffix] < 0)
{
list[scope[i].suffix] = root;
root = scope[i].suffix;
}
}
for (; root != 0; root = list[root])
{
for (j = root; scope_right_side[j] != 0; j++)
{
k = scope_right_side[j];
scope_right_side[j] = temp[k];
}
}
ffree(list);
}
if (java_bit)
print_java_names();
else print_c_names();
if (num_scopes > 0)
{
if (scope_rhs_size <= (java_bit ? 127 : 255))
{
if (java_bit)
mystrcpy("\n public final static byte scope_prefix[] = {\n");
else mystrcpy("\nconst unsigned char CLASS_HEADER scope_prefix[] = {\n");
}
else
{
if (java_bit)
mystrcpy("\n public final static char scope_prefix[] = {\n");
else mystrcpy("\nconst unsigned short CLASS_HEADER scope_prefix[] = {\n");
}
padline();
k = 0;
for (i = 1; i <= num_scopes; i++)
{
itoc(scope[i].prefix);
*output_ptr++ = COMMA;
k++;
if (k == 10 && i != num_scopes)
{
*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");
if (scope_rhs_size <= (java_bit ? 127 : 255))
{
if (java_bit)
mystrcpy("\n public final static byte scope_suffix[] = {\n");
else mystrcpy("\nconst unsigned char CLASS_HEADER scope_suffix[] = {\n");
}
else
{
if (java_bit)
mystrcpy("\n public final static char scope_suffix[] = {\n");
else mystrcpy("\nconst unsigned short CLASS_HEADER scope_suffix[] = {\n");
}
padline();
k = 0;
for (i = 1; i <= num_scopes; i++)
{
itoc(scope[i].suffix);
*output_ptr++ = COMMA;
k++;
if (k == 10 && i != num_scopes)
{
*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");
if (num_symbols <= (java_bit ? 127 : 255))
{
if (java_bit)
mystrcpy("\n public final static byte scope_lhs[] = {\n");
else mystrcpy("\nconst unsigned char CLASS_HEADER scope_lhs[] = {\n");
}
else
{
if (java_bit)
mystrcpy("\n public final static char scope_lhs[] = {\n");
else mystrcpy("\nconst unsigned short CLASS_HEADER scope_lhs[] = {\n");
}
padline();
k = 0;
for (i = 1; i <= num_scopes; i++)
{
itoc(scope[i].lhs_symbol);
*output_ptr++ = COMMA;
k++;
if (k == 10 && i != num_scopes)
{
*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");
if (num_terminals <= (java_bit ? 127 : 255))
{
if (java_bit)
mystrcpy("\n public final static byte scope_la[] = {\n");
else mystrcpy("\nconst unsigned char CLASS_HEADER scope_la[] = {\n");
}
else
{
if (java_bit)
mystrcpy("\n public final static char scope_la[] = {\n");
else mystrcpy("\nconst unsigned short CLASS_HEADER scope_la[] = {\n");
}
padline();
k = 0;
for (i = 1; i <= num_scopes; i++)
{
itoc(scope[i].look_ahead);
*output_ptr++ = COMMA;
k++;
if (k == 10 && i != num_scopes)
{
*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");
if (scope_state_size <= (java_bit ? 127 : 255))
{
if (java_bit)
mystrcpy("\n public final static byte scope_state_set[] = {\n");
else mystrcpy("\nconst unsigned char CLASS_HEADER scope_state_set[] = {\n");
}
else
{
if (java_bit)
mystrcpy("\n public final static char scope_state_set[] = {\n");
else mystrcpy("\nconst unsigned short CLASS_HEADER scope_state_set[] = {\n");
}
padline();
k = 0;
for (i = 1; i <= num_scopes; i++)
{
itoc(scope[i].state_set);
*output_ptr++ = COMMA;
k++;
if (k == 10 && i != num_scopes)
{
*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");
if (num_symbols <= (java_bit ? 127 : 255))
{
if (java_bit)
{
prnt_shorts
("\n public final static byte scope_rhs[] = {0,\n",
1, scope_rhs_size, 10, scope_right_side);
}
else
{
prnt_shorts
("\nconst unsigned char CLASS_HEADER scope_rhs[] = {0,\n",
1, scope_rhs_size, 10, scope_right_side);
}
}
else
{
if (java_bit)
{
prnt_shorts
("\n public final static char scope_rhs[] = {0,\n",
1, scope_rhs_size, 10, scope_right_side);
}
else
{
prnt_shorts
("\nconst unsigned short CLASS_HEADER scope_rhs[] = {0,\n",
1, scope_rhs_size, 10, scope_right_side);
}
}
if (java_bit)
mystrcpy("\n public final static char scope_state[] = {0,\n");
else mystrcpy("\nconst unsigned short CLASS_HEADER scope_state[] = {0,\n");
padline();
k = 0;
for (i = 1; i <= scope_state_size; i++)
{
if (scope_state[i] == 0)
itoc(0);
else
itoc(state_index[scope_state[i]] + num_rules);
*output_ptr++ = COMMA;
k++;
if (k == 10 && i != scope_state_size)
{
*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");
if (num_symbols <= (java_bit ? 127 : 255))
{
if (java_bit)
mystrcpy("\n public final static byte in_symb[] = {0,\n");
else mystrcpy("\nconst unsigned char CLASS_HEADER in_symb[] = {0,\n");
}
else
{
if (java_bit)
mystrcpy("\n public final static char in_symb[] = {0,\n");
else mystrcpy("\nconst unsigned short CLASS_HEADER in_symb[] = {0,\n");
}
/* Transition symbol */
padline();
*output_ptr++ = '0';
*output_ptr++ = COMMA;
k = 1;
for (state_no = 2; state_no <= (int) num_states; state_no++)
{
struct node *q;
int item_no;
q = statset[state_no].kernel_items;
if (q != NULL)
{
item_no = q -> value - 1;
i = item_table[item_no].symbol;
}
else i = 0;
itoc(symbol_map[i]);
*output_ptr++ = COMMA;
k++;
if (k == 10 && state_no != (int) num_states)
{
*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;
}
/****************************************************************************/
/* PRINT_SYMBOLS: */
/****************************************************************************/
static void print_symbols(void)
{
int symbol;
char line[SYMBOL_SIZE + /* max length of a token symbol */
2 * MAX_PARM_SIZE + /* max length of prefix + suffix */
64]; /* +64 for error messages lines */
/* or other fillers(blank, =,...)*/
if (java_bit)
{
strcpy(line, "interface ");
strcat(line, sym_tag);
strcat(line, "\n{\n public final static int\n");
}
else strcpy(line, "enum {\n");
/*********************************************************/
/* We write the terminal symbols map. */
/*********************************************************/
for ALL_TERMINALS(symbol)
{
char *tok = RETRIEVE_STRING(symbol);
fprintf(syssym, "%s", line);
if (tok[0] == '\n' || tok[0] == escape)
{
tok[0] = escape;
sprintf(line, "Escaped symbol %s is an invalid C variable.\n",tok);
PRNT(line);
}
else if (strpbrk(tok, "!%^&*()-+={}[];:\"`~|\\,.<>/?\'") != NULL)
{
sprintf(line, "%s may be an invalid variable name.\n", tok);
PRNT(line);
}
sprintf(line, " %s%s%s = %i,\n\0",
prefix, tok, suffix, symbol_map[symbol]);
if (c_bit || cpp_bit)
{
while(strlen(line) > PARSER_LINE_SIZE)
{
fwrite(line, sizeof(char), PARSER_LINE_SIZE - 2, syssym);
fprintf(syssym, "\\\n");
strcpy(line, &line[PARSER_LINE_SIZE - 2]);
}
}
}
line[strlen(line) - 2] = '\0'; /* remove the string ",\n" from last line */
fprintf(syssym, "%s%s", line, (java_bit ? ";\n}\n" : "\n };\n"));
return;
}
/****************************************************************************/
/* PRINT_DEFINITIONS: */
/****************************************************************************/
static void print_definitions(void)
{
if (java_bit)
fprintf(sysdef, "interface %s\n{\n public final static int\n\n",
def_tag);
else fprintf(sysdef, "enum {\n");
if (error_maps_bit)
{
if (java_bit)
fprintf(sysdef,
" ERROR_SYMBOL = %d,\n"
" MAX_NAME_LENGTH = %d,\n"
" NUM_STATES = %d,\n\n",
error_image,
max_name_length,
num_states);
else fprintf(sysdef,
" ERROR_CODE,\n"
" BEFORE_CODE,\n"
" INSERTION_CODE,\n"
" INVALID_CODE,\n"
" SUBSTITUTION_CODE,\n"
" DELETION_CODE,\n"
" MERGE_CODE,\n"
" MISPLACED_CODE,\n"
" SCOPE_CODE,\n"
" MANUAL_CODE,\n"
" SECONDARY_CODE,\n"
" EOF_CODE,\n\n"
" ERROR_SYMBOL = %d,\n"
" MAX_DISTANCE = %d,\n"
" MIN_DISTANCE = %d,\n"
" MAX_NAME_LENGTH = %d,\n"
" MAX_TERM_LENGTH = %d,\n"
" NUM_STATES = %d,\n\n",
error_image,
maximum_distance,
minimum_distance,
max_name_length,
max_name_length,
num_states);
}
if (java_bit)
fprintf(sysdef,
" NT_OFFSET = %d,\n"
" SCOPE_UBOUND = %d,\n"
" SCOPE_SIZE = %d,\n"
" LA_STATE_OFFSET = %d,\n"
" MAX_LA = %d,\n"
" NUM_RULES = %d,\n"
" NUM_TERMINALS = %d,\n"
" NUM_NON_TERMINALS = %d,\n"
" NUM_SYMBOLS = %d,\n"
" START_STATE = %d,\n"
" EOFT_SYMBOL = %d,\n"
" EOLT_SYMBOL = %d,\n"
" ACCEPT_ACTION = %d,\n"
" ERROR_ACTION = %d;\n"
"};\n\n",
(table_opt == OPTIMIZE_SPACE ? num_terminals : num_symbols),
num_scopes - 1,
num_scopes,
(read_reduce_bit && lalr_level > 1
? error_act + num_rules : error_act),
lalr_level,
num_rules,
num_terminals,
num_non_terminals,
num_symbols,
state_index[1] + num_rules,
eoft_image,
eolt_image,
accept_act,
error_act);
else fprintf(sysdef,
" NT_OFFSET = %d,\n"
" BUFF_UBOUND = %d,\n"
" BUFF_SIZE = %d,\n"
" STACK_UBOUND = %d,\n"
" STACK_SIZE = %d,\n"
" SCOPE_UBOUND = %d,\n"
" SCOPE_SIZE = %d,\n"
" LA_STATE_OFFSET = %d,\n"
" MAX_LA = %d,\n"
" NUM_RULES = %d,\n"
" NUM_TERMINALS = %d,\n"
" NUM_NON_TERMINALS = %d,\n"
" NUM_SYMBOLS = %d,\n"
" START_STATE = %d,\n"
" EOFT_SYMBOL = %d,\n"
" EOLT_SYMBOL = %d,\n"
" ACCEPT_ACTION = %d,\n"
" ERROR_ACTION = %d\n"
" };\n\n",
(table_opt == OPTIMIZE_SPACE ? num_terminals : num_symbols),
maximum_distance + lalr_level - 1,
maximum_distance + lalr_level,
stack_size - 1,
stack_size,
num_scopes - 1,
num_scopes,
(read_reduce_bit && lalr_level > 1
? error_act + num_rules : error_act),
lalr_level,
num_rules,
num_terminals,
num_non_terminals,
num_symbols,
state_index[1] + num_rules,
eoft_image,
eolt_image,
accept_act,
error_act);
return;
}
/****************************************************************************/
/* PRINT_EXTERNS: */
/****************************************************************************/
static void print_externs(void)
{
if (c_bit || cpp_bit)
{
fprintf(sysprs,
"%s SCOPE_REPAIR\n"
"%s DEFERRED_RECOVERY\n"
"%s FULL_DIAGNOSIS\n"
"%s SPACE_TABLES\n\n",
(num_scopes > 0 ? "#define" : "#undef "),
(deferred_bit ? "#define" : "#undef "),
(error_maps_bit ? "#define" : "#undef "),
(table_opt == OPTIMIZE_SPACE ? "#define" : "#undef "));
}
if (c_bit)
fprintf(sysprs,
"#define original_state(state) (-%s[state])\n"
"#define asi(state) asb[original_state(state)]\n"
"#define nasi(state) nasb[original_state(state)]\n"
"#define in_symbol(state) in_symb[original_state(state)]\n\n",
(table_opt == OPTIMIZE_TIME ? "check" : "base_check"));
else if (cpp_bit)
{
fprintf(sysprs,
"class LexStream;\n\n"
"class %s_table\n"
"{\n"
"public:\n",
prs_tag);
if (error_maps_bit || debug_bit)
fprintf(sysprs,
" static int original_state(int state) "
"{ return -%s[state]; }\n",
(table_opt == OPTIMIZE_TIME ? "check" : "base_check"));
if (error_maps_bit)
{
fprintf(sysprs,
" static int asi(int state) "
"{ return asb[original_state(state)]; }\n"
" static int nasi(int state) "
"{ return nasb[original_state(state)]; }\n");
if (num_scopes > 0)
fprintf(sysprs,
" static int in_symbol(int state) "
"{ return in_symb[original_state(state)]; }\n");
}
fprintf(sysprs, "\n");
}
else if (java_bit)
{
fprintf(sysprs,
"abstract class %s extends %s implements %s\n{\n",
prs_tag, dcl_tag, def_tag);
if (error_maps_bit || debug_bit)
{
fprintf(sysprs,
" public final static int original_state(int state) "
"{ return -%s(state); }\n",
(table_opt == OPTIMIZE_TIME ? "check" : "base_check"));
if (error_maps_bit)
{
fprintf(sysprs,
" public final static int asi(int state) "
"{ return asb[original_state(state)]; }\n"
" static int nasi(int state) "
"{ return nasb[original_state(state)]; }\n");
if (num_scopes > 0)
fprintf(sysprs,
" public final static int in_symbol(int state) "
"{ return in_symb[original_state(state)]; }\n");
}
fprintf(sysprs, "\n");
}
}
if (c_bit || cpp_bit)
{
fprintf(sysprs, "%s const unsigned char rhs[];\n",
(c_bit ? "extern" : " static"));
if (check_size > 0 || table_opt == OPTIMIZE_TIME)
{
BOOLEAN small = byte_check_bit && (! error_maps_bit);
fprintf(sysprs, "%s const %s check_table[];\n"
"%s const %s *%s;\n",
(c_bit ? "extern" : " static"),
(small ? "unsigned char " : " signed short"),
(c_bit ? "extern" : " static"),
(small ? "unsigned char " : " signed short"),
(table_opt == OPTIMIZE_TIME
? "check" : "base_check"));
}
fprintf(sysprs, "%s const unsigned short lhs[];\n"
"%s const unsigned short *%s;\n",
(c_bit ? "extern" : " static"),
(c_bit ? "extern" : " static"),
(table_opt == OPTIMIZE_TIME
? "action" : "base_action"));
if (goto_default_bit)
fprintf(sysprs, "%s const unsigned short default_goto[];\n",
(c_bit ? "extern" : " static"));
if (table_opt == OPTIMIZE_SPACE)
{
fprintf(sysprs, "%s const unsigned %s term_check[];\n",
(c_bit ? "extern" : " static"),
(num_terminals <= (java_bit ? 127 : 255) ? "char " : "short"));
fprintf(sysprs, "%s const unsigned short term_action[];\n",
(c_bit ? "extern" : " static"));
if (shift_default_bit)
{
fprintf(sysprs, "%s const unsigned short default_reduce[];\n",
(c_bit ? "extern" : " static"));
fprintf(sysprs, "%s const unsigned short shift_state[];\n",
(c_bit ? "extern" : " static"));
fprintf(sysprs, "%s const unsigned %s shift_check[];\n",
(c_bit ? "extern" : " static"),
(num_terminals <= (java_bit ? 127 : 255) ? "char " : "short"));
fprintf(sysprs, "%s const unsigned short default_shift[];\n",
(c_bit ? "extern" : " static"));
}
}
if (error_maps_bit)
{
fprintf(sysprs,
"\n"
"%s const unsigned short asb[];\n"
"%s const unsigned %s asr[];\n"
"%s const unsigned short nasb[];\n"
"%s const unsigned short nasr[];\n"
"%s const unsigned short name_start[];\n"
"%s const unsigned char name_length[];\n"
"%s const char string_buffer[];\n",
(c_bit ? "extern" : " static"),
(c_bit ? "extern" : " static"),
(byte_terminal_range <= (java_bit ? 127 : 255) ? "char " : "short"),
(c_bit ? "extern" : " static"),
(c_bit ? "extern" : " static"),
(c_bit ? "extern" : " static"),
(c_bit ? "extern" : " static"),
(c_bit ? "extern" : " static"));
if (table_opt == OPTIMIZE_SPACE)
{
fprintf(sysprs,
"%s const unsigned %s terminal_index[];\n"
"%s const unsigned %s non_terminal_index[];\n",
(c_bit ? "extern" : " static"),
(num_names <= (java_bit ? 127 : 255) ? "char " : "short"),
(c_bit ? "extern" : " static"),
(num_names <= (java_bit ? 127 : 255) ? "char " : "short"));
}
else
{
fprintf(sysprs, "%s const unsigned %s symbol_index[];\n&quo