home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / jikepg12.zip / jikespg / src / lpgparse.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-11-04  |  14.5 KB  |  353 lines

  1. /* $Id: lpgparse.h,v 1.2 1999/11/04 14:02:22 shields Exp $ */
  2. /*
  3.  This software is subject to the terms of the IBM Jikes Compiler
  4.  License Agreement available at the following URL:
  5.  http://www.ibm.com/research/jikes.
  6.  Copyright (C) 1983, 1999, International Business Machines Corporation
  7.  and others.  All Rights Reserved.
  8.  You must accept the terms of that agreement to use this software.
  9. */
  10. /*******************************************************************/
  11. /*******************************************************************/
  12. /**                                                               **/
  13. /**                        OPTIONS DECLARATIONS                   **/
  14. /**                                                               **/
  15. /*******************************************************************/
  16. /*******************************************************************/
  17. /* The following static variables are used only in processing the  */
  18. /* options.                                                        */
  19. /*******************************************************************/
  20. #define OUTPUT_PARM_SIZE MAX_PARM_SIZE + 7
  21. #define MAXIMUM_LA_LEVEL 15
  22. #define STRING_BUFFER_SIZE 8192
  23.  
  24. #if defined(VM) || defined(CW)
  25. static char han[9] = "",
  26.             hat[9] = "INCLUDE",
  27.             ham[3] = "A",
  28.             an[9]  = "",
  29.             at[9]  = "ACTION",
  30.             am[3]  = "A",
  31.             pn[9]  = "",
  32.             pt[9]  = "H",
  33.             pm[3]  = "A",
  34.             sn[9]  = "",
  35.             st[9]  = "H",
  36.             sm[3]  = "A";
  37. #endif
  38.  
  39. static const char *oaction             = "ACTION",
  40.                   *oactfile_name       = "ACTFILENAME",
  41.                   *oactfile_name2      = "ACTFILE-NAME",
  42.                   *oactfile_name3      = "ACTFILE_NAME",
  43. #if defined(VM) || defined(CW)
  44.                   *oactfile_type       = "ACTFILETYPE",
  45.                   *oactfile_type2      = "ACTFILE-TYPE",
  46.                   *oactfile_type3      = "ACTFILE_TYPE",
  47.                   *oactfile_mode       = "ACTFILEMODE",
  48.                   *oactfile_mode2      = "ACTFILE-MODE",
  49.                   *oactfile_mode3      = "ACTFILE_MODE",
  50. #endif
  51.                   *oblockb             = "BLOCKB",
  52.                   *oblocke             = "BLOCKE",
  53.                   *obyte               = "BYTE",
  54.                   *oconflicts          = "CONFLICTS",
  55.                   *odebug              = "DEBUG",
  56.                   *odefault            = "DEFAULT",
  57.                   *odeferred           = "DEFERRED",
  58.                   *oedit               = "EDIT",
  59. /*
  60. Option no longer used ...
  61.                   *oerrproc3           = "ERROR-PROC",
  62.                   *oerrproc2           = "ERROR_PROC",
  63.                   *oerrproc            = "ERRORPROC",
  64. */
  65.                   *oerrormaps2         = "ERROR_MAPS",
  66.                   *oerrormaps3         = "ERROR-MAPS",
  67.                   *oerrormaps          = "ERRORMAPS",
  68.                   *oescape             = "ESCAPE",
  69.                   *ofile_prefix2       = "FILE_PREFIX",
  70.                   *ofile_prefix3       = "FILE-PREFIX",
  71.                   *ofile_prefix        = "FILEPREFIX",
  72.                   *ofirst              = "FIRST",
  73.                   *ofixed              = "FIXED",
  74.                   *ofollow             = "FOLLOW",
  75.                   *ofull               = "FULL",
  76.                   *ogenprsr3           = "GENERATE-PARSER",
  77.                   *ogenprsr2           = "GENERATE_PARSER",
  78.                   *ogenprsr            = "GENERATEPARSER",
  79.                   *ogotodefault2       = "GOTO_DEFAULT",
  80.                   *ogotodefault3       = "GOTO-DEFAULT",
  81.                   *ogotodefault        = "GOTODEFAULT",
  82.                   *ohactfile_name      = "HACTFILENAME",
  83.                   *ohactfile_name2     = "HACTFILE-NAME",
  84.                   *ohactfile_name3     = "HACTFILE_NAME",
  85. #if defined(VM) || defined(CW)
  86.                   *ohactfile_type      = "HACTFILETYPE",
  87.                   *ohactfile_type2     = "HACTFILE-TYPE",
  88.                   *ohactfile_type3     = "HACTFILE_TYPE",
  89.                   *ohactfile_mode      = "HACTFILEMODE",
  90.                   *ohactfile_mode2     = "HACTFILE-MODE",
  91.                   *ohactfile_mode3     = "HACTFILE_MODE",
  92. #endif
  93.                   *ohalfword2          = "HALF_WORD",
  94.                   *ohalfword3          = "HALF-WORD",
  95.                   *ohalfword           = "HALFWORD",
  96.                   *ohblockb            = "HBLOCKB",
  97.                   *ohblocke            = "HBLOCKE",
  98.                   *olalr               = "LALR",
  99.                   *olist               = "LIST",
  100.                   *omax                = "MAXIMUM",
  101.                   *omaximum_distance2  = "MAX_DISTANCE",
  102.                   *omaximum_distance3  = "MAX-DISTANCE",
  103.                   *omaximum_distance   = "MAXDISTANCE",
  104.                   *omin                = "MINIMUM",
  105.                   *ominimum_distance2  = "MIN_DISTANCE",
  106.                   *ominimum_distance3  = "MIN-DISTANCE",
  107.                   *ominimum_distance   = "MINDISTANCE",
  108.                   *onames              = "NAMES",
  109.                   *ontcheck2           = "NT_CHECK",
  110.                   *ontcheck3           = "NT-CHECK",
  111.                   *ontcheck            = "NTCHECK",
  112.                   *ooptimized          = "OPTIMIZED",
  113.                   *oormark             = "ORMARK",
  114.                   *ooutputsize2        = "OUTPUT-SIZE",
  115.                   *ooutputsize3        = "OUTPUT_SIZE",
  116.                   *ooutputsize         = "OUTPUTSIZE",
  117.                   *oprefix             = "PREFIX",
  118.                   *oreadreduce2        = "READ_REDUCE",
  119.                   *oreadreduce3        = "READ-REDUCE",
  120.                   *oreadreduce         = "READREDUCE",
  121. #if defined(VM) || defined(CW)
  122.                   *orecordformat2      = "RECORD_FORMAT",
  123.                   *orecordformat3      = "RECORD-FORMAT",
  124.                   *orecordformat       = "RECORDFORMAT",
  125. #endif
  126. /*
  127. Option no longer used ...
  128.                   *ogettok             = "SCANNER_PROC",
  129.                   *ogettok2            = "SCANNER-PROC",
  130.                   *ogettok3            = "SCANNERPROC",
  131. */
  132.                   *oscopes             = "SCOPES",
  133.                   *oshiftdefault2      = "SHIFT-DEFAULT",
  134.                   *oshiftdefault3      = "SHIFT_DEFAULT",
  135.                   *oshiftdefault       = "SHIFTDEFAULT",
  136.                   *osingleproductions2 = "SINGLE-PRODUCTIONS",
  137.                   *osingleproductions3 = "SINGLE_PRODUCTIONS",
  138.                   *osingleproductions  = "SINGLEPRODUCTIONS",
  139.                   *oslr                = "SLR",
  140. /*
  141. Option no longer used ...
  142.                   *osmactn2            = "SEMANTIC-PROC",
  143.                   *osmactn3            = "SEMANTIC_PROC",
  144.                   *osmactn             = "SEMANTICPROC",
  145. */
  146.                   *ospace              = "SPACE",
  147.                   *ostack_size2        = "STACK_SIZE",
  148.                   *ostack_size3        = "STACK-SIZE",
  149.                   *ostack_size         = "STACKSIZE",
  150.                   *ostates             = "STATES",
  151.                   *osuffix             = "SUFFIX",
  152.                   *otable              = "TABLE",
  153.                   *otime               = "TIME",
  154. /*
  155. Option no longer used ...
  156.                   *otkactn3            = "TERMINAL-PROC",
  157.                   *otkactn2            = "TERMINAL_PROC",
  158.                   *otkactn             = "TERMINALPROC",
  159. */
  160.                   *otrace              = "TRACE",
  161.                   *ovariable           = "VARIABLE",
  162.                   *overbose            = "VERBOSE",
  163.                   *owarnings           = "WARNINGS",
  164.                   *oxref               = "XREF";
  165.  
  166.  
  167. /*******************************************************************/
  168. /*******************************************************************/
  169. /**                                                               **/
  170. /**                        PARSING DECLARATIONS                   **/
  171. /**                                                               **/
  172. /*******************************************************************/
  173. /*******************************************************************/
  174. /* The following static variables are used only in processing the  */
  175. /* the input source.                                               */
  176. /*******************************************************************/
  177. #define CTL_Z '\x1a'
  178. #undef  min
  179. #define min(x, y) ((x) < (y) ? (x) : (y))
  180.  
  181. /*******************************************************************/
  182. /*                                                                 */
  183. /*                             IO variables                        */
  184. /*                                                                 */
  185. /* The two character pointer variables, P1 and P2, are used in     */
  186. /* processing the io buffer, INPUT_BUFFER.                         */
  187. /*******************************************************************/
  188. static char *p1,
  189.             *p2,
  190.             *input_buffer;
  191.  
  192. static char *linestart,
  193.             *bufend,
  194.             *ct_ptr;
  195.  
  196. static short ct            = 0, /* current token & related variables */
  197.              ct_start_col  = 0,
  198.              ct_end_col    = 0,
  199.              ct_length     = 0;
  200.  
  201. static long ct_start_line = 0,
  202.             ct_end_line   = 0;
  203.  
  204. static int num_acts = 0,     /* macro definition & action variables */
  205.            num_defs = 0;
  206.  
  207. static long defelmt_size = 0, /* macro definition & action vars */
  208.             actelmt_size = 0,
  209.             rulehdr_size = 0;
  210.  
  211. struct rulehdr_type       /* structure to store rule in first pass */
  212. {
  213.     struct node *rhs_root;
  214.     short        lhs;
  215.     BOOLEAN      sp;
  216. };
  217.  
  218. struct defelmt_type   /* structure to store location of macro def. */
  219. {
  220.     short                next,
  221.                          length,
  222.                          start_column,
  223.                          end_column;
  224.     char                *macro;
  225.     long                 start_line,
  226.                          end_line;
  227.     char                 name[SYMBOL_SIZE + 1];
  228. };
  229.  
  230. struct actelmt_type       /* structure to store location of action */
  231. {
  232.     long    start_line,
  233.             end_line;
  234.     short   rule_number,
  235.             start_column,
  236.             end_column;
  237.     BOOLEAN header_block;
  238. };
  239.  
  240. struct hash_type         /* structure used to hash grammar symbols */
  241. {
  242.     struct hash_type *link;
  243.     short             number,
  244.                       name_index;
  245.     int               st_ptr;
  246. };
  247.  
  248. struct terminal_type   /* structure used to hold token information */
  249. {
  250.     long  start_line,
  251.           end_line;
  252.     short start_column,
  253.           end_column,
  254.           length,
  255.           kind;
  256.     char  name[SYMBOL_SIZE + 1];
  257. };
  258.  
  259. static struct rulehdr_type   *rulehdr = NULL;
  260. static struct defelmt_type   *defelmt = NULL;
  261. static struct actelmt_type   *actelmt = NULL;
  262.  
  263. static struct node           *start_symbol_root;
  264. static struct hash_type      **hash_table;
  265. static struct terminal_type  *terminal;
  266.  
  267. /******************************************/
  268. /* The following variables hold the names */
  269. /*  of keywords and predefined macros.    */
  270. /******************************************/
  271. static char kdefine[8]             = " define",
  272.             kterminals[11]         = " terminals",
  273.             kalias[7]              = " alias",
  274.             kstart[7]              = " start",
  275.             krules[7]              = " rules",
  276.             knames[7]              = " names",
  277.             kend[5]                = " end",
  278.             krule_text[11]         = " rule_text",
  279.             krule_number[13]       = " rule_number",
  280.             knum_rules[11]         = " num_rules",
  281.             krule_size[11]         = " rule_size",
  282.             knum_terminals[15]     = " num_terminals",
  283.             knum_non_terminals[19] = " num_non_terminals",
  284.             knum_symbols[13]       = " num_symbols",
  285.             kinput_file[12]        = " input_file",
  286.             kcurrent_line[14]      = " current_line",
  287.             knext_line[11]         = " next_line",
  288.  
  289.      /*****************************************************************/
  290.      /* Note that the next four keywords start with \n instead of     */
  291.      /* the escape character.  This is to prevent the user from       */
  292.      /* declaring a grammar symbol with the same name.  The           */
  293.      /* end-of-line character was chosen since that character can     */
  294.      /* never appear in the input without being interpreted as        */
  295.      /* marking the end of an input line.  When printing such a       */
  296.      /* keyword, the \n is properly replaced by the escape character. */
  297.      /* See RESTORE_SYMBOL in the file LPGUTIL.C.                     */
  298.      /*****************************************************************/
  299.             kempty[7]              = "\nempty",
  300.             kerror[7]              = "\nerror",
  301.             keoft[5]               = "\neof",
  302.             kaccept[5]             = "\nacc",
  303.  
  304.             kstart_nt[7]           = " start",
  305.             keolt[5]               = " eol";
  306.  
  307. static struct line_elemt
  308. {
  309.     struct line_elemt *link;
  310.     char line[MAX_LINE_SIZE + 1];
  311. }  *line_pool_root = NULL;
  312.  
  313. static int blockb_len,
  314.            blocke_len,
  315.            hblockb_len,
  316.            hblocke_len;
  317.  
  318. static int stack_top = -1;
  319.  
  320. static void init_process(void);
  321. static void exit_process(void);
  322. static BOOLEAN verify(char *item);
  323. static char *translate(char *str, int len);
  324. static void options(void);
  325. static void process_options_lines(void);
  326. static int hash(char *symbl);
  327. static void insert_string(struct hash_type *q, char *string);
  328. static void assign_symbol_no(char *string_ptr, int image);
  329. static void alias_map(char *stringptr, int image);
  330. static int symbol_image(char *item);
  331. static int name_map(char *symb);
  332. static void process_grammar(void);
  333. static void scanner(void);
  334. static void token_action(void);
  335. static void error_action(void);
  336. static void accept_action(void);
  337. static void build_symno(void);
  338.  
  339. static struct hash_type *alias_root = NULL;
  340. static short *macro_table;
  341.  
  342. static void make_rules_map(void);
  343. static void make_names_map(void);
  344. static void process_actions(void);
  345. static void process_action_line(FILE *sysout, char *text,
  346.                                 int line_no, int rule_no);
  347. static struct line_elemt *alloc_line(void);
  348. static void free_line(struct line_elemt *p);
  349. static void mapmacro(int def_index);
  350. static struct line_elemt *find_macro(char *name);
  351. static void process_aliases(void);
  352. static void display_input(void);
  353.