home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / jikepg12.zip / jikespg / src / ctabs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-11-04  |  110.6 KB  |  3,277 lines

  1. /* $Id: ctabs.c,v 1.2 1999/11/04 14:02:21 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. static char hostfile[] = __FILE__;
  11.  
  12. #include <string.h>
  13. #include "common.h"
  14. #include "space.h"
  15. #include "header.h"
  16.  
  17. static char dcl_tag[SYMBOL_SIZE],
  18.             sym_tag[SYMBOL_SIZE],
  19.             def_tag[SYMBOL_SIZE],
  20.             prs_tag[SYMBOL_SIZE];
  21.  
  22. static int  byte_check_bit = 1;
  23.  
  24. /*********************************************************************/
  25. /*                         NON_TERMINAL_TIME_ACTION:                 */
  26. /*********************************************************************/
  27. static void non_terminal_time_action(void)
  28. {
  29.     if (c_bit)
  30.         fprintf(sysprs,
  31.                 "#define nt_action(state, sym) \\\n"
  32.                 "           ((check[state+sym] == sym) ? \\\n"
  33.                 "                   action[state + sym] : "
  34.                                     "default_goto[sym])\n\n");
  35.     else if (cpp_bit)
  36.         fprintf(sysprs,
  37.                 "    static int nt_action(int state, int sym)\n"
  38.                 "    {\n"
  39.                 "        return (check[state + sym] == sym)\n"
  40.                 "                                    ? action[state + sym]\n"
  41.                 "                                    : default_goto[sym];\n"
  42.                 "    }\n\n");
  43.     else if (java_bit)
  44.         fprintf(sysprs,
  45.                 "    public final static int nt_action(int state, int sym)\n"
  46.                 "    {\n"
  47.                 "        return (check(state + sym) == sym)\n"
  48.                 "                                    ? action[state + sym]\n"
  49.                 "                                    : default_goto[sym];\n"
  50.                 "    }\n\n");
  51.     return;
  52. }
  53.  
  54.  
  55. /*********************************************************************/
  56. /*            NON_TERMINAL_NO_GOTO_DEFAULT_TIME_ACTION:              */
  57. /*********************************************************************/
  58. static void non_terminal_no_goto_default_time_action(void)
  59. {
  60.     if (c_bit)
  61.         fprintf(sysprs,
  62.                 "#define nt_action(state, sym) action[state + sym]\n\n");
  63.     else if (cpp_bit)
  64.         fprintf(sysprs,
  65.                 "    static int nt_action(int state, int sym)\n"
  66.                 "    {\n        return action[state + sym];\n    }\n\n");
  67.     else if (java_bit)
  68.         fprintf(sysprs,
  69.                 "    public final static int nt_action(int state, int sym)\n"
  70.                 "    {\n        return action[state + sym];\n    }\n\n");
  71.     return;
  72. }
  73.  
  74.  
  75. /*********************************************************************/
  76. /*                        NON_TERMINAL_SPACE_ACTION:                 */
  77. /*********************************************************************/
  78. static void non_terminal_space_action(void)
  79. {
  80.     if (c_bit)
  81.         fprintf(sysprs,
  82.                 "#define nt_action(state, sym) \\\n"
  83.                 "           ((base_check[state + sym] == sym) ? \\\n"
  84.                 "               base_action[state + sym] : "
  85.                                     "default_goto[sym])\n\n");
  86.     else if (cpp_bit)
  87.         fprintf(sysprs,
  88.                 "    static int nt_action(int state, int sym)\n"
  89.                 "    {\n"
  90.                 "        return (base_check[state + sym] == sym)\n"
  91.                 "                             ? base_action[state + sym]\n"
  92.                 "                             : default_goto[sym];\n"
  93.                 "    }\n\n");
  94.     else if (java_bit)
  95.         fprintf(sysprs,
  96.                 "    public final static int nt_action(int state, int sym)\n"
  97.                 "    {\n"
  98.                 "        return (base_check(state + sym) == sym)\n"
  99.                 "                             ? base_action[state + sym]\n"
  100.                 "                             : default_goto[sym];\n"
  101.                 "    }\n\n");
  102.     return;
  103. }
  104.  
  105.  
  106. /*********************************************************************/
  107. /*              NON_TERMINAL_NO_GOTO_DEFAULT_SPACE_ACTION:           */
  108. /*********************************************************************/
  109. static void non_terminal_no_goto_default_space_action(void)
  110. {
  111.     if (c_bit)
  112.         fprintf(sysprs,
  113.                 "#define nt_action(state, sym) "
  114.                    "base_action[state + sym]\n\n");
  115.     else if (cpp_bit)
  116.         fprintf(sysprs,
  117.                 "    static int nt_action(int state, int sym)\n"
  118.                 "    {\n        return base_action[state + sym];\n    }\n\n");
  119.     else if (java_bit)
  120.         fprintf(sysprs,
  121.                 "    public final static int nt_action(int state, int sym)\n"
  122.                 "    {\n        return base_action[state + sym];\n    }\n\n");
  123.     return;
  124. }
  125.  
  126.  
  127. /*********************************************************************/
  128. /*                          TERMINAL_TIME_ACTION:                    */
  129. /*********************************************************************/
  130. static void terminal_time_action(void)
  131. {
  132.     if (c_bit)
  133.         fprintf(sysprs,
  134.             "#define t_action(state, sym, next_tok) \\\n"
  135.             "   action[check[state + sym] == sym ? state + sym : state]\n\n");
  136.     else if (cpp_bit)
  137.         fprintf(sysprs,
  138.             "    static int t_action(int state, int sym, LexStream *stream)\n"
  139.             "    {\n"
  140.             "        return action[check[state + sym] == sym"
  141.                                  " ? state + sym : state];\n"
  142.             "    }\n");
  143.  
  144.     else if (java_bit)
  145.         fprintf(sysprs,
  146.             "    public final static int t_action(int state, int sym, LexStream stream)\n"
  147.             "    {\n"
  148.             "        return action[check(state + sym) == sym"
  149.                                  " ? state + sym : state];\n"
  150.             "    }\n");
  151.  
  152.     return;
  153. }
  154.  
  155.  
  156. /*********************************************************************/
  157. /*                          TERMINAL_SPACE_ACTION:                   */
  158. /*********************************************************************/
  159. static void terminal_space_action(void)
  160. {
  161.     if (c_bit)
  162.         fprintf(sysprs,
  163.             "#define t_action(state, sym, next_tok) \\\n"
  164.             "  term_action[term_check[base_action[state]+sym] == sym ? \\\n"
  165.             "          base_action[state] + sym : base_action[state]]\n\n");
  166.     else if (cpp_bit)
  167.         fprintf(sysprs,
  168.             "    static int t_action(int state, int sym, LexStream *stream)\n"
  169.             "    {\n"
  170.             "        return term_action[term_check[base_action[state]"
  171.                                                       "+sym] == sym\n"
  172.             "                               ? base_action[state] + sym\n"
  173.             "                               : base_action[state]];\n"
  174.             "    }\n");
  175.     else if (java_bit)
  176.         fprintf(sysprs,
  177.             "    public final static int t_action(int state, int sym, LexStream stream)\n"
  178.             "    {\n"
  179.             "        return term_action[term_check[base_action[state]"
  180.                                                       "+sym] == sym\n"
  181.             "                               ? base_action[state] + sym\n"
  182.             "                               : base_action[state]];\n"
  183.             "    }\n");
  184.  
  185.     return;
  186. }
  187.  
  188.  
  189. /*********************************************************************/
  190. /*               TERMINAL_SHIFT_DEFAULT_SPACE_ACTION:                */
  191. /*********************************************************************/
  192. static void terminal_shift_default_space_action(void)
  193. {
  194.     if (c_bit)
  195.         fprintf(sysprs,
  196.             "static int t_action(int state, int sym, TokenObject next_tok)\n"
  197.             "{\n"
  198.             "    int i;\n\n"
  199.             "    if (sym == 0)\n"
  200.             "        return ERROR_ACTION;\n"
  201.             "    i = base_action[state];\n"
  202.             "    if (term_check[i + sym] == sym)\n"
  203.             "        return term_action[i + sym];\n"
  204.             "    i = term_action[i];\n"
  205.             "    return ((shift_check[shift_state[i] + sym] == sym) ?\n"
  206.             "                 default_shift[sym] : default_reduce[i]);\n"
  207.             "}\n\n");
  208.     else if (cpp_bit)
  209.         fprintf(sysprs,
  210.             "    static int t_action(int state, int sym, LexStream *stream)\n"
  211.             "    {\n"
  212.             "        if (sym == 0)\n"
  213.             "            return ERROR_ACTION;\n"
  214.             "        int i = base_action[state];\n"
  215.             "        if (term_check[i + sym] == sym)\n"
  216.             "            return term_action[i + sym];\n"
  217.             "        i = term_action[i];\n"
  218.             "        return ((shift_check[shift_state[i] + sym] == sym) ?\n"
  219.             "                      default_shift[sym] : default_reduce[i]);\n"
  220.             "    }\n");
  221.     else if (java_bit)
  222.         fprintf(sysprs,
  223.             "    public final static int t_action(int state, int sym, LexStream stream)\n"
  224.             "    {\n"
  225.             "        if (sym == 0)\n"
  226.             "            return ERROR_ACTION;\n"
  227.             "        int i = base_action[state];\n"
  228.             "        if (term_check[i + sym] == sym)\n"
  229.             "            return term_action[i + sym];\n"
  230.             "        i = term_action[i];\n"
  231.             "        return ((shift_check[shift_state[i] + sym] == sym) ?\n"
  232.             "                      default_shift[sym] : default_reduce[i]);\n"
  233.             "    }\n");
  234.  
  235.     return;
  236. }
  237.  
  238.  
  239. /*********************************************************************/
  240. /*                          TERMINAL_TIME_LALR_K:                    */
  241. /*********************************************************************/
  242. static void terminal_time_lalr_k(void)
  243. {
  244.     if (c_bit)
  245.         fprintf(sysprs,
  246.             "static int t_action(int act, int sym, TokenObject next_tok)\n"
  247.             "{\n"
  248.             "    int i = act + sym;\n\n"
  249.             "    act = action[check[i] == sym ? i : act];\n\n"
  250.             "    if (act > LA_STATE_OFFSET)\n"
  251.             "    {\n"
  252.             "        for (;;)\n"
  253.             "        {\n"
  254.             "            act -= ERROR_ACTION;\n"
  255.             "            sym = Class(next_tok);\n"
  256.             "            i = act + sym;\n"
  257.             "            act = action[check[i] == sym ? i : act];\n"
  258.             "            if (act <= LA_STATE_OFFSET)\n"
  259.             "                break;\n"
  260.             "            next_tok = Next(next_tok);\n"
  261.             "        }\n"
  262.             "    }\n\n"
  263.             "    return act;\n"
  264.             "}\n\n");
  265.     else if (cpp_bit)
  266.         fprintf(sysprs,
  267.             "    static int t_action(int act, int sym, LexStream *stream)\n"
  268.             "    {\n"
  269.             "        int i = act + sym;\n\n"
  270.             "        act = action[check[i] == sym ? i : act];\n\n"
  271.             "        if (act > LA_STATE_OFFSET)\n"
  272.             "        {\n"
  273.             "            for (TokenObject tok = stream -> Peek();\n"
  274.             "                 ;\n"
  275.             "                 tok = stream -> Next(tok))\n"
  276.             "            {\n"
  277.             "                act -= ERROR_ACTION;\n"
  278.             "                sym = stream -> Kind(tok);\n"
  279.             "                i = act + sym;\n"
  280.             "                act = action[check[i] == sym ? i : act];\n"
  281.             "                if (act <= LA_STATE_OFFSET)\n"
  282.             "                    break;\n"
  283.             "            }\n"
  284.             "        }\n\n"
  285.             "        return act;\n"
  286.             "    }\n\n");
  287.     else if (java_bit)
  288.         fprintf(sysprs,
  289.             "    public final static int t_action(int act, int sym, LexStream stream)\n"
  290.             "    {\n"
  291.             "        int i = act + sym;\n\n"
  292.             "        act = action[check(i) == sym ? i : act];\n\n"
  293.             "        if (act > LA_STATE_OFFSET)\n"
  294.             "        {\n"
  295.             "            for (int tok = stream.Peek();\n"
  296.             "                 ;\n"
  297.             "                 tok = stream.Next(tok))\n"
  298.             "            {\n"
  299.             "                act -= ERROR_ACTION;\n"
  300.             "                sym = stream.Kind(tok);\n"
  301.             "                i = act + sym;\n"
  302.             "                act = action[check(i) == sym ? i : act];\n"
  303.             "                if (act <= LA_STATE_OFFSET)\n"
  304.             "                    break;\n"
  305.             "            }\n"
  306.             "        }\n\n"
  307.             "        return act;\n"
  308.             "    }\n\n");
  309.  
  310.     return;
  311. }
  312.  
  313.  
  314. /*********************************************************************/
  315. /*                       TERMINAL_SPACE_LALR_K:                      */
  316. /*********************************************************************/
  317. static void terminal_space_lalr_k(void)
  318. {
  319.     if (c_bit)
  320.         fprintf(sysprs,
  321.             "static int t_action(int state, int sym, TokenObject next_tok)\n"
  322.             "{\n"
  323.             "    int act = base_action[state],\n"
  324.             "          i = act + sym;\n\n"
  325.             "    act = term_action[term_check[i] == sym ? i : act];\n\n"
  326.             "    if (act > LA_STATE_OFFSET)\n"
  327.             "    {\n"
  328.             "        for (;;)\n"
  329.             "        {\n"
  330.             "           act -= LA_STATE_OFFSET;\n"
  331.             "           sym = Class(next_tok);\n"
  332.             "           i = act + sym;\n"
  333.             "           act = term_action[term_check[i] == sym ? i : act];\n"
  334.             "           if (act <= LA_STATE_OFFSET)\n"
  335.             "               break;\n"
  336.             "           next_tok = Next(next_tok);\n"
  337.             "        }\n"
  338.             "    }\n\n"
  339.             "    return act;\n"
  340.             "}\n\n");
  341.     else if (cpp_bit)
  342.         fprintf(sysprs,
  343.         "    static int t_action(int act, int sym, LexStream *stream)\n"
  344.         "    {\n"
  345.         "        act = base_action[act];\n"
  346.         "        int i = act + sym;\n\n"
  347.         "        act = term_action[term_check[i] == sym ? i : act];\n\n"
  348.         "        if (act > LA_STATE_OFFSET)\n"
  349.         "        {\n"
  350.         "            for (TokenObject tok = stream -> Peek();\n"
  351.         "                 ;\n"
  352.         "                 tok = stream -> Next(tok))\n"
  353.         "            {\n"
  354.         "               act -= LA_STATE_OFFSET;\n"
  355.         "               sym = stream -> Kind(tok);\n"
  356.         "               i = act + sym;\n"
  357.         "               act = term_action[term_check[i] == sym ? i : act];\n"
  358.         "               if (act <= LA_STATE_OFFSET)\n"
  359.         "                   break;\n"
  360.         "            } \n"
  361.         "        }\n\n"
  362.         "        return act;\n"
  363.         "    }\n");
  364.     else if (java_bit)
  365.         fprintf(sysprs,
  366.         "    public final static int t_action(int act, int sym, LexStream stream)\n"
  367.         "    {\n"
  368.         "        act = base_action[act];\n"
  369.         "        int i = act + sym;\n\n"
  370.         "        act = term_action[term_check[i] == sym ? i : act];\n\n"
  371.         "        if (act > LA_STATE_OFFSET)\n"
  372.         "        {\n"
  373.         "            for (int tok = stream.Peek();\n"
  374.         "                 ;\n"
  375.         "                 tok = stream.Next(tok))\n"
  376.         "            {\n"
  377.         "               act -= LA_STATE_OFFSET;\n"
  378.         "               sym = stream.Kind(tok);\n"
  379.         "               i = act + sym;\n"
  380.         "               act = term_action[term_check[i] == sym ? i : act];\n"
  381.         "               if (act <= LA_STATE_OFFSET)\n"
  382.         "                   break;\n"
  383.         "            } \n"
  384.         "        }\n\n"
  385.         "        return act;\n"
  386.         "    }\n");
  387.  
  388.     return;
  389. }
  390.  
  391.  
  392. /*********************************************************************/
  393. /*                TERMINAL_SHIFT_DEFAULT_SPACE_LALR_K:               */
  394. /*********************************************************************/
  395. static void terminal_shift_default_space_lalr_k(void)
  396. {
  397.     if (c_bit)
  398.         fprintf(sysprs,
  399.             "static int t_action(int state, int sym, TokenObject next_tok)\n"
  400.             "{\n"
  401.             "    int act = base_action[state],\n"
  402.             "          i = act + sym;\n\n"
  403.             "    if (sym == 0)\n"
  404.             "        act = ERROR_ACTION;\n"
  405.             "    else if (term_check[i] == sym)\n"
  406.             "        act = term_action[i];\n"
  407.             "    else\n"
  408.             "    {\n"
  409.             "        act = term_action[act];\n"
  410.             "        i = shift_state[act] + sym;\n"
  411.             "        act = (shift_check[i] == sym ? default_shift[sym]\n"
  412.             "                                     : default_reduce[act]);\n"
  413.             "    }\n\n"
  414.             "    while (act > LA_STATE_OFFSET)\n"
  415.             "    {\n"
  416.             "         act -= LA_STATE_OFFSET;\n"
  417.             "         sym = Class(next_tok);\n"
  418.             "         i = act + sym;\n"
  419.             "         if (term_check[i] == sym)\n"
  420.             "             act = term_action[i];\n"
  421.             "         else\n"
  422.             "         {\n"
  423.             "             act = term_action[act];\n"
  424.             "             i = shift_state[act] + sym;\n"
  425.             "             act = (shift_check[i] == sym\n"
  426.             "                                    ? default_shift[sym]\n"
  427.             "                                    : default_reduce[act]);\n"
  428.             "         }\n"
  429.             "         if (act <= LA_STATE_OFFSET)\n"
  430.             "             break;\n"
  431.             "         next_tok = Next(next_tok);\n"
  432.             "    }\n\n"
  433.             "    return act;\n"
  434.             "}\n\n");
  435.     else if (cpp_bit)
  436.         fprintf(sysprs,
  437.         "    static int t_action(int act, int sym, LexStream *stream)\n"
  438.         "    {\n"
  439.         "        act = base_action[act];\n"
  440.         "        int i = act + sym;\n\n"
  441.         "        if (sym == 0)\n"
  442.         "            act = ERROR_ACTION;\n"
  443.         "        else if (term_check[i] == sym)\n"
  444.         "            act = term_action[i];\n"
  445.         "        else\n"
  446.         "        {\n"
  447.         "            act = term_action[act];\n"
  448.         "            i = shift_state[act] + sym;\n"
  449.         "            act = (shift_check[i] == sym ? default_shift[sym]\n"
  450.         "                                         : default_reduce[act]);\n"
  451.         "        }\n\n"
  452.         "        if (act > LA_STATE_OFFSET)\n"
  453.         "        {\n"
  454.         "            for (TokenObject tok = stream -> Peek();\n"
  455.         "                 ;\n"
  456.         "                 tok = stream -> Next(tok))\n"
  457.         "            {\n"
  458.         "                 act -= LA_STATE_OFFSET;\n"
  459.         "                 sym = stream -> Kind(tok);\n"
  460.         "                 i = act + sym;\n"
  461.         "                 if (term_check[i] == sym)\n"
  462.         "                     act = term_action[i];\n"
  463.         "                 else\n"
  464.         "                 {\n"
  465.         "                     act = term_action[act];\n"
  466.         "                     i = shift_state[act] + sym;\n"
  467.         "                     act = (shift_check[i] == sym\n"
  468.         "                                            ? default_shift[sym]\n"
  469.         "                                            : default_reduce[act]);\n"
  470.         "                 }\n"
  471.         "                 if (act <= LA_STATE_OFFSET)\n"
  472.         "                     break;\n"
  473.         "            }\n"
  474.         "        }\n\n"
  475.         "        return act;\n"
  476.         "    }\n");
  477.     else if (java_bit)
  478.         fprintf(sysprs,
  479.         "    public final static int t_action(int act, int sym, LexStream stream)\n"
  480.         "    {\n"
  481.         "        act = base_action[act];\n"
  482.         "        int i = act + sym;\n\n"
  483.         "        if (sym == 0)\n"
  484.         "            act = ERROR_ACTION;\n"
  485.         "        else if (term_check[i] == sym)\n"
  486.         "            act = term_action[i];\n"
  487.         "        else\n"
  488.         "        {\n"
  489.         "            act = term_action[act];\n"
  490.         "            i = shift_state[act] + sym;\n"
  491.         "            act = (shift_check[i] == sym ? default_shift[sym]\n"
  492.         "                                         : default_reduce[act]);\n"
  493.         "        }\n\n"
  494.         "        if (act > LA_STATE_OFFSET)\n"
  495.         "        {\n"
  496.         "            for (int tok = stream.Peek();\n"
  497.         "                 ;\n"
  498.         "                 tok = stream.Next(tok))\n"
  499.         "            {\n"
  500.         "                 act -= LA_STATE_OFFSET;\n"
  501.         "                 sym = stream.Kind(tok);\n"
  502.         "                 i = act + sym;\n"
  503.         "                 if (term_check[i] == sym)\n"
  504.         "                     act = term_action[i];\n"
  505.         "                 else\n"
  506.         "                 {\n"
  507.         "                     act = term_action[act];\n"
  508.         "                     i = shift_state[act] + sym;\n"
  509.         "                     act = (shift_check[i] == sym\n"
  510.         "                                            ? default_shift[sym]\n"
  511.         "                                            : default_reduce[act]);\n"
  512.         "                 }\n"
  513.         "                 if (act <= LA_STATE_OFFSET)\n"
  514.         "                     break;\n"
  515.         "            }\n"
  516.         "        }\n\n"
  517.         "        return act;\n"
  518.         "    }\n");
  519.  
  520.     return;
  521. }
  522.  
  523.  
  524. /*********************************************************************/
  525. /*                            INIT_FILE:                             */
  526. /*********************************************************************/
  527. static void init_file(FILE **file, char *file_name, char *file_tag)
  528. {
  529.     char *p;
  530.  
  531. #if defined(C370) && !defined(CW)
  532.     int size;
  533.  
  534.     size = PARSER_LINE_SIZE;
  535.     if (record_format != 'F')
  536.         size += 4;
  537.     sprintf(msg_line, "w, recfm=%cB, lrecl=%d",
  538.                       record_format, size);
  539.  
  540.     p = strchr(file_name, '.');
  541.     if ((*file = fopen(file_name, msg_line)) == NULL)
  542. #else
  543.     p = strrchr(file_name, '.');
  544.     if ((*file = fopen(file_name, "w")) == NULL)
  545. #endif
  546.     {
  547.         fprintf(stderr,
  548.                 "***ERROR: Symbol file \"%s\" cannot be opened\n",
  549.                 file_name);
  550.         exit(12);
  551.     }
  552.  
  553.     memcpy(file_tag, file_name, p - file_name);
  554.     file_tag[p - file_name] = '\0';
  555.  
  556.     if (c_bit || cpp_bit)
  557.     {
  558.         fprintf(*file, "#ifndef %s_INCLUDED\n", file_tag);
  559.         fprintf(*file, "#define %s_INCLUDED\n\n", file_tag);
  560.     }
  561.  
  562.     return;
  563. }
  564.  
  565.  
  566. /*********************************************************************/
  567. /*                        INIT_PARSER_FILES:                         */
  568. /*********************************************************************/
  569. static void init_parser_files(void)
  570. {
  571.     init_file(&sysdcl, dcl_file, dcl_tag);
  572.     init_file(&syssym, sym_file, sym_tag);
  573.     init_file(&sysdef, def_file, def_tag);
  574.     init_file(&sysprs, prs_file, prs_tag);
  575.  
  576.     return;
  577. }
  578.  
  579.  
  580. /*********************************************************************/
  581. /*                            EXIT_PRS_FILE:                         */
  582. /*********************************************************************/
  583. static void exit_parser_files(void)
  584. {
  585.     if (c_bit || cpp_bit)
  586.     {
  587.         fprintf(sysdcl, "\n#endif /* %s_INCLUDED */\n", dcl_tag);
  588.         fprintf(syssym, "\n#endif /* %s_INCLUDED */\n", sym_tag);
  589.         fprintf(sysdef, "\n#endif /* %s_INCLUDED */\n", def_tag);
  590.         fprintf(sysprs, "\n#endif /* %s_INCLUDED */\n", prs_tag);
  591.     }
  592.  
  593.     fclose(sysdcl);
  594.     fclose(syssym);
  595.     fclose(sysdef);
  596.     fclose(sysprs);
  597.  
  598.     return;
  599. }
  600.  
  601.  
  602. /**************************************************************************/
  603. /*                              PRINT_C_NAMES:                            */
  604. /**************************************************************************/
  605. static void print_c_names(void)
  606. {
  607.     char tok[SYMBOL_SIZE + 1];
  608.     short *name_len = Allocate_short_array(num_names + 1);
  609.     long num_bytes = 0;
  610.     int i, j, k, n;
  611.  
  612.     max_name_length = 0;
  613.     mystrcpy("\nconst char  CLASS_HEADER string_buffer[] = {0,\n");
  614.  
  615.     n = 0;
  616.     j = 0;
  617.     padline();
  618.     for (i = 1; i <= num_names; i++)
  619.     {
  620.         strcpy(tok, RETRIEVE_NAME(i));
  621.         name_len[i] = strlen(tok);
  622.         num_bytes += name_len[i];
  623.         if (max_name_length < name_len[i])
  624.             max_name_length = name_len[i];
  625.         k = 0;
  626.         for (j = 0; j < name_len[i]; j++)
  627.         {
  628.             *output_ptr++ = '\'';
  629.             if (tok[k] == '\'' || tok[k] == '\\')
  630.                 *output_ptr++ = '\\';
  631.             if (tok[k] == '\n')
  632.                 *output_ptr++ = escape;
  633.             else
  634.                 *output_ptr++ = tok[k];
  635.             k++;
  636.             *output_ptr++ = '\'';
  637.             *output_ptr++ = ',';
  638.             n++;
  639.             if (n == 10 && ! (i == num_names && j == name_len[i] - 1))
  640.             {
  641.                 n = 0;
  642.                 *output_ptr++ = '\n';
  643.                 BUFFER_CHECK(sysdcl);
  644.                 padline();
  645.             }
  646.         }
  647.     }
  648.     *(output_ptr - 1) = '\n';  /*overwrite last comma*/
  649.     BUFFER_CHECK(sysdcl);
  650.     if (java_bit)
  651.          mystrcpy("    };\n");
  652.     else mystrcpy("                          };\n");
  653.  
  654.     /*****************************************************************/
  655.     /* Compute and list space required for STRING_BUFFER map.        */
  656.     /*****************************************************************/
  657.     sprintf(msg_line,
  658.             "    Storage required for STRING_BUFFER map: %d Bytes",
  659.             num_bytes);
  660.     PRNT(msg_line);
  661.  
  662.     /******************************/
  663.     /* Write out NAME_START array */
  664.     /******************************/
  665.     mystrcpy("\nconst unsigned short CLASS_HEADER name_start[] = {0,\n");
  666.  
  667.     padline();
  668.     j = 1;
  669.     k = 0;
  670.     for (i = 1; i <= num_names; i++)
  671.     {
  672.         itoc(j);
  673.         *output_ptr++ = COMMA;
  674.         j += name_len[i];
  675.         k++;
  676.         if (k == 10 && i != num_names)
  677.         {
  678.             *output_ptr++ = '\n';
  679.             BUFFER_CHECK(sysdcl);
  680.             padline();
  681.             k = 0;
  682.         }
  683.     }
  684.  
  685.     if (k != 0)
  686.     {
  687.         *(output_ptr - 1) = '\n';
  688.         BUFFER_CHECK(sysdcl);
  689.     }
  690.     if (java_bit)
  691.          mystrcpy("    };\n");
  692.     else mystrcpy("                          };\n");
  693.  
  694.     /*****************************************************************/
  695.     /* Compute and list space required for NAME_START map.           */
  696.     /*****************************************************************/
  697.     sprintf(msg_line,
  698.             "    Storage required for NAME_START map: %d Bytes",
  699.             (2 * num_names));
  700.     PRNT(msg_line);
  701.  
  702.     /*******************************/
  703.     /* Write out NAME_LENGTH array */
  704.     /*******************************/
  705.     prnt_shorts("\nconst unsigned char  CLASS_HEADER name_length[] = {0,\n",
  706.                 1, num_names, 10, name_len);
  707.  
  708.     /*****************************************************************/
  709.     /* Compute and list space required for NAME_LENGTH map.          */
  710.     /*****************************************************************/
  711.     sprintf(msg_line,
  712.             "    Storage required for NAME_LENGTH map: %d Bytes",
  713.             num_names);
  714.     PRNT(msg_line);
  715.  
  716.     ffree(name_len);
  717.  
  718.     return;
  719. }
  720.  
  721.  
  722. /**************************************************************************/
  723. /*                             PRINT_JAVA_NAMES:                          */
  724. /**************************************************************************/
  725. static void print_java_names(void)
  726. {
  727.     char tok[SYMBOL_SIZE + 1];
  728.     long num_bytes = 0;
  729.     int i, j, k;
  730.  
  731.     max_name_length = 0;
  732.     mystrcpy("\n    public final static String name[] = { null,\n");
  733.  
  734.     for (i = 1; i <= num_names; i++)
  735.     {
  736.         int len;
  737.         strcpy(tok, RETRIEVE_NAME(i));
  738.         len = strlen(tok);
  739.         num_bytes += (len * 2);
  740.         if (max_name_length < len)
  741.             max_name_length = len;
  742.         padline();
  743.         *output_ptr++ = '\"';
  744.         k = 0;
  745.         for (j = 0; j < len; j++)
  746.         {
  747.             if (tok[j] == '\"' || tok[j] == '\\')
  748.                 *output_ptr++ = '\\';
  749.  
  750.             if (tok[j] == '\n')
  751.                 *output_ptr++ = escape;
  752.             else
  753.                 *output_ptr++ = tok[j];
  754.             k++;
  755.             if (k == 30 && (! (j == len - 1)))
  756.             {
  757.                 k = 0;
  758.                 *output_ptr++ = '\"';
  759.                 *output_ptr++ = ' ';
  760.                 *output_ptr++ = '+';
  761.                 *output_ptr++ = '\n';
  762.                 BUFFER_CHECK(sysdcl);
  763.                 padline();
  764.                 *output_ptr++ = '\"';
  765.             }
  766.         }
  767.         *output_ptr++ = '\"';
  768.         if (i < num_names)
  769.             *output_ptr++ = ',';
  770.         *output_ptr++ = '\n';
  771.     }
  772.     BUFFER_CHECK(sysdcl);
  773.     if (java_bit)
  774.          mystrcpy("    };\n");
  775.     else mystrcpy("                          };\n");
  776.  
  777.     /*****************************************************************/
  778.     /* Compute and list space required for STRING_BUFFER map.        */
  779.     /*****************************************************************/
  780.     sprintf(msg_line,
  781.             "    Storage required for STRING_BUFFER map: %d Bytes",
  782.             num_bytes);
  783.     PRNT(msg_line);
  784.  
  785.     return;
  786. }
  787.  
  788.  
  789. /**************************************************************************/
  790. /*                          PRINT_ERROR_MAPS:                             */
  791. /**************************************************************************/
  792. static void print_error_maps(void)
  793. {
  794.     short *state_start,
  795.           *state_stack,
  796.           *temp,
  797.           *original,
  798.           *as_size,
  799.           *action_symbols_base,
  800.           *action_symbols_range,
  801.           *naction_symbols_base,
  802.           *naction_symbols_range;
  803.  
  804.     int i,
  805.         j,
  806.         k,
  807.         n,
  808.         offset,
  809.         state_no,
  810.         symbol;
  811.  
  812.     long num_bytes;
  813.  
  814.     state_start = Allocate_short_array(num_states + 2);
  815.     state_stack = Allocate_short_array(num_states + 1);
  816.  
  817.     PRNT("\nError maps storage:");
  818.  
  819.     /********************************************************************/
  820.     /* We now construct a bit map for the set of terminal symbols that  */
  821.     /* may appear in each state. Then, we invoke PARTSET to apply the   */
  822.     /* Partition Heuristic and print it.                                */
  823.     /********************************************************************/
  824.     as_size = Allocate_short_array(num_states + 1);
  825.  
  826.     if (table_opt == OPTIMIZE_TIME)
  827.     {
  828.         original = Allocate_short_array(num_symbols + 1);
  829.  
  830.        /*************************************************************/
  831.        /* In a compressed TIME table, the terminal and non-terminal */
  832.        /* symbols are mixed together when they are remapped.        */
  833.        /* We shall now recover the original number associated with  */
  834.        /* each terminal symbol since it lies very nicely in the     */
  835.        /* range 1..NUM_TERMINALS.  This will save a considerable    */
  836.        /* amount of space in the bit_string representation of sets  */
  837.        /* as well as time when operations are performed on those    */
  838.        /* bit-strings.                                              */
  839.        /*************************************************************/
  840.  
  841.        for ALL_TERMINALS(symbol)
  842.           original[symbol_map[symbol]] = symbol;
  843.     }
  844.  
  845.     for ALL_STATES(state_no)
  846.     {
  847.         struct shift_header_type  sh;
  848.         struct reduce_header_type red;
  849.  
  850.         sh = shift[statset[state_no].shift_number];
  851.         as_size[state_no] = sh.size;
  852.         for (i = 1; i <= sh.size; i++)
  853.         {
  854.             if (table_opt == OPTIMIZE_TIME)
  855.                 symbol = original[SHIFT_SYMBOL(sh, i)];
  856.             else
  857.                 symbol = SHIFT_SYMBOL(sh, i);
  858.             SET_BIT_IN(action_symbols, state_no, symbol);
  859.         }
  860.  
  861.         red = reduce[state_no];
  862.         as_size[state_no] += red.size;
  863.         for (i = 1; i <= red.size; i++)
  864.         {
  865.             if (table_opt == OPTIMIZE_TIME)
  866.                 symbol = original[REDUCE_SYMBOL(red, i)];
  867.             else
  868.                 symbol = REDUCE_SYMBOL(red, i);
  869.             SET_BIT_IN(action_symbols, state_no, symbol);
  870.         }
  871.     }
  872.  
  873.     partset(action_symbols, as_size, state_list, state_start,
  874.             state_stack, num_terminals);
  875.  
  876.     ffree(action_symbols);
  877.  
  878. /*************************************************************/
  879. /* Compute and write out the base of the ACTION_SYMBOLS map. */
  880. /*************************************************************/
  881.     action_symbols_base = Allocate_short_array(num_states + 1);
  882.  
  883.     for ALL_STATES(i)
  884.         action_symbols_base[state_list[i]] =
  885.                        ABS(state_start[state_list[i]]);
  886.     if (java_bit)
  887.     {
  888.         prnt_shorts("\n    public final static char asb[] = {0,\n",
  889.                     1, num_states, 10, action_symbols_base);
  890.     }
  891.     else
  892.     {
  893.         prnt_shorts("\nconst unsigned short CLASS_HEADER asb[] = {0,\n",
  894.                     1, num_states, 10, action_symbols_base);
  895.     }
  896.  
  897.     ffree(action_symbols_base);
  898.  
  899. /**************************************************************/
  900. /* Compute and write out the range of the ACTION_SYMBOLS map. */
  901. /**************************************************************/
  902.     offset = state_start[num_states + 1];
  903.     action_symbols_range = Allocate_short_array(offset);
  904.  
  905.     compute_action_symbols_range(state_start, state_stack,
  906.                                  state_list, action_symbols_range);
  907.  
  908.     for (i = 0; i < (offset - 1); i++)
  909.     {
  910.          if (action_symbols_range[i] > (java_bit ? 127 : 255))
  911.          {
  912.              byte_terminal_range = 0;
  913.              break;
  914.          }
  915.     }
  916.  
  917.     if (byte_terminal_range)
  918.     {
  919.         if (java_bit)
  920.         {
  921.             prnt_shorts("\n    public final static byte asr[] = {0,\n",
  922.                         0, offset - 2, 10, action_symbols_range);
  923.         }
  924.         else
  925.         {
  926.             prnt_shorts("\nconst unsigned char  CLASS_HEADER asr[] = {0,\n",
  927.                         0, offset - 2, 10, action_symbols_range);
  928.         }
  929.     }
  930.     else
  931.     {
  932.         if (java_bit)
  933.         {
  934.             prnt_shorts("\n    public final static char asr[] = {0,\n",
  935.                         0, offset - 2, 10, action_symbols_range);
  936.         }
  937.         else
  938.         {
  939.             prnt_shorts("\nconst unsigned short CLASS_HEADER asr[] = {0,\n",
  940.                         0, offset - 2, 10, action_symbols_range);
  941.         }
  942.     }
  943.  
  944.     num_bytes = 2 * num_states;
  945.     sprintf(msg_line,
  946.             "    Storage required for ACTION_SYMBOLS_BASE map: "
  947.             "%ld Bytes", num_bytes);
  948.     PRNT(msg_line);
  949.  
  950.     if ((table_opt == OPTIMIZE_TIME) && (last_terminal <= (java_bit ? 127 : 255)))
  951.         num_bytes = offset - 1;
  952.     else if ((table_opt != OPTIMIZE_TIME) && (num_terminals <= (java_bit ? 127 : 255)))
  953.         num_bytes = offset - 1;
  954.     else
  955.         num_bytes = 2 * (offset - 1);
  956.  
  957.     sprintf(msg_line,
  958.             "    Storage required for ACTION_SYMBOLS_RANGE map: "
  959.             "%ld Bytes", num_bytes);
  960.     PRNT(msg_line);
  961.  
  962.     ffree(action_symbols_range);
  963.  
  964.     /***********************************************************************/
  965.     /* We now repeat the same process for the domain of the GOTO table.    */
  966.     /***********************************************************************/
  967.     for ALL_STATES(state_no)
  968.     {
  969.         as_size[state_no] = gd_index[state_no + 1] - gd_index[state_no];
  970.  
  971.         for (i = gd_index[state_no]; i <= gd_index[state_no + 1] - 1; i++)
  972.         {
  973.              symbol = gd_range[i] - num_terminals;
  974.              NTSET_BIT_IN(naction_symbols, state_no, symbol);
  975.         }
  976.     }
  977.  
  978.     partset(naction_symbols, as_size, state_list, state_start,
  979.             state_stack, num_non_terminals);
  980.  
  981.     ffree(as_size);
  982.     ffree(naction_symbols);
  983.  
  984.     for (i = 1; i <= gotodom_size; i++)  /* Remap non-terminals */
  985.     {
  986.         if (table_opt == OPTIMIZE_SPACE)
  987.             gd_range[i] = symbol_map[gd_range[i]] - num_terminals;
  988.         else
  989.             gd_range[i] = symbol_map[gd_range[i]];
  990.     }
  991.  
  992. /*************************************************************/
  993. /* Compute and write out the base of the NACTION_SYMBOLS map.*/
  994. /*************************************************************/
  995.     naction_symbols_base = Allocate_short_array(num_states + 1);
  996.  
  997.     for ALL_STATES(i)
  998.         naction_symbols_base[state_list[i]] =
  999.                         ABS(state_start[state_list[i]]);
  1000.  
  1001.     if (java_bit)
  1002.     {
  1003.         prnt_shorts("\n    public final static char nasb[] = {0,\n",
  1004.                     1, num_states, 10, naction_symbols_base);
  1005.     }
  1006.     else
  1007.     {
  1008.         prnt_shorts("\nconst unsigned short CLASS_HEADER nasb[] = {0,\n",
  1009.                     1, num_states, 10, naction_symbols_base);
  1010.     }
  1011.  
  1012.     ffree(naction_symbols_base);
  1013.  
  1014. /**************************************************************/
  1015. /* Compute and write out the range of the NACTION_SYMBOLS map.*/
  1016. /**************************************************************/
  1017.     offset = state_start[num_states + 1];
  1018.     naction_symbols_range = Allocate_short_array(offset);
  1019.  
  1020.     compute_naction_symbols_range(state_start, state_stack,
  1021.                                   state_list, naction_symbols_range);
  1022.  
  1023.     if (java_bit)
  1024.     {
  1025.         prnt_shorts("\n    public final static char nasr[] = {0,\n",
  1026.                     0, offset - 2, 10, naction_symbols_range);
  1027.     }
  1028.     else
  1029.     {
  1030.         prnt_shorts("\nconst unsigned short CLASS_HEADER nasr[] = {0,\n",
  1031.                     0, offset - 2, 10, naction_symbols_range);
  1032.     }
  1033.  
  1034.     num_bytes = 2 * num_states;
  1035.     sprintf(msg_line,
  1036.             "    Storage required for NACTION_SYMBOLS_BASE map: "
  1037.             "%ld Bytes", num_bytes);
  1038.     PRNT(msg_line);
  1039.     num_bytes = 2 * (offset - 1);
  1040.     sprintf(msg_line,
  1041.             "    Storage required for NACTION_SYMBOLS_RANGE map: "
  1042.             "%ld Bytes", ((long) 2 * (offset - 1)));
  1043.     PRNT(msg_line);
  1044.  
  1045.     ffree(naction_symbols_range);
  1046.  
  1047.     /*********************************************************************/
  1048.     /* We write the name_index of each terminal symbol.  The array TEMP  */
  1049.     /* is used to remap the NAME_INDEX values based on the new symbol    */
  1050.     /* numberings. If time tables are requested, the terminals and non-  */
  1051.     /* terminals are mixed together.                                     */
  1052.     /*********************************************************************/
  1053.     temp = Allocate_short_array(num_symbols + 1);
  1054.  
  1055.     if (table_opt == OPTIMIZE_SPACE)
  1056.     {
  1057.         for ALL_TERMINALS(symbol)
  1058.             temp[symbol_map[symbol]] = symno[symbol].name_index;
  1059.  
  1060.         if (num_names <= (java_bit ? 127 : 255))
  1061.         {
  1062.             if (java_bit)
  1063.             {
  1064.                 prnt_shorts
  1065.                    ("\n    public final static byte terminal_index[] = {0,\n",
  1066.                     1, num_terminals, 10, temp);
  1067.             }
  1068.             else
  1069.             {
  1070.                 prnt_shorts
  1071.                    ("\nconst unsigned char  CLASS_HEADER terminal_index[] = {0,\n",
  1072.                     1, num_terminals, 10, temp);
  1073.             }
  1074.             num_bytes =  num_terminals;
  1075.         }
  1076.         else
  1077.         {
  1078.             if (java_bit)
  1079.             {
  1080.                 prnt_shorts
  1081.                   ("\n    public final static char terminal_index[] = {0,\n",
  1082.                    1, num_terminals, 10, temp);
  1083.             }
  1084.             else
  1085.             {
  1086.                 prnt_shorts
  1087.                   ("\nconst unsigned short CLASS_HEADER terminal_index[] = {0,\n",
  1088.                    1, num_terminals, 10, temp);
  1089.             }
  1090.             num_bytes = 2 * num_terminals;
  1091.         }
  1092.         /*****************************************************************/
  1093.         /* Compute and list space required for TERMINAL_INDEX map.       */
  1094.         /*****************************************************************/
  1095.         sprintf(msg_line,
  1096.                 "    Storage required for TERMINAL_INDEX map: %d Bytes",
  1097.                 num_bytes);
  1098.         PRNT(msg_line);
  1099.  
  1100.         /******************************************************************/
  1101.         /* We write the name_index of each non_terminal symbol. The array */
  1102.         /* TEMP is used to remap the NAME_INDEX values based on the new   */
  1103.         /* symbol numberings.                                             */
  1104.         /******************************************************************/
  1105.         for ALL_NON_TERMINALS(symbol)
  1106.             temp[symbol_map[symbol]] = symno[symbol].name_index;
  1107.  
  1108.         if (num_names <= (java_bit ? 127 : 255))
  1109.         {
  1110.             if (java_bit)
  1111.             {
  1112.                 prnt_shorts
  1113.                     ("\n    public final static byte "
  1114.                      "non_terminal_index[] = {0,\n",
  1115.                      num_terminals + 1, num_symbols, 10, temp);
  1116.             }
  1117.             else
  1118.             {
  1119.                 prnt_shorts
  1120.                     ("\nconst unsigned char  CLASS_HEADER "
  1121.                      "non_terminal_index[] = {0,\n",
  1122.                      num_terminals + 1, num_symbols, 10, temp);
  1123.             }
  1124.             num_bytes = num_non_terminals;
  1125.         }
  1126.         else
  1127.         {
  1128.             if (java_bit)
  1129.             {
  1130.                 prnt_shorts
  1131.                     ("\n    public final static char "
  1132.                      "non_terminal_index[] = {0,\n",
  1133.                      num_terminals + 1, num_symbols, 10, temp);
  1134.             }
  1135.             else
  1136.             {
  1137.                 prnt_shorts
  1138.                     ("\nconst unsigned short CLASS_HEADER "
  1139.                      "non_terminal_index[] = {0,\n",
  1140.                      num_terminals + 1, num_symbols, 10, temp);
  1141.             }
  1142.             num_bytes = 2 * num_non_terminals;
  1143.         }
  1144.         /*****************************************************************/
  1145.         /* Compute and list space required for NON_TERMINAL_INDEX map.   */
  1146.         /*****************************************************************/
  1147.         sprintf(msg_line,
  1148.                 "    Storage required for NON_TERMINAL_INDEX map: %d Bytes",
  1149.                 num_bytes);
  1150.         PRNT(msg_line);
  1151.     }
  1152.     else
  1153.     {
  1154.         for ALL_SYMBOLS(symbol)
  1155.             temp[symbol_map[symbol]] = symno[symbol].name_index;
  1156.         if (num_names <= (java_bit ? 127 : 255))
  1157.         {
  1158.             if (java_bit)
  1159.             {
  1160.                 prnt_shorts
  1161.                    ("\n    public final static byte symbol_index[] = {0,\n",
  1162.                     1, num_symbols, 10, temp);
  1163.                 mystrcpy("    public final static byte terminal_index[] = "
  1164.                          "symbol_index;\n");
  1165.                 mystrcpy("    public final static byte non_terminal_index[] = "
  1166.                          "symbol_index;\n");
  1167.             }
  1168.             else
  1169.             {
  1170.                 prnt_shorts
  1171.                    ("\nconst unsigned char  CLASS_HEADER symbol_index[] = {0,\n",
  1172.                     1, num_symbols, 10, temp);
  1173.                 mystrcpy("const unsigned char  *CLASS_HEADER terminal_index[] = "
  1174.                          "&(symbol_index[0]);\n");
  1175.                 mystrcpy("const unsigned char  *CLASS_HEADER non_terminal_index[] = "
  1176.                          "&(symbol_index[0]);\n");
  1177.             }
  1178.             num_bytes = num_symbols;
  1179.         }
  1180.         else
  1181.         {
  1182.             if (java_bit)
  1183.             {
  1184.                 prnt_shorts
  1185.                    ("\n    public final static char symbol_index[] = {0,\n",
  1186.                     1, num_symbols, 10, temp);
  1187.                 mystrcpy("    public final static char terminal_index[] = "
  1188.                          "symbol_index[0];\n");
  1189.                 mystrcpy("    public final static char non_terminal_index[] = "
  1190.                          "symbol_index;\n");
  1191.             }
  1192.             else
  1193.             {
  1194.                 prnt_shorts
  1195.                    ("\nconst unsigned short CLASS_HEADER symbol_index[] = {0,\n",
  1196.                     1, num_symbols, 10, temp);
  1197.                 mystrcpy("const unsigned short *CLASS_HEADER terminal_index[] = "
  1198.                          "&(symbol_index[0]);\n");
  1199.                 mystrcpy("const unsigned short *CLASS_HEADER non_terminal_index[] = "
  1200.                          "&(symbol_index[0]);\n");
  1201.             }
  1202.             num_bytes = 2 * num_symbols;
  1203.         }
  1204.         /*****************************************************************/
  1205.         /* Compute and list space required for SYMBOL_INDEX map.         */
  1206.         /*****************************************************************/
  1207.         sprintf(msg_line,
  1208.                 "    Storage required for SYMBOL_INDEX map: %d Bytes",
  1209.                 num_bytes);
  1210.         PRNT(msg_line);
  1211.     }
  1212.     if (num_scopes > 0)
  1213.     {
  1214.         short root = 0;
  1215.         short *list;
  1216.         list = Allocate_short_array(scope_rhs_size + 1);
  1217.  
  1218.         for (i = 1; i <= scope_rhs_size; i++)
  1219.         {
  1220.             if (scope_right_side[i] != 0)
  1221.                 scope_right_side[i] = symbol_map[scope_right_side[i]];
  1222.         }
  1223.  
  1224.         for (i = 1; i <= num_scopes; i++)
  1225.         {
  1226.             scope[i].look_ahead = symbol_map[scope[i].look_ahead];
  1227.             if (table_opt == OPTIMIZE_SPACE)
  1228.                 scope[i].lhs_symbol = symbol_map[scope[i].lhs_symbol]
  1229.                                       - num_terminals;
  1230.             else
  1231.                 scope[i].lhs_symbol = symbol_map[scope[i].lhs_symbol];
  1232.         }
  1233.         /****************************************/
  1234.         /* Mark all elements of prefix strings. */
  1235.         /****************************************/
  1236.         for (i=1; i <= scope_rhs_size; i++)
  1237.              list[i] = -1;
  1238.  
  1239.         for (i = 1; i <= num_scopes; i++)
  1240.         {
  1241.             if (list[scope[i].suffix] < 0)
  1242.             {
  1243.                 list[scope[i].suffix] = root;
  1244.                 root = scope[i].suffix;
  1245.             }
  1246.         }
  1247.  
  1248.         for (; root != 0; root = list[root])
  1249.         {
  1250.             for (j = root; scope_right_side[j] != 0; j++)
  1251.             {
  1252.                 k = scope_right_side[j];
  1253.                 scope_right_side[j] = temp[k];
  1254.             }
  1255.         }
  1256.         ffree(list);
  1257.     }
  1258.  
  1259.     if (java_bit)
  1260.          print_java_names();
  1261.     else print_c_names();
  1262.  
  1263.     if (num_scopes > 0)
  1264.     {
  1265.         if (scope_rhs_size <= (java_bit ? 127 : 255))
  1266.         {
  1267.             if (java_bit)
  1268.                  mystrcpy("\n    public final static byte scope_prefix[] = {\n");
  1269.             else mystrcpy("\nconst unsigned char  CLASS_HEADER scope_prefix[] = {\n");
  1270.         }
  1271.         else
  1272.         {
  1273.             if (java_bit)
  1274.                  mystrcpy("\n    public final static char scope_prefix[] = {\n");
  1275.             else mystrcpy("\nconst unsigned short CLASS_HEADER scope_prefix[] = {\n");
  1276.         }
  1277.  
  1278.         padline();
  1279.         k = 0;
  1280.         for (i = 1; i <= num_scopes; i++)
  1281.         {
  1282.             itoc(scope[i].prefix);
  1283.             *output_ptr++ = COMMA;
  1284.             k++;
  1285.             if (k == 10 && i != num_scopes)
  1286.             {
  1287.                 *output_ptr++ = '\n';
  1288.                 BUFFER_CHECK(sysdcl);
  1289.                 padline();
  1290.                 k = 0;
  1291.             }
  1292.         }
  1293.         if (k != 0)
  1294.         {
  1295.             *(output_ptr - 1) = '\n';
  1296.             BUFFER_CHECK(sysdcl);
  1297.         }
  1298.         if (java_bit)
  1299.              mystrcpy("    };\n");
  1300.         else mystrcpy("                          };\n");
  1301.  
  1302.         if (scope_rhs_size <= (java_bit ? 127 : 255))
  1303.         {
  1304.             if (java_bit)
  1305.                  mystrcpy("\n    public final static byte scope_suffix[] = {\n");
  1306.             else mystrcpy("\nconst unsigned char  CLASS_HEADER scope_suffix[] = {\n");
  1307.         }
  1308.         else
  1309.         {
  1310.             if (java_bit)
  1311.                  mystrcpy("\n    public final static char scope_suffix[] = {\n");
  1312.             else mystrcpy("\nconst unsigned short CLASS_HEADER scope_suffix[] = {\n");
  1313.         }
  1314.  
  1315.         padline();
  1316.         k = 0;
  1317.         for (i = 1; i <= num_scopes; i++)
  1318.         {
  1319.             itoc(scope[i].suffix);
  1320.             *output_ptr++ = COMMA;
  1321.             k++;
  1322.             if (k == 10 && i != num_scopes)
  1323.             {
  1324.                 *output_ptr++ = '\n';
  1325.                 BUFFER_CHECK(sysdcl);
  1326.                 padline();
  1327.                 k = 0;
  1328.             }
  1329.         }
  1330.         if (k != 0)
  1331.         {
  1332.             *(output_ptr - 1) = '\n';
  1333.             BUFFER_CHECK(sysdcl);
  1334.         }
  1335.         if (java_bit)
  1336.              mystrcpy("    };\n");
  1337.         else mystrcpy("                          };\n");
  1338.  
  1339.         if (num_symbols <= (java_bit ? 127 : 255))
  1340.         {
  1341.             if (java_bit)
  1342.                  mystrcpy("\n    public final static byte scope_lhs[] = {\n");
  1343.             else mystrcpy("\nconst unsigned char  CLASS_HEADER scope_lhs[] = {\n");
  1344.         }
  1345.         else
  1346.         {
  1347.             if (java_bit)
  1348.                  mystrcpy("\n    public final static char scope_lhs[] = {\n");
  1349.             else mystrcpy("\nconst unsigned short CLASS_HEADER scope_lhs[] = {\n");
  1350.         }
  1351.  
  1352.         padline();
  1353.         k = 0;
  1354.         for (i = 1; i <= num_scopes; i++)
  1355.         {
  1356.             itoc(scope[i].lhs_symbol);
  1357.             *output_ptr++ = COMMA;
  1358.             k++;
  1359.             if (k == 10 && i != num_scopes)
  1360.             {
  1361.                 *output_ptr++ = '\n';
  1362.                 BUFFER_CHECK(sysdcl);
  1363.                 padline();
  1364.                 k = 0;
  1365.             }
  1366.         }
  1367.         if (k != 0)
  1368.         {
  1369.             *(output_ptr - 1) = '\n';
  1370.             BUFFER_CHECK(sysdcl);
  1371.         }
  1372.         if (java_bit)
  1373.              mystrcpy("    };\n");
  1374.         else mystrcpy("                          };\n");
  1375.  
  1376.         if (num_terminals <= (java_bit ? 127 : 255))
  1377.         {
  1378.             if (java_bit)
  1379.                  mystrcpy("\n    public final static byte scope_la[] = {\n");
  1380.             else mystrcpy("\nconst unsigned char  CLASS_HEADER scope_la[] = {\n");
  1381.         }
  1382.         else
  1383.         {
  1384.             if (java_bit)
  1385.                  mystrcpy("\n    public final static char scope_la[] = {\n");
  1386.             else mystrcpy("\nconst unsigned short CLASS_HEADER scope_la[] = {\n");
  1387.         }
  1388.  
  1389.         padline();
  1390.         k = 0;
  1391.         for (i = 1; i <= num_scopes; i++)
  1392.         {
  1393.             itoc(scope[i].look_ahead);
  1394.             *output_ptr++ = COMMA;
  1395.             k++;
  1396.             if (k == 10 && i != num_scopes)
  1397.             {
  1398.                 *output_ptr++ = '\n';
  1399.                 BUFFER_CHECK(sysdcl);
  1400.                 padline();
  1401.                 k = 0;
  1402.             }
  1403.         }
  1404.         if (k != 0)
  1405.         {
  1406.             *(output_ptr - 1) = '\n';
  1407.             BUFFER_CHECK(sysdcl);
  1408.         }
  1409.         if (java_bit)
  1410.              mystrcpy("    };\n");
  1411.         else mystrcpy("                          };\n");
  1412.  
  1413.         if (scope_state_size <= (java_bit ? 127 : 255))
  1414.         {
  1415.             if (java_bit)
  1416.                  mystrcpy("\n    public final static byte scope_state_set[] = {\n");
  1417.             else mystrcpy("\nconst unsigned char  CLASS_HEADER scope_state_set[] = {\n");
  1418.         }
  1419.         else
  1420.         {
  1421.             if (java_bit)
  1422.                  mystrcpy("\n    public final static char scope_state_set[] = {\n");
  1423.             else mystrcpy("\nconst unsigned short CLASS_HEADER scope_state_set[] = {\n");
  1424.         }
  1425.  
  1426.         padline();
  1427.         k = 0;
  1428.         for (i = 1; i <= num_scopes; i++)
  1429.         {
  1430.             itoc(scope[i].state_set);
  1431.             *output_ptr++ = COMMA;
  1432.             k++;
  1433.             if (k == 10 && i != num_scopes)
  1434.             {
  1435.                 *output_ptr++ = '\n';
  1436.                 BUFFER_CHECK(sysdcl);
  1437.                 padline();
  1438.                 k = 0;
  1439.             }
  1440.         }
  1441.         if (k != 0)
  1442.         {
  1443.             *(output_ptr - 1) = '\n';
  1444.             BUFFER_CHECK(sysdcl);
  1445.         }
  1446.         if (java_bit)
  1447.              mystrcpy("    };\n");
  1448.         else mystrcpy("                          };\n");
  1449.  
  1450.         if (num_symbols <= (java_bit ? 127 : 255))
  1451.         {
  1452.             if (java_bit)
  1453.             {
  1454.                 prnt_shorts
  1455.                     ("\n    public final static byte scope_rhs[] = {0,\n",
  1456.                      1, scope_rhs_size, 10, scope_right_side);
  1457.             }
  1458.             else
  1459.             {
  1460.                 prnt_shorts
  1461.                     ("\nconst unsigned char  CLASS_HEADER scope_rhs[] = {0,\n",
  1462.                      1, scope_rhs_size, 10, scope_right_side);
  1463.             }
  1464.         }
  1465.         else
  1466.         {
  1467.             if (java_bit)
  1468.             {
  1469.                 prnt_shorts
  1470.                     ("\n    public final static char scope_rhs[] = {0,\n",
  1471.                      1, scope_rhs_size, 10, scope_right_side);
  1472.             }
  1473.             else
  1474.             {
  1475.                 prnt_shorts
  1476.                     ("\nconst unsigned short CLASS_HEADER scope_rhs[] = {0,\n",
  1477.                      1, scope_rhs_size, 10, scope_right_side);
  1478.             }
  1479.         }
  1480.  
  1481.         if (java_bit)
  1482.              mystrcpy("\n    public final static char scope_state[] = {0,\n");
  1483.         else mystrcpy("\nconst unsigned short CLASS_HEADER scope_state[] = {0,\n");
  1484.  
  1485.         padline();
  1486.         k = 0;
  1487.         for (i = 1; i <= scope_state_size; i++)
  1488.         {
  1489.             if (scope_state[i] == 0)
  1490.                 itoc(0);
  1491.             else
  1492.                 itoc(state_index[scope_state[i]] + num_rules);
  1493.             *output_ptr++ = COMMA;
  1494.             k++;
  1495.             if (k == 10 && i != scope_state_size)
  1496.             {
  1497.                 *output_ptr++ = '\n';
  1498.                 BUFFER_CHECK(sysdcl);
  1499.                 padline();
  1500.                 k = 0;
  1501.             }
  1502.         }
  1503.         if (k != 0)
  1504.         {
  1505.             *(output_ptr - 1) = '\n';
  1506.             BUFFER_CHECK(sysdcl);
  1507.         }
  1508.         if (java_bit)
  1509.              mystrcpy("    };\n");
  1510.         else mystrcpy("                          };\n");
  1511.  
  1512.         if (num_symbols <= (java_bit ? 127 : 255))
  1513.         {
  1514.             if (java_bit)
  1515.                  mystrcpy("\n    public final static byte in_symb[] = {0,\n");
  1516.             else mystrcpy("\nconst unsigned char  CLASS_HEADER in_symb[] = {0,\n");
  1517.         }
  1518.         else
  1519.         {
  1520.             if (java_bit)
  1521.                  mystrcpy("\n    public final static char in_symb[] = {0,\n");
  1522.             else mystrcpy("\nconst unsigned short CLASS_HEADER in_symb[] = {0,\n");
  1523.         }
  1524.  
  1525.         /* Transition symbol */
  1526.         padline();
  1527.         *output_ptr++ = '0';
  1528.         *output_ptr++ = COMMA;
  1529.         k = 1;
  1530.         for (state_no = 2; state_no <= (int) num_states; state_no++)
  1531.         {
  1532.             struct node *q;
  1533.             int item_no;
  1534.  
  1535.             q = statset[state_no].kernel_items;
  1536.             if (q != NULL)
  1537.             {
  1538.                 item_no = q -> value - 1;
  1539.                 i = item_table[item_no].symbol;
  1540.             }
  1541.             else i = 0;
  1542.  
  1543.             itoc(symbol_map[i]);
  1544.             *output_ptr++ = COMMA;
  1545.             k++;
  1546.             if (k == 10 && state_no != (int) num_states)
  1547.             {
  1548.                 *output_ptr++ = '\n';
  1549.                 BUFFER_CHECK(sysdcl);
  1550.                 padline();
  1551.                 k = 0;
  1552.             }
  1553.         }
  1554.         if (k != 0)
  1555.         {
  1556.             *(output_ptr - 1) = '\n';
  1557.             BUFFER_CHECK(sysdcl);
  1558.         }
  1559.         if (java_bit)
  1560.              mystrcpy("    };\n");
  1561.         else mystrcpy("                          };\n");
  1562.     }
  1563.  
  1564.     return;
  1565. }
  1566.  
  1567.  
  1568. /****************************************************************************/
  1569. /*                               PRINT_SYMBOLS:                             */
  1570. /****************************************************************************/
  1571. static void print_symbols(void)
  1572. {
  1573.     int symbol;
  1574.     char line[SYMBOL_SIZE +       /* max length of a token symbol  */
  1575.               2 * MAX_PARM_SIZE + /* max length of prefix + suffix */
  1576.               64];                /* +64 for error messages lines  */
  1577.                                   /* or other fillers(blank, =,...)*/
  1578.     if (java_bit)
  1579.     {
  1580.          strcpy(line, "interface ");
  1581.          strcat(line, sym_tag);
  1582.          strcat(line, "\n{\n    public final static int\n");
  1583.     }
  1584.     else strcpy(line, "enum {\n");
  1585.  
  1586.     /*********************************************************/
  1587.     /* We write the terminal symbols map.                    */
  1588.     /*********************************************************/
  1589.     for ALL_TERMINALS(symbol)
  1590.     {
  1591.         char *tok = RETRIEVE_STRING(symbol);
  1592.  
  1593.         fprintf(syssym, "%s", line);
  1594.  
  1595.         if (tok[0] == '\n' || tok[0] == escape)
  1596.         {
  1597.             tok[0] = escape;
  1598.             sprintf(line, "Escaped symbol %s is an invalid C variable.\n",tok);
  1599.             PRNT(line);
  1600.         }
  1601.         else if (strpbrk(tok, "!%^&*()-+={}[];:\"`~|\\,.<>/?\'") != NULL)
  1602.         {
  1603.             sprintf(line, "%s may be an invalid variable name.\n", tok);
  1604.             PRNT(line);
  1605.         }
  1606.  
  1607.         sprintf(line, "      %s%s%s = %i,\n\0",
  1608.                       prefix, tok, suffix, symbol_map[symbol]);
  1609.  
  1610.         if (c_bit || cpp_bit)
  1611.         {
  1612.             while(strlen(line) > PARSER_LINE_SIZE)
  1613.             {
  1614.                 fwrite(line, sizeof(char), PARSER_LINE_SIZE - 2, syssym);
  1615.                 fprintf(syssym, "\\\n");
  1616.                 strcpy(line, &line[PARSER_LINE_SIZE - 2]);
  1617.             }
  1618.         }
  1619.     }
  1620.  
  1621.     line[strlen(line) - 2] = '\0'; /* remove the string ",\n" from last line */
  1622.     fprintf(syssym, "%s%s", line, (java_bit ? ";\n}\n" : "\n     };\n"));
  1623.  
  1624.     return;
  1625. }
  1626.  
  1627.  
  1628. /****************************************************************************/
  1629. /*                            PRINT_DEFINITIONS:                            */
  1630. /****************************************************************************/
  1631. static void print_definitions(void)
  1632. {
  1633.     if (java_bit)
  1634.          fprintf(sysdef, "interface %s\n{\n    public final static int\n\n",
  1635.                          def_tag);
  1636.     else fprintf(sysdef, "enum {\n");
  1637.  
  1638.     if (error_maps_bit)
  1639.     {
  1640.         if (java_bit)
  1641.              fprintf(sysdef,
  1642.                      "      ERROR_SYMBOL      = %d,\n"
  1643.                      "      MAX_NAME_LENGTH   = %d,\n"
  1644.                      "      NUM_STATES        = %d,\n\n",
  1645.                      error_image,
  1646.                      max_name_length,
  1647.                      num_states);
  1648.         else fprintf(sysdef,
  1649.                      "      ERROR_CODE,\n"
  1650.                      "      BEFORE_CODE,\n"
  1651.                      "      INSERTION_CODE,\n"
  1652.                      "      INVALID_CODE,\n"
  1653.                      "      SUBSTITUTION_CODE,\n"
  1654.                      "      DELETION_CODE,\n"
  1655.                      "      MERGE_CODE,\n"
  1656.                      "      MISPLACED_CODE,\n"
  1657.                      "      SCOPE_CODE,\n"
  1658.                      "      MANUAL_CODE,\n"
  1659.                      "      SECONDARY_CODE,\n"
  1660.                      "      EOF_CODE,\n\n"
  1661.  
  1662.                      "      ERROR_SYMBOL      = %d,\n"
  1663.                      "      MAX_DISTANCE      = %d,\n"
  1664.                      "      MIN_DISTANCE      = %d,\n"
  1665.                      "      MAX_NAME_LENGTH   = %d,\n"
  1666.                      "      MAX_TERM_LENGTH   = %d,\n"
  1667.                      "      NUM_STATES        = %d,\n\n",
  1668.  
  1669.                      error_image,
  1670.                      maximum_distance,
  1671.                      minimum_distance,
  1672.                      max_name_length,
  1673.                      max_name_length,
  1674.                      num_states);
  1675.     }
  1676.  
  1677.     if (java_bit)
  1678.          fprintf(sysdef,
  1679.                  "      NT_OFFSET         = %d,\n"
  1680.                  "      SCOPE_UBOUND      = %d,\n"
  1681.                  "      SCOPE_SIZE        = %d,\n"
  1682.                  "      LA_STATE_OFFSET   = %d,\n"
  1683.                  "      MAX_LA            = %d,\n"
  1684.                  "      NUM_RULES         = %d,\n"
  1685.                  "      NUM_TERMINALS     = %d,\n"
  1686.                  "      NUM_NON_TERMINALS = %d,\n"
  1687.                  "      NUM_SYMBOLS       = %d,\n"
  1688.                  "      START_STATE       = %d,\n"
  1689.                  "      EOFT_SYMBOL       = %d,\n"
  1690.                  "      EOLT_SYMBOL       = %d,\n"
  1691.                  "      ACCEPT_ACTION     = %d,\n"
  1692.                  "      ERROR_ACTION      = %d;\n"
  1693.                  "};\n\n",
  1694.  
  1695.  
  1696.                  (table_opt == OPTIMIZE_SPACE ? num_terminals : num_symbols),
  1697.                  num_scopes - 1,
  1698.                  num_scopes,
  1699.                  (read_reduce_bit && lalr_level > 1
  1700.                                    ? error_act + num_rules : error_act),
  1701.                  lalr_level,
  1702.                  num_rules,
  1703.                  num_terminals,
  1704.                  num_non_terminals,
  1705.                  num_symbols,
  1706.                  state_index[1] + num_rules,
  1707.                  eoft_image,
  1708.                  eolt_image,
  1709.                  accept_act,
  1710.                  error_act);
  1711.     else fprintf(sysdef,
  1712.                  "      NT_OFFSET         = %d,\n"
  1713.                  "      BUFF_UBOUND       = %d,\n"
  1714.                  "      BUFF_SIZE         = %d,\n"
  1715.                  "      STACK_UBOUND      = %d,\n"
  1716.                  "      STACK_SIZE        = %d,\n"
  1717.                  "      SCOPE_UBOUND      = %d,\n"
  1718.                  "      SCOPE_SIZE        = %d,\n"
  1719.                  "      LA_STATE_OFFSET   = %d,\n"
  1720.                  "      MAX_LA            = %d,\n"
  1721.                  "      NUM_RULES         = %d,\n"
  1722.                  "      NUM_TERMINALS     = %d,\n"
  1723.                  "      NUM_NON_TERMINALS = %d,\n"
  1724.                  "      NUM_SYMBOLS       = %d,\n"
  1725.                  "      START_STATE       = %d,\n"
  1726.                  "      EOFT_SYMBOL       = %d,\n"
  1727.                  "      EOLT_SYMBOL       = %d,\n"
  1728.                  "      ACCEPT_ACTION     = %d,\n"
  1729.                  "      ERROR_ACTION      = %d\n"
  1730.                  "     };\n\n",
  1731.  
  1732.  
  1733.                  (table_opt == OPTIMIZE_SPACE ? num_terminals : num_symbols),
  1734.                  maximum_distance + lalr_level - 1,
  1735.                  maximum_distance + lalr_level,
  1736.                  stack_size - 1,
  1737.                  stack_size,
  1738.                  num_scopes - 1,
  1739.                  num_scopes,
  1740.                  (read_reduce_bit && lalr_level > 1
  1741.                                    ? error_act + num_rules : error_act),
  1742.                  lalr_level,
  1743.                  num_rules,
  1744.                  num_terminals,
  1745.                  num_non_terminals,
  1746.                  num_symbols,
  1747.                  state_index[1] + num_rules,
  1748.                  eoft_image,
  1749.                  eolt_image,
  1750.                  accept_act,
  1751.                  error_act);
  1752.  
  1753.     return;
  1754. }
  1755.  
  1756.  
  1757. /****************************************************************************/
  1758. /*                               PRINT_EXTERNS:                             */
  1759. /****************************************************************************/
  1760. static void print_externs(void)
  1761. {
  1762.     if (c_bit || cpp_bit)
  1763.     {
  1764.         fprintf(sysprs,
  1765.                 "%s SCOPE_REPAIR\n"
  1766.                 "%s DEFERRED_RECOVERY\n"
  1767.                 "%s FULL_DIAGNOSIS\n"
  1768.                 "%s SPACE_TABLES\n\n",
  1769.  
  1770.                 (num_scopes > 0              ? "#define" : "#undef "),
  1771.                 (deferred_bit                ? "#define" : "#undef "),
  1772.                 (error_maps_bit              ? "#define" : "#undef "),
  1773.                 (table_opt == OPTIMIZE_SPACE ? "#define" : "#undef "));
  1774.     }
  1775.  
  1776.     if (c_bit)
  1777.         fprintf(sysprs,
  1778.             "#define original_state(state) (-%s[state])\n"
  1779.             "#define asi(state)            asb[original_state(state)]\n"
  1780.             "#define nasi(state)           nasb[original_state(state)]\n"
  1781.             "#define in_symbol(state)      in_symb[original_state(state)]\n\n",
  1782.             (table_opt == OPTIMIZE_TIME  ? "check" : "base_check"));
  1783.     else if (cpp_bit)
  1784.     {
  1785.         fprintf(sysprs,
  1786.                 "class LexStream;\n\n"
  1787.                 "class %s_table\n"
  1788.                 "{\n"
  1789.                 "public:\n",
  1790.  
  1791.                 prs_tag);
  1792.  
  1793.         if (error_maps_bit || debug_bit)
  1794.             fprintf(sysprs,
  1795.                     "    static int original_state(int state) "
  1796.                     "{ return -%s[state]; }\n",
  1797.  
  1798.                     (table_opt == OPTIMIZE_TIME  ? "check" : "base_check"));
  1799.  
  1800.         if (error_maps_bit)
  1801.         {
  1802.             fprintf(sysprs,
  1803.                     "    static int asi(int state) "
  1804.                     "{ return asb[original_state(state)]; }\n"
  1805.                     "    static int nasi(int state) "
  1806.                     "{ return nasb[original_state(state)]; }\n");
  1807.             if (num_scopes > 0)
  1808.                 fprintf(sysprs,
  1809.                         "    static int in_symbol(int state) "
  1810.                         "{ return in_symb[original_state(state)]; }\n");
  1811.         }
  1812.  
  1813.         fprintf(sysprs, "\n");
  1814.     }
  1815.     else if (java_bit)
  1816.     {
  1817.         fprintf(sysprs,
  1818.                 "abstract class %s extends %s implements %s\n{\n",
  1819.                 prs_tag, dcl_tag, def_tag);
  1820.  
  1821.         if (error_maps_bit || debug_bit)
  1822.         {
  1823.             fprintf(sysprs,
  1824.                     "    public final static int original_state(int state) "
  1825.                     "{ return -%s(state); }\n",
  1826.  
  1827.                     (table_opt == OPTIMIZE_TIME  ? "check" : "base_check"));
  1828.  
  1829.             if (error_maps_bit)
  1830.             {
  1831.                 fprintf(sysprs,
  1832.                         "    public final static int asi(int state) "
  1833.                         "{ return asb[original_state(state)]; }\n"
  1834.                         "    static int nasi(int state) "
  1835.                         "{ return nasb[original_state(state)]; }\n");
  1836.                 if (num_scopes > 0)
  1837.                     fprintf(sysprs,
  1838.                             "    public final static int in_symbol(int state) "
  1839.                             "{ return in_symb[original_state(state)]; }\n");
  1840.             }
  1841.     
  1842.             fprintf(sysprs, "\n");
  1843.         }
  1844.     }
  1845.  
  1846.     if (c_bit || cpp_bit)
  1847.     {
  1848.         fprintf(sysprs, "%s const unsigned char  rhs[];\n",
  1849.                         (c_bit ? "extern" : "    static"));
  1850.  
  1851.         if (check_size > 0 || table_opt == OPTIMIZE_TIME)
  1852.         {
  1853.             BOOLEAN small = byte_check_bit && (! error_maps_bit);
  1854.  
  1855.             fprintf(sysprs, "%s const %s check_table[];\n"
  1856.                             "%s const %s *%s;\n",
  1857.  
  1858.                             (c_bit ? "extern" : "    static"),
  1859.                             (small ? "unsigned char " : "  signed short"),
  1860.                             (c_bit ? "extern" : "    static"),
  1861.                             (small ? "unsigned char " : "  signed short"),
  1862.                             (table_opt == OPTIMIZE_TIME
  1863.                                         ? "check" : "base_check"));
  1864.         }
  1865.  
  1866.         fprintf(sysprs, "%s const unsigned short lhs[];\n"
  1867.                         "%s const unsigned short *%s;\n",
  1868.  
  1869.                         (c_bit ? "extern" : "    static"),
  1870.                         (c_bit ? "extern" : "    static"),
  1871.                         (table_opt == OPTIMIZE_TIME
  1872.                                     ? "action" : "base_action"));
  1873.  
  1874.         if (goto_default_bit)
  1875.             fprintf(sysprs, "%s const unsigned short default_goto[];\n",
  1876.                             (c_bit ? "extern" : "    static"));
  1877.  
  1878.         if (table_opt == OPTIMIZE_SPACE)
  1879.         {
  1880.             fprintf(sysprs, "%s const unsigned %s term_check[];\n",
  1881.                             (c_bit ? "extern" : "    static"),
  1882.                             (num_terminals <= (java_bit ? 127 : 255) ? "char " : "short"));
  1883.             fprintf(sysprs, "%s const unsigned short term_action[];\n",
  1884.                             (c_bit ? "extern" : "    static"));
  1885.  
  1886.             if (shift_default_bit)
  1887.             {
  1888.                 fprintf(sysprs, "%s const unsigned short default_reduce[];\n",
  1889.                                 (c_bit ? "extern" : "    static"));
  1890.                 fprintf(sysprs, "%s const unsigned short shift_state[];\n",
  1891.                                 (c_bit ? "extern" : "    static"));
  1892.                 fprintf(sysprs, "%s const unsigned %s shift_check[];\n",
  1893.                                 (c_bit ? "extern" : "    static"),
  1894.                                 (num_terminals <= (java_bit ? 127 : 255) ? "char " : "short"));
  1895.                 fprintf(sysprs, "%s const unsigned short default_shift[];\n",
  1896.                                 (c_bit ? "extern" : "    static"));
  1897.             }
  1898.         }
  1899.  
  1900.         if (error_maps_bit)
  1901.         {
  1902.             fprintf(sysprs,
  1903.                     "\n"
  1904.                     "%s const unsigned short asb[];\n"
  1905.                     "%s const unsigned %s asr[];\n"
  1906.                     "%s const unsigned short nasb[];\n"
  1907.                     "%s const unsigned short nasr[];\n"
  1908.                     "%s const unsigned short name_start[];\n"
  1909.                     "%s const unsigned char  name_length[];\n"
  1910.                     "%s const          char  string_buffer[];\n",
  1911.  
  1912.                     (c_bit ? "extern" : "    static"),
  1913.                     (c_bit ? "extern" : "    static"),
  1914.                     (byte_terminal_range <= (java_bit ? 127 : 255) ? "char " : "short"),
  1915.                     (c_bit ? "extern" : "    static"),
  1916.                     (c_bit ? "extern" : "    static"),
  1917.                     (c_bit ? "extern" : "    static"),
  1918.                     (c_bit ? "extern" : "    static"),
  1919.                     (c_bit ? "extern" : "    static"));
  1920.  
  1921.             if (table_opt == OPTIMIZE_SPACE)
  1922.             {
  1923.                 fprintf(sysprs,
  1924.                         "%s const unsigned %s terminal_index[];\n"
  1925.                         "%s const unsigned %s non_terminal_index[];\n",
  1926.                         (c_bit ? "extern" : "    static"),
  1927.                         (num_names <= (java_bit ? 127 : 255) ? "char " : "short"),
  1928.                         (c_bit ? "extern" : "    static"),
  1929.                         (num_names <= (java_bit ? 127 : 255) ? "char " : "short"));
  1930.             }
  1931.             else
  1932.             {
  1933.                 fprintf(sysprs, "%s const unsigned %s symbol_index[];\n"
  1934.                                 "%s const unsigned %s *terminal_index;\n"
  1935.                                 "%s const unsigned %s *non_terminal_index;\n",
  1936.                                 (c_bit ? "extern" : "    static"),
  1937.                                 (num_names <= (java_bit ? 127 : 255) ? "char " : "short"),
  1938.                                 (c_bit ? "extern" : "    static"),
  1939.                                 (num_names <= (java_bit ? 127 : 255) ? "char " : "short"),
  1940.                                 (c_bit ? "extern" : "    static"),
  1941.                                 (num_names <= (java_bit ? 127 : 255) ? "char " : "short"));
  1942.             }
  1943.  
  1944.             if (num_scopes > 0)
  1945.             {
  1946.                 fprintf(sysprs, "%s const unsigned %s scope_prefix[];\n"
  1947.                                 "%s const unsigned %s scope_suffix[];\n"
  1948.                                 "%s const unsigned %s scope_lhs[];\n"
  1949.                                 "%s const unsigned %s scope_la[];\n"
  1950.                                 "%s const unsigned %s scope_state_set[];\n"
  1951.                                 "%s const unsigned %s scope_rhs[];\n"
  1952.                                 "%s const unsigned short scope_state[];\n"
  1953.                                 "%s const unsigned %s in_symb[];\n",
  1954.  
  1955.                                 (c_bit ? "extern" : "    static"),
  1956.                                 (scope_rhs_size    <= (java_bit ? 127 : 255) ? "char " : "short"),
  1957.                                 (c_bit ? "extern" : "    static"),
  1958.                                 (scope_rhs_size    <= (java_bit ? 127 : 255) ? "char " : "short"),
  1959.                                 (c_bit ? "extern" : "    static"),
  1960.                                 (num_symbols       <= (java_bit ? 127 : 255) ? "char " : "short"),
  1961.                                 (c_bit ? "extern" : "    static"),
  1962.                                 (num_terminals     <= (java_bit ? 127 : 255) ? "char " : "short"),
  1963.                                 (c_bit ? "extern" : "    static"),
  1964.                                 (scope_state_size  <= (java_bit ? 127 : 255) ? "char " : "short"),
  1965.                                 (c_bit ? "extern" : "    static"),
  1966.                                 (num_symbols       <= (java_bit ? 127 : 255) ? "char " : "short"),
  1967.                                 (c_bit ? "extern" : "    static"),
  1968.                                 (c_bit ? "extern" : "    static"),
  1969.                                 (num_symbols       <= (java_bit ? 127 : 255) ? "char " : "short"));
  1970.             }
  1971.         }
  1972.  
  1973.         fprintf(sysprs, "\n");
  1974.     }
  1975.  
  1976.     if (table_opt == OPTIMIZE_SPACE)
  1977.     {
  1978.         if (goto_default_bit)
  1979.             non_terminal_space_action();
  1980.         else
  1981.             non_terminal_no_goto_default_space_action();
  1982.  
  1983.         if (lalr_level > 1)
  1984.         {
  1985.             if (shift_default_bit)
  1986.                 terminal_shift_default_space_lalr_k();
  1987.             else
  1988.                 terminal_space_lalr_k();
  1989.         }
  1990.         else
  1991.         {
  1992.             if (shift_default_bit)
  1993.                 terminal_shift_default_space_action();
  1994.             else
  1995.                 terminal_space_action();
  1996.         }
  1997.     }
  1998.     else
  1999.     {
  2000.         if (goto_default_bit)
  2001.             non_terminal_time_action();
  2002.         else
  2003.             non_terminal_no_goto_default_time_action();
  2004.  
  2005.         if (lalr_level > 1)
  2006.             terminal_time_lalr_k();
  2007.         else
  2008.             terminal_time_action();
  2009.     }
  2010.  
  2011.     if (cpp_bit)
  2012.         fprintf(sysprs, "};\n");
  2013.     else if (java_bit)
  2014.         fprintf(sysprs, "}\n");
  2015.  
  2016.     return;
  2017. }
  2018.  
  2019.  
  2020. /**************************************************************************/
  2021. /*                           PRINT_SPACE_TABLES:                          */
  2022. /**************************************************************************/
  2023. static void print_space_tables(void)
  2024. {
  2025.     int *check,
  2026.         *action;
  2027.  
  2028.     int la_state_offset,
  2029.         i,
  2030.         j,
  2031.         k,
  2032.         indx,
  2033.         act,
  2034.         result_act,
  2035.         default_count = 0,
  2036.         goto_count = 0,
  2037.         goto_reduce_count = 0,
  2038.         reduce_count = 0,
  2039.         la_shift_count = 0,
  2040.         shift_count = 0,
  2041.         shift_reduce_count = 0;
  2042.  
  2043.     int rule_no,
  2044.         symbol,
  2045.         state_no;
  2046.  
  2047.     long offset;
  2048.  
  2049.     check = Allocate_int_array(table_size + 1);
  2050.     action = Allocate_int_array(table_size + 1);
  2051.  
  2052.     output_ptr = &output_buffer[0];
  2053.  
  2054.     /******************************************************************/
  2055.     /* Prepare header card with proper information, and write it out. */
  2056.     /******************************************************************/
  2057.     offset = error_act;
  2058.  
  2059.     if (lalr_level > 1)
  2060.     {
  2061.         if (read_reduce_bit)
  2062.             offset += num_rules;
  2063.         la_state_offset = offset;
  2064.     }
  2065.     else
  2066.         la_state_offset = error_act;
  2067.  
  2068.     if (offset > (MAX_TABLE_SIZE + 1))
  2069.     {
  2070.         sprintf(msg_line, "Table contains entries that are > "
  2071.                 "%d; Processing stopped.", MAX_TABLE_SIZE + 1);
  2072.         PRNTERR(msg_line);
  2073.         exit(12);
  2074.     }
  2075.  
  2076.     for (i = 1; i <= check_size; i++)
  2077.          check[i] = DEFAULT_SYMBOL;
  2078.  
  2079.     for (i = 1; i <= (int) action_size; i++)
  2080.          action[i] = error_act;
  2081.  
  2082.     /********************************************************************/
  2083.     /*    Update the default non-terminal action of each state with the */
  2084.     /* appropriate corresponding terminal state starting index.         */
  2085.     /********************************************************************/
  2086.     for (i = 1; i <= num_terminal_states; i++)
  2087.     {
  2088.         indx = term_state_index[i];
  2089.         state_no = new_state_element[i].image;
  2090.  
  2091.     /*********************************************************************/
  2092.     /*   Update the action link between the non-terminal and terminal    */
  2093.     /* tables.  If error-maps are requested, an indirect linking is made */
  2094.     /* as follows:                                                       */
  2095.     /*  Each non-terminal row identifies its original state number, and  */
  2096.     /* a new vector START_TERMINAL_STATE indexable by state numbers      */
  2097.     /* identifies the starting point of each state in the terminal table.*/
  2098.     /*********************************************************************/
  2099.         if (state_no <= (int) num_states)
  2100.         {
  2101.             for (; state_no != NIL; state_no = state_list[state_no])
  2102.                 action[state_index[state_no]] = indx;
  2103.         }
  2104.         else
  2105.         {
  2106.             for (; state_no != NIL; state_no = state_list[state_no])
  2107.             {
  2108.                 act = la_state_offset + indx;
  2109.                 state_index[state_no] = act;
  2110.             }
  2111.         }
  2112.     }
  2113.  
  2114.     /*********************************************************************/
  2115.     /*  Now update the non-terminal tables with the non-terminal actions.*/
  2116.     /*********************************************************************/
  2117.     for ALL_STATES(state_no)
  2118.     {
  2119.         struct goto_header_type go_to;
  2120.  
  2121.         indx = state_index[state_no];
  2122.         go_to = statset[state_no].go_to;
  2123.         for (j = 1; j <= go_to.size; j++)
  2124.         {
  2125.             symbol = GOTO_SYMBOL(go_to, j);
  2126.             i = indx + symbol;
  2127.             if (goto_default_bit || nt_check_bit)
  2128.                 check[i] = symbol;
  2129.             act = GOTO_ACTION(go_to, j);
  2130.             if (act > 0)
  2131.             {
  2132.                 action[i] = state_index[act] + num_rules;
  2133.                 goto_count++;
  2134.             }
  2135.             else
  2136.             {
  2137.                 action[i] = -act;
  2138.                 goto_reduce_count++;
  2139.             }
  2140.         }
  2141.     }
  2142.  
  2143.     if (error_maps_bit || debug_bit)
  2144.     {
  2145.         if (check_size == 0)
  2146.         {
  2147.             check_size = action_size;
  2148.             for (i = 0; i <= check_size; i++)
  2149.                 check[i] = 0;
  2150.         }
  2151.  
  2152.         for ALL_STATES(state_no)
  2153.             check[state_index[state_no]] = -state_no;
  2154.     }
  2155.     for (i = 1; i <= check_size; i++)
  2156.     {
  2157.         if (check[i] < 0 || check[i] > (java_bit ? 127 : 255))
  2158.              byte_check_bit = 0;
  2159.     }
  2160.  
  2161.     if (c_bit)
  2162.         mystrcpy("\n#define CLASS_HEADER\n\n");
  2163.     else if (cpp_bit)
  2164.     {
  2165.         mystrcpy("\n#define CLASS_HEADER ");
  2166.         mystrcpy(prs_tag);
  2167.         mystrcpy("_table::\n\n");
  2168.     }
  2169.     else
  2170.     {
  2171.         mystrcpy("abstract class ");
  2172.         mystrcpy(dcl_tag);
  2173.         mystrcpy(" implements ");
  2174.         mystrcpy(def_tag);
  2175.         mystrcpy("\n{\n");
  2176.     }
  2177.  
  2178.     /*********************************************************************/
  2179.     /* Write size of right hand side of rules followed by CHECK table.   */
  2180.     /*********************************************************************/
  2181.     if (java_bit)
  2182.          mystrcpy("    public final static byte rhs[] = {0,\n");
  2183.     else mystrcpy("const unsigned char  CLASS_HEADER rhs[] = {0,\n");
  2184.  
  2185.     padline();
  2186.     k = 0;
  2187.     for (i = 1; i <= num_rules; i++)
  2188.     {
  2189.         k++;
  2190.         if (k > 15)
  2191.         {
  2192.             *output_ptr++ = '\n';
  2193.             BUFFER_CHECK(sysdcl);
  2194.             padline();
  2195.             k = 1;
  2196.         }
  2197.         itoc(RHS_SIZE(i));
  2198.         *output_ptr++ = COMMA;
  2199.     }
  2200.     *(output_ptr - 1) = '\n';
  2201.     BUFFER_CHECK(sysdcl);
  2202.  
  2203.     if (java_bit)
  2204.          mystrcpy("    };\n");
  2205.     else mystrcpy("                 };\n");
  2206.  
  2207.     *output_ptr++ = '\n';
  2208.  
  2209.     if (check_size > 0)
  2210.     {
  2211.         if (byte_check_bit && ! error_maps_bit)
  2212.         {
  2213.             if (java_bit)
  2214.                  mystrcpy("    public final static byte check_table[] = {\n");
  2215.             else mystrcpy("const unsigned char  CLASS_HEADER check_table[] = {\n");
  2216.         }
  2217.         else
  2218.         {
  2219.             if (java_bit)
  2220.                  mystrcpy("    public final static short check_table[] = {\n");
  2221.             else mystrcpy("const   signed short CLASS_HEADER check_table[] = {\n");
  2222.         }
  2223.  
  2224.         padline();
  2225.         k = 0;
  2226.         for (i = 1; i <= check_size; i++)
  2227.         {
  2228.             k++;
  2229.             if (k > 10)
  2230.             {
  2231.                 *output_ptr++ = '\n';
  2232.                 BUFFER_CHECK(sysdcl);
  2233.                 padline();
  2234.                 k = 1;
  2235.             }
  2236.             itoc(check[i]);
  2237.             *output_ptr++ = COMMA;
  2238.         }
  2239.         *(output_ptr - 1) = '\n';
  2240.         BUFFER_CHECK(sysdcl);
  2241.  
  2242.         if (java_bit)
  2243.              mystrcpy("    };\n");
  2244.         else mystrcpy("                 };\n");
  2245.         *output_ptr++ = '\n';
  2246.  
  2247.         if (byte_check_bit && (! error_maps_bit))
  2248.         {
  2249.             if (java_bit)
  2250.                  mystrcpy("    public final static byte base_check(int i)"
  2251.                           "\n    {\n        return check_table[i - (NUM_RULES + 1)];\n    }\n");
  2252.             else mystrcpy("const unsigned char  *CLASS_HEADER base_check = "
  2253.                           "&(check_table[0]) - (NUM_RULES + 1);\n");
  2254.         }
  2255.         else
  2256.         {
  2257.             if (java_bit)
  2258.                  mystrcpy("    public final static short base_check(int i) "
  2259.                           "\n    {\n        return check_table[i - (NUM_RULES + 1)];\n    }\n");
  2260.             else mystrcpy("const   signed short *CLASS_HEADER base_check = "
  2261.                           "&(check_table[0]) - (NUM_RULES + 1);\n");
  2262.         }
  2263.         *output_ptr++ = '\n';
  2264.     }
  2265.  
  2266.     /*********************************************************************/
  2267.     /* Write left hand side symbol of rules followed by ACTION table.    */
  2268.     /*********************************************************************/
  2269.     if (java_bit)
  2270.          mystrcpy("    public final static char lhs[] = {0,\n");
  2271.     else mystrcpy("const unsigned short CLASS_HEADER lhs[] = {0,\n");
  2272.  
  2273.     padline();
  2274.     k = 0;
  2275.     for (i = 1; i <= num_rules; i++)
  2276.     {
  2277.         itoc(symbol_map[rules[i].lhs] - num_terminals);
  2278.         *output_ptr++ = COMMA;
  2279.         k++;
  2280.         if (k == 15)
  2281.         {
  2282.             *output_ptr++ = '\n';
  2283.             BUFFER_CHECK(sysdcl);
  2284.             padline();
  2285.             k = 0;
  2286.         }
  2287.     }
  2288.  
  2289.     *output_ptr++ = '\n';
  2290.     *output_ptr++ = '\n';
  2291.     BUFFER_CHECK(sysdcl);
  2292.     padline();
  2293.     k = 0;
  2294.  
  2295.     if (error_maps_bit)
  2296.     {
  2297.         int max_indx;
  2298.  
  2299.         max_indx = accept_act - num_rules - 1;
  2300.         for (i = 1; i <= max_indx; i++)
  2301.             check[i] = OMEGA;
  2302.         for ALL_STATES(state_no)
  2303.             check[state_index[state_no]] = state_no;
  2304.  
  2305.         j = num_states + 1;
  2306.         for (i = max_indx; i >= 1; i--)
  2307.         {
  2308.             state_no = check[i];
  2309.             if (state_no != OMEGA)
  2310.             {
  2311.                 j--;
  2312.                 ordered_state[j] = i + num_rules;
  2313.                 state_list[j] = state_no;
  2314.             }
  2315.         }
  2316.     }
  2317.  
  2318.     for (i = 1; i <= (int) action_size; i++)
  2319.     {
  2320.         itoc(action[i]);
  2321.         *output_ptr++ = COMMA;
  2322.         k++;
  2323.         if (k == 10 && i != (int) action_size)
  2324.         {
  2325.             *output_ptr++ = '\n';
  2326.             BUFFER_CHECK(sysdcl);
  2327.             padline();
  2328.             k = 0;
  2329.         }
  2330.     }
  2331.  
  2332.     if (k != 0)
  2333.     {
  2334.         *(output_ptr - 1) = '\n';
  2335.         BUFFER_CHECK(sysdcl);
  2336.     }
  2337.     if (java_bit)
  2338.          mystrcpy("    };\n");
  2339.     else mystrcpy("                 };\n");
  2340.     *output_ptr++ = '\n';
  2341.     BUFFER_CHECK(sysdcl);
  2342.  
  2343.     if (java_bit)
  2344.          mystrcpy("    public final static char base_action[] = lhs;\n");
  2345.     else mystrcpy("const unsigned short *CLASS_HEADER base_action = lhs;\n");
  2346.     *output_ptr++ = '\n';
  2347.  
  2348.     /********************************************************************/
  2349.     /* Initialize the terminal tables,and update with terminal actions. */
  2350.     /********************************************************************/
  2351.     for (i = 1; i <= term_check_size; i++)
  2352.         check[i] = DEFAULT_SYMBOL;
  2353.  
  2354.     for (i = 1; i <= term_action_size; i++)
  2355.        action[i] = error_act;
  2356.  
  2357.     for (state_no = 1; state_no <= num_terminal_states; state_no++)
  2358.     {
  2359.         struct shift_header_type  sh;
  2360.         struct reduce_header_type red;
  2361.  
  2362.         indx = term_state_index[state_no];
  2363.         sh = shift[new_state_element[state_no].shift_number];
  2364.         for (j = 1; j <= sh.size; j++)
  2365.         {
  2366.             symbol = SHIFT_SYMBOL(sh, j);
  2367.             act = SHIFT_ACTION(sh, j);
  2368.             if ((! shift_default_bit) || (act != shiftdf[symbol]))
  2369.             {
  2370.                 i = indx + symbol;
  2371.                 check[i] = symbol;
  2372.  
  2373.                 if (act > (int) num_states)
  2374.                 {
  2375.                     result_act = state_index[act];
  2376.                     la_shift_count++;
  2377.                 }
  2378.                 else if (act > 0)
  2379.                 {
  2380.                     result_act = state_index[act] + num_rules;
  2381.                     shift_count++;
  2382.                 }
  2383.                 else
  2384.                 {
  2385.                     result_act = -act + error_act;
  2386.                     shift_reduce_count++;
  2387.                 }
  2388.  
  2389.                 if (result_act > (MAX_TABLE_SIZE + 1))
  2390.                 {
  2391.                     sprintf(msg_line,
  2392.                         "Table contains look-ahead shift entry that is >"
  2393.                         " %d; Processing stopped.", MAX_TABLE_SIZE + 1);
  2394.                     PRNTERR(msg_line);
  2395.                     return;
  2396.                 }
  2397.  
  2398.                 action[i] = result_act;
  2399.             }
  2400.         }
  2401.  
  2402.         red = new_state_element[state_no].reduce;
  2403.         for (j = 1; j <= red.size; j++)
  2404.         {
  2405.             symbol = REDUCE_SYMBOL(red, j);
  2406.             rule_no = REDUCE_RULE_NO(red, j);
  2407.             i = indx + symbol;
  2408.             check[i] = symbol;
  2409.             action[i] = rule_no;
  2410.             reduce_count++;
  2411.         }
  2412.  
  2413.         rule_no = REDUCE_RULE_NO(red, 0);
  2414.         if (rule_no != error_act)
  2415.             default_count++;
  2416.         check[indx] = DEFAULT_SYMBOL;
  2417.         if (shift_default_bit)
  2418.             action[indx] = state_no;
  2419.         else
  2420.             action[indx] = rule_no;
  2421.     }
  2422.  
  2423.     PRNT("\n\nActions in Compressed Tables:");
  2424.     sprintf(msg_line,"     Number of Shifts: %d",shift_count);
  2425.     PRNT(msg_line);
  2426.  
  2427.     sprintf(msg_line,"     Number of Shift/Reduces: %d",shift_reduce_count);
  2428.     PRNT(msg_line);
  2429.  
  2430.     if (max_la_state > num_states)
  2431.     {
  2432.         sprintf(msg_line,
  2433.                 "     Number of Look-Ahead Shifts: %d",
  2434.                 la_shift_count);
  2435.         PRNT(msg_line);
  2436.     }
  2437.  
  2438.     sprintf(msg_line,"     Number of Gotos: %d",goto_count);
  2439.     PRNT(msg_line);
  2440.  
  2441.     sprintf(msg_line,"     Number of Goto/Reduces: %d",goto_reduce_count);
  2442.     PRNT(msg_line);
  2443.  
  2444.     sprintf(msg_line,"     Number of Reduces: %d",reduce_count);
  2445.     PRNT(msg_line);
  2446.  
  2447.     sprintf(msg_line,"     Number of Defaults: %d",default_count);
  2448.     PRNT(msg_line);
  2449.  
  2450.     /********************************************************************/
  2451.     /* Write Terminal Check Table.                                      */
  2452.     /********************************************************************/
  2453.     if (num_terminals <= (java_bit ? 127 : 255))
  2454.     {
  2455.         if (java_bit)
  2456.              prnt_ints("\n    public final static byte term_check[] = {0,\n",
  2457.                        1, term_check_size, 15, check);
  2458.         else prnt_ints("\nconst unsigned char  CLASS_HEADER term_check[] = {0,\n",
  2459.                        1, term_check_size, 15, check);
  2460.     }
  2461.     else
  2462.     {
  2463.         if (java_bit)
  2464.              prnt_ints("\n    public final static char term_check[] = {0,\n",
  2465.                        1, term_check_size, 15, check);
  2466.         else prnt_ints("\nconst unsigned short CLASS_HEADER term_check[] = {0,\n",
  2467.                        1, term_check_size, 15, check);
  2468.     }
  2469.  
  2470.     /********************************************************************/
  2471.     /* Write Terminal Action Table.                                      */
  2472.     /********************************************************************/
  2473.     if (java_bit)
  2474.          prnt_ints("\n    public final static char term_action[] = {0,\n",
  2475.                    1, term_action_size, 10, action);
  2476.     else prnt_ints("\nconst unsigned short CLASS_HEADER term_action[] = {0,\n",
  2477.                    1, term_action_size, 10, action);
  2478.  
  2479.     /********************************************************************/
  2480.     /* If GOTO_DEFAULT is requested, we print out the GOTODEF vector.   */
  2481.     /********************************************************************/
  2482.     if (goto_default_bit)
  2483.     {
  2484.         if (java_bit)
  2485.              mystrcpy("\n    public final static char default_goto[] = {0,\n");
  2486.         else mystrcpy("\nconst unsigned short CLASS_HEADER default_goto[] = {0,\n");
  2487.  
  2488.         padline();
  2489.         k = 0;
  2490.         for ALL_NON_TERMINALS(symbol)
  2491.         {
  2492.            act = gotodef[symbol];
  2493.  
  2494.            if (act < 0)
  2495.                result_act = -act;
  2496.            else if (act == 0)
  2497.                result_act = error_act;
  2498.            else
  2499.                result_act = state_index[act] + num_rules;
  2500.  
  2501.            itoc(result_act);
  2502.            *output_ptr++ = COMMA;
  2503.            k++;
  2504.            if (k == 10 && symbol != num_symbols)
  2505.            {
  2506.                *output_ptr++ = '\n';
  2507.                BUFFER_CHECK(sysdcl);
  2508.                padline();
  2509.                k = 0;
  2510.            }
  2511.        }
  2512.  
  2513.        if (k != 0)
  2514.        {
  2515.            *(output_ptr - 1) = '\n';
  2516.            BUFFER_CHECK(sysdcl);
  2517.        }
  2518.        if (java_bit)
  2519.             mystrcpy("    };\n");
  2520.        else mystrcpy("                 };\n");
  2521.     }
  2522.  
  2523.     if (shift_default_bit)
  2524.     {
  2525.         if (java_bit)
  2526.              mystrcpy("\n    public final static char default_reduce[] = {0,\n");
  2527.         else mystrcpy("\nconst unsigned short CLASS_HEADER default_reduce[] = {0,\n");
  2528.  
  2529.         padline();
  2530.         k = 0;
  2531.         for (i = 1; i <= num_terminal_states; i++)
  2532.         {
  2533.             struct reduce_header_type red;
  2534.  
  2535.             red = new_state_element[i].reduce;
  2536.             itoc(REDUCE_RULE_NO(red, 0));
  2537.             *output_ptr++ = COMMA;
  2538.             k++;
  2539.             if (k == 10 && i != num_terminal_states)
  2540.             {
  2541.                 *output_ptr++ = '\n';
  2542.                 BUFFER_CHECK(sysdcl);
  2543.                 padline();
  2544.                 k = 0;
  2545.             }
  2546.         }
  2547.  
  2548.         if (k != 0)
  2549.         {
  2550.             *(output_ptr - 1) = '\n';
  2551.             BUFFER_CHECK(sysdcl);
  2552.         }
  2553.         if (java_bit)
  2554.              mystrcpy("    };\n");
  2555.         else mystrcpy("                 };\n");
  2556.  
  2557.         if (java_bit)
  2558.              mystrcpy("\n    public final static char shift_state[] = {0,\n");
  2559.         else mystrcpy("\nconst unsigned short CLASS_HEADER shift_state[] = {0,\n");
  2560.  
  2561.         padline();
  2562.         k = 0;
  2563.         for (i = 1; i <= num_terminal_states; i++)
  2564.         {
  2565.             itoc(shift_check_index[shift_image[i]]);
  2566.             *output_ptr++ = COMMA;
  2567.             k++;
  2568.             if (k == 10 && i != num_terminal_states)
  2569.             {
  2570.                 *output_ptr++ = '\n';
  2571.                 BUFFER_CHECK(sysdcl);
  2572.                 padline();
  2573.                 k = 0;
  2574.             }
  2575.         }
  2576.  
  2577.         if (k != 0)
  2578.         {
  2579.             *(output_ptr - 1) = '\n';
  2580.             BUFFER_CHECK(sysdcl);
  2581.         }
  2582.         if (java_bit)
  2583.              mystrcpy("    };\n");
  2584.         else mystrcpy("                 };\n");
  2585.  
  2586.         for (i = 1; i <= shift_check_size; i++)
  2587.             check[i] = DEFAULT_SYMBOL;
  2588.  
  2589.         for (i = 1; i <= shift_domain_count; i++)
  2590.         {
  2591.             struct shift_header_type sh;
  2592.  
  2593.             indx = shift_check_index[i];
  2594.             sh = shift[real_shift_number[i]];
  2595.             for (j = 1; j <= sh.size; j++)
  2596.             {
  2597.                 symbol = SHIFT_SYMBOL(sh, j);
  2598.                 check[indx + symbol] = symbol;
  2599.             }
  2600.         }
  2601.  
  2602.         if (num_terminals <= (java_bit ? 127 : 255))
  2603.         {
  2604.             if (java_bit)
  2605.                  mystrcpy("\n    public final static byte shift_check[] = {0,\n");
  2606.             else mystrcpy("\nconst unsigned char  CLASS_HEADER shift_check[] = {0,\n");
  2607.         }
  2608.         else
  2609.         {
  2610.             if (java_bit)
  2611.                  mystrcpy("\n    public final static char shift_check[] = {0,\n");
  2612.             else mystrcpy("\nconst unsigned short CLASS_HEADER shift_check[] = {0,\n");
  2613.         }
  2614.  
  2615.         padline();
  2616.         k = 0;
  2617.         for (i = 1; i <= shift_check_size; i++)
  2618.         {
  2619.             itoc(check[i]);
  2620.             *output_ptr++ = COMMA;
  2621.             k++;
  2622.             if (k == 10 && i != shift_check_size)
  2623.             {
  2624.                 *output_ptr++ = '\n';
  2625.                 BUFFER_CHECK(sysdcl);
  2626.                 padline();
  2627.                 k = 0;
  2628.             }
  2629.         }
  2630.  
  2631.         if (k != 0)
  2632.         {
  2633.             *(output_ptr - 1) = '\n';
  2634.             BUFFER_CHECK(sysdcl);
  2635.         }
  2636.         if (java_bit)
  2637.              mystrcpy("    };\n");
  2638.         else mystrcpy("                 };\n");
  2639.  
  2640.         if (java_bit)
  2641.              mystrcpy("\n    public final static char default_shift[] = {0,\n");
  2642.         else mystrcpy("\nconst unsigned short CLASS_HEADER default_shift[] = {0,\n");
  2643.  
  2644.         padline();
  2645.         k = 0;
  2646.         for ALL_TERMINALS(symbol)
  2647.         {
  2648.             act = shiftdf[symbol];
  2649.             if (act < 0)
  2650.                 result_act = -act + error_act;
  2651.             else if (act == 0)
  2652.                 result_act = error_act;
  2653.             else if (act > (int) num_states)
  2654.                 result_act = state_index[act];
  2655.             else
  2656.                 result_act = state_index[act] + num_rules;
  2657.  
  2658.             if (result_act > (MAX_TABLE_SIZE + 1))
  2659.             {
  2660.                 sprintf(msg_line,
  2661.                     "Table contains look-ahead shift entry that is >"
  2662.                     " %d; Processing stopped.", MAX_TABLE_SIZE + 1);
  2663.                 PRNTERR(msg_line);
  2664.                 return;
  2665.             }
  2666.  
  2667.             itoc(result_act);
  2668.             *output_ptr++ = COMMA;
  2669.             k++;
  2670.             if (k == 10 && i != num_terminals)
  2671.             {
  2672.                 *output_ptr++ = '\n';
  2673.                 BUFFER_CHECK(sysdcl);
  2674.                 padline();
  2675.                 k = 0;
  2676.             }
  2677.         }
  2678.  
  2679.         if (k != 0)
  2680.         {
  2681.             *(output_ptr - 1) = '\n';
  2682.             BUFFER_CHECK(sysdcl);
  2683.         }
  2684.         if (java_bit)
  2685.              mystrcpy("    };\n");
  2686.         else mystrcpy("                 };\n");
  2687.     }
  2688.  
  2689.     ffree(check);
  2690.     ffree(action);
  2691.  
  2692.     if (error_maps_bit)
  2693.         print_error_maps();
  2694.  
  2695.     if (! byte_check_bit)
  2696.     {
  2697.         if (java_bit)
  2698.         {
  2699.             PRNT("\n***Warning: Base Check vector contains value "
  2700.                  "> 127. 16-bit words used.");
  2701.         }
  2702.         else
  2703.         {
  2704.             PRNT("\n***Warning: Base Check vector contains value "
  2705.                  "> 255. 16-bit words used.");
  2706.         }
  2707.     }
  2708.  
  2709.     if (! byte_terminal_range)
  2710.     {
  2711.         if (java_bit)
  2712.         {
  2713.             PRNT("***Warning: Terminal symbol > 127. 16-bit words used.");
  2714.         }
  2715.         else
  2716.         {
  2717.             PRNT("***Warning: Terminal symbol > 255. 16-bit words used.");
  2718.         }
  2719.     }
  2720.  
  2721.     if (java_bit)
  2722.         mystrcpy("}\n");
  2723.  
  2724.     fwrite(output_buffer, sizeof(char),
  2725.            output_ptr - &output_buffer[0], sysdcl);
  2726.  
  2727.     return;
  2728. }
  2729.  
  2730.  
  2731. /**************************************************************************/
  2732. /*                         PRINT_TIME_TABLES:                             */
  2733. /**************************************************************************/
  2734. static void print_time_tables(void)
  2735. {
  2736.     int *action,
  2737.         *check;
  2738.  
  2739.     int la_shift_count = 0,
  2740.         shift_count = 0,
  2741.         goto_count = 0,
  2742.         default_count = 0,
  2743.         reduce_count = 0,
  2744.         shift_reduce_count = 0,
  2745.         goto_reduce_count = 0;
  2746.  
  2747.     int indx,
  2748.         la_state_offset,
  2749.         act,
  2750.         result_act,
  2751.         i,
  2752.         j,
  2753.         k,
  2754.         symbol,
  2755.         state_no;
  2756.  
  2757.     short default_rule;
  2758.  
  2759.     long offset;
  2760.  
  2761.     state_list = Allocate_short_array(max_la_state + 1);
  2762.  
  2763.     output_ptr = &output_buffer[0];
  2764.  
  2765.     check  = next;
  2766.     action = previous;
  2767.  
  2768.     offset = error_act;
  2769.  
  2770.     if (lalr_level > 1)
  2771.     {
  2772.         if (read_reduce_bit)
  2773.             offset += num_rules;
  2774.         la_state_offset = offset;
  2775.     }
  2776.     else
  2777.         la_state_offset = error_act;
  2778.  
  2779.     if (offset > (MAX_TABLE_SIZE + 1))
  2780.     {
  2781.         sprintf(msg_line, "Table contains entries that are > "
  2782.                 "%d; Processing stopped.", MAX_TABLE_SIZE + 1);
  2783.         PRNTERR(msg_line);
  2784.         exit(12);
  2785.     }
  2786.  
  2787. /*********************************************************************/
  2788. /* Initialize all unfilled slots with default values.                */
  2789. /* RECALL that the vector "check" is aliased to the vector "next".   */
  2790. /*********************************************************************/
  2791.     indx = first_index;
  2792.     for (i = indx; (i != NIL) && (i <= (int) action_size); i = indx)
  2793.     {
  2794.         indx = next[i];
  2795.  
  2796.         check[i]  = DEFAULT_SYMBOL;
  2797.         action[i] = error_act;
  2798.     }
  2799.     for (i = (int) action_size + 1; i <= (int) table_size; i++)
  2800.         check[i] = DEFAULT_SYMBOL;
  2801.  
  2802. /*********************************************************************/
  2803. /* We set the rest of the table with the proper table entries.       */
  2804. /*********************************************************************/
  2805.     for (state_no = 1; state_no <= (int) max_la_state; state_no++)
  2806.     {
  2807.         struct goto_header_type   go_to;
  2808.         struct shift_header_type  sh;
  2809.         struct reduce_header_type red;
  2810.  
  2811.         indx = state_index[state_no];
  2812.         if (state_no > (int) num_states)
  2813.         {
  2814.             sh  = shift[lastats[state_no].shift_number];
  2815.             red = lastats[state_no].reduce;
  2816.         }
  2817.         else
  2818.         {
  2819.             go_to = statset[state_no].go_to;
  2820.             for (j = 1; j <= go_to.size; j++)
  2821.             {
  2822.                 symbol = GOTO_SYMBOL(go_to, j);
  2823.                 i = indx + symbol;
  2824.                 if (goto_default_bit || nt_check_bit)
  2825.                     check[i] = symbol;
  2826.                 else
  2827.                     check[i] = DEFAULT_SYMBOL;
  2828.                 act = GOTO_ACTION(go_to, j);
  2829.                 if (act > 0)
  2830.                 {
  2831.                     action[i] = state_index[act] + num_rules;
  2832.                     goto_count++;
  2833.                 }
  2834.                 else
  2835.                 {
  2836.                     action[i] = -act;
  2837.                     goto_reduce_count++;
  2838.                 }
  2839.             }
  2840.             sh = shift[statset[state_no].shift_number];
  2841.             red = reduce[state_no];
  2842.         }
  2843.  
  2844.         for (j = 1; j <= sh.size; j++)
  2845.         {
  2846.             symbol = SHIFT_SYMBOL(sh, j);
  2847.             i = indx + symbol;
  2848.             check[i] = symbol;
  2849.             act = SHIFT_ACTION(sh, j);
  2850.             if (act > (int) num_states)
  2851.             {
  2852.                 result_act = la_state_offset + state_index[act];
  2853.                 la_shift_count++;
  2854.             }
  2855.             else if (act > 0)
  2856.             {
  2857.                 result_act = state_index[act] + num_rules;
  2858.                 shift_count++;
  2859.             }
  2860.             else
  2861.             {
  2862.                 result_act = -act + error_act;
  2863.                 shift_reduce_count++;
  2864.             }
  2865.  
  2866.             if (result_act > (MAX_TABLE_SIZE + 1))
  2867.             {
  2868.                 sprintf(msg_line,
  2869.                     "Table contains look-ahead shift entry that is >"
  2870.                     " %d; Processing stopped.", MAX_TABLE_SIZE + 1);
  2871.                 PRNTERR(msg_line);
  2872.                 return;
  2873.             }
  2874.  
  2875.             action[i] = result_act;
  2876.         }
  2877.  
  2878. /*********************************************************************/
  2879. /*   We now initialize the elements reserved for reduce actions in   */
  2880. /* the current state.                                                */
  2881. /*********************************************************************/
  2882.         default_rule = REDUCE_RULE_NO(red, 0);
  2883.         for (j = 1; j <= red.size; j++)
  2884.         {
  2885.             if (REDUCE_RULE_NO(red, j) != default_rule)
  2886.             {
  2887.                 symbol = REDUCE_SYMBOL(red, j);
  2888.                 i = indx + symbol;
  2889.                 check[i] = symbol;
  2890.                 act = REDUCE_RULE_NO(red, j);
  2891.                 if (rules[act].lhs == accept_image)
  2892.                     action[i] = accept_act;
  2893.                 else
  2894.                     action[i] = act;
  2895.                 reduce_count++;
  2896.             }
  2897.         }
  2898.  
  2899. /*********************************************************************/
  2900. /*   We now initialize the element reserved for the DEFAULT reduce   */
  2901. /* action of the current state.  If error maps are requested,  the   */
  2902. /* default slot is initialized to the original state number, and the */
  2903. /* corresponding element of the DEFAULT_REDUCE array is initialized. */
  2904. /* Otherwise it is initialized to the rule number in question.       */
  2905. /*********************************************************************/
  2906.         i = indx + DEFAULT_SYMBOL;
  2907.         check[i] = DEFAULT_SYMBOL;
  2908.         act = REDUCE_RULE_NO(red, 0);
  2909.         if (act == OMEGA)
  2910.             action[i] = error_act;
  2911.         else
  2912.         {
  2913.             action[i] = act;
  2914.             default_count++;
  2915.         }
  2916.     }
  2917.  
  2918.     PRNT("\n\nActions in Compressed Tables:");
  2919.     sprintf(msg_line, "     Number of Shifts: %d", shift_count);
  2920.     PRNT(msg_line);
  2921.  
  2922.     sprintf(msg_line,
  2923.             "     Number of Shift/Reduces: %d",
  2924.             shift_reduce_count);
  2925.     PRNT(msg_line);
  2926.  
  2927.     if (max_la_state > num_states)
  2928.     {
  2929.         sprintf(msg_line,
  2930.                 "     Number of Look-Ahead Shifts: %d",
  2931.                 la_shift_count);
  2932.         PRNT(msg_line);
  2933.     }
  2934.  
  2935.     sprintf(msg_line, "     Number of Gotos: %d", goto_count);
  2936.     PRNT(msg_line);
  2937.  
  2938.     sprintf(msg_line,
  2939.             "     Number of Goto/Reduces: %d", goto_reduce_count);
  2940.     PRNT(msg_line);
  2941.  
  2942.     sprintf(msg_line, "     Number of Reduces: %d", reduce_count);
  2943.     PRNT(msg_line);
  2944.  
  2945.     sprintf(msg_line, "     Number of Defaults: %d", default_count);
  2946.     PRNT(msg_line);
  2947.  
  2948.     if (error_maps_bit || debug_bit)
  2949.     {
  2950.         for ALL_STATES(state_no)
  2951.             check[state_index[state_no]] = -state_no;
  2952.     }
  2953.     for (i = 1; i <= (int) table_size; i++)
  2954.     {
  2955.         if (check[i] < 0 || check[i] > (java_bit ? 127 : 255))
  2956.             byte_check_bit = 0;
  2957.     }
  2958.  
  2959.     if (c_bit)
  2960.         mystrcpy("\n#define CLASS_HEADER\n\n");
  2961.     else if (cpp_bit)
  2962.     {
  2963.         mystrcpy("\n#define CLASS_HEADER ");
  2964.         mystrcpy(prs_tag);
  2965.         mystrcpy("_table::\n\n");
  2966.     }
  2967.     else if (java_bit)
  2968.     {
  2969.         mystrcpy("abstract class ");
  2970.         mystrcpy(dcl_tag);
  2971.         mystrcpy(" implements ");
  2972.         mystrcpy(def_tag);
  2973.         mystrcpy("\n{\n");
  2974.     }
  2975.  
  2976.     /*********************************************************************/
  2977.     /* Write size of right hand side of rules followed by CHECK table.   */
  2978.     /*********************************************************************/
  2979.     if (java_bit)
  2980.          mystrcpy("    public final static byte rhs[] = {0,\n");
  2981.     else mystrcpy("const unsigned char  CLASS_HEADER rhs[] = {0,\n");
  2982.  
  2983.     padline();
  2984.     k = 0;
  2985.     for (i = 1; i <= num_rules; i++)
  2986.     {
  2987.         k++;
  2988.         if (k > 15)
  2989.         {
  2990.             *output_ptr++ = '\n';
  2991.             BUFFER_CHECK(sysdcl);
  2992.             padline();
  2993.             k = 1;
  2994.         }
  2995.         itoc(RHS_SIZE(i));
  2996.         *output_ptr++ = COMMA;
  2997.     }
  2998.     *(output_ptr - 1) = '\n';
  2999.     BUFFER_CHECK(sysdcl);
  3000.  
  3001.     if (java_bit)
  3002.          mystrcpy("    };\n");
  3003.     else mystrcpy("                 };\n");
  3004.     *output_ptr++ = '\n';
  3005.  
  3006.     /*****************************************************************/
  3007.     /* Write CHECK table.                                            */
  3008.     /*****************************************************************/
  3009.     if (byte_check_bit && (! error_maps_bit))
  3010.     {
  3011.         if (java_bit)
  3012.              mystrcpy("    public final static byte check_table[] = {\n");
  3013.         else mystrcpy("const unsigned char  CLASS_HEADER check_table[] = {\n");
  3014.     }
  3015.     else
  3016.     {
  3017.         if (java_bit)
  3018.              mystrcpy("     public final static short check_table[] = {\n");
  3019.         else mystrcpy("const   signed short CLASS_HEADER check_table[] = {\n");
  3020.     }
  3021.  
  3022.     padline();
  3023.     k = 0;
  3024.     for (i = 1; i <= (int) table_size; i++)
  3025.     {
  3026.         k++;
  3027.         if (k > 10)
  3028.         {
  3029.             *output_ptr++ = '\n';
  3030.             BUFFER_CHECK(sysdcl);
  3031.             padline();
  3032.             k = 1;
  3033.         }
  3034.         itoc(check[i]);
  3035.         *output_ptr++ = COMMA;
  3036.     }
  3037.     *(output_ptr - 1) = '\n';
  3038.     BUFFER_CHECK(sysdcl);
  3039.  
  3040.     if (java_bit)
  3041.          mystrcpy("    };\n");
  3042.     else mystrcpy("                 };\n");
  3043.     *output_ptr++ = '\n';
  3044.     BUFFER_CHECK(sysdcl);
  3045.  
  3046.     if (byte_check_bit && (! error_maps_bit))
  3047.     {
  3048.         if (java_bit)
  3049.              mystrcpy("    public final static byte check(int i) "
  3050.                       "\n    {\n        return check_table[i - (NUM_RULES + 1)];\n    }\n");
  3051.         else mystrcpy("const unsigned char  *CLASS_HEADER check = "
  3052.                       "&(check_table[0]) - (NUM_RULES + 1);\n");
  3053.     }
  3054.     else
  3055.     {
  3056.         if (java_bit)
  3057.              mystrcpy("    public final static short check(int i) "
  3058.                       "\n    {\n        return check_table[i - (NUM_RULES + 1)];\n    }\n");
  3059.         else mystrcpy("const   signed short *CLASS_HEADER check = "
  3060.                       "&(check_table[0]) - (NUM_RULES + 1);\n");
  3061.     }
  3062.     *output_ptr++ = '\n';
  3063.  
  3064.     /*********************************************************************/
  3065.     /* Write left hand side symbol of rules followed by ACTION table.    */
  3066.     /*********************************************************************/
  3067.     if (java_bit)
  3068.          mystrcpy("    public final static char lhs[] = {0,\n");
  3069.     else mystrcpy("const unsigned short CLASS_HEADER lhs[] = {0,\n");
  3070.     padline();
  3071.     k = 0;
  3072.     for (i = 1; i <= num_rules; i++)
  3073.     {
  3074.         itoc(symbol_map[rules[i].lhs]);
  3075.         *output_ptr++ = COMMA;
  3076.         k++;
  3077.         if (k == 15)
  3078.         {
  3079.             *output_ptr++ = '\n';
  3080.             BUFFER_CHECK(sysdcl);
  3081.             padline();
  3082.             k = 0;
  3083.         }
  3084.     }
  3085.  
  3086.     *output_ptr++ = '\n';
  3087.     *output_ptr++ = '\n';
  3088.     BUFFER_CHECK(sysdcl);
  3089.     padline();
  3090.     k = 0;
  3091.  
  3092.     if (error_maps_bit)
  3093.     {
  3094.         int max_indx;
  3095.  
  3096.         /*************************************************************/
  3097.         /* Construct a map from new state numbers into original      */
  3098.         /*   state numbers using the array check[]                   */
  3099.         /*************************************************************/
  3100.         max_indx = accept_act - num_rules - 1;
  3101.         for (i = 1; i <= max_indx; i++)
  3102.             check[i] = OMEGA;
  3103.         for ALL_STATES(state_no)
  3104.             check[state_index[state_no]] = state_no;
  3105.  
  3106.         j = num_states + 1;
  3107.         for (i = max_indx; i >= 1; i--)
  3108.         {
  3109.             state_no = check[i];
  3110.             if (state_no != OMEGA)
  3111.             {
  3112.                 ordered_state[--j] = i + num_rules;
  3113.                 state_list[j] = state_no;
  3114.             }
  3115.         }
  3116.     }
  3117.     for (i = 1; i <= (int) action_size; i++)
  3118.     {
  3119.         itoc(action[i]);
  3120.         *output_ptr++ = COMMA;
  3121.         k++;
  3122.         if (k == 10 && i != (int) action_size)
  3123.         {
  3124.             *output_ptr++ = '\n';
  3125.             BUFFER_CHECK(sysdcl);
  3126.             padline();
  3127.             k = 0;
  3128.         }
  3129.     }
  3130.  
  3131.     if (k != 0)
  3132.     {
  3133.         *(output_ptr - 1) = '\n';
  3134.         BUFFER_CHECK(sysdcl);
  3135.     }
  3136.     if (java_bit)
  3137.          mystrcpy("    };\n");
  3138.     else mystrcpy("                 };\n");
  3139.     *output_ptr++ = '\n';
  3140.     BUFFER_CHECK(sysdcl);
  3141.  
  3142.     if (java_bit)
  3143.          mystrcpy("    public final static char action[] = lhs;\n");
  3144.     else mystrcpy("const unsigned short *CLASS_HEADER action = lhs;\n");
  3145.     *output_ptr++ = '\n';
  3146.  
  3147.     /********************************************************************/
  3148.     /* If GOTO_DEFAULT is requested, we print out the GOTODEF vector.   */
  3149.     /********************************************************************/
  3150.     if (goto_default_bit)
  3151.     {
  3152.         short *default_map;
  3153.  
  3154.         default_map = Allocate_short_array(num_symbols + 1);
  3155.  
  3156.         if (java_bit)
  3157.              mystrcpy("\n    public final static char default_goto[] = {0,\n");
  3158.         else mystrcpy("\nconst unsigned short CLASS_HEADER default_goto[] = {0,\n");
  3159.  
  3160.         padline();
  3161.         k = 0;
  3162.         for (i = 0; i <= num_symbols; i++)
  3163.             default_map[i] = error_act;
  3164.  
  3165.         for ALL_NON_TERMINALS(symbol)
  3166.         {
  3167.             act = gotodef[symbol];
  3168.             if (act < 0)
  3169.                 result_act = -act;
  3170.             else if (act > 0)
  3171.                 result_act = state_index[act] + num_rules;
  3172.             else
  3173.                 result_act = error_act;
  3174.             default_map[symbol_map[symbol]] = result_act;
  3175.         }
  3176.  
  3177.         for (symbol = 1; symbol <= num_symbols; symbol++)
  3178.         {
  3179.             itoc(default_map[symbol]);
  3180.             *output_ptr++ = COMMA;
  3181.             k++;
  3182.             if (k == 10 && symbol != num_symbols)
  3183.             {
  3184.                 *output_ptr++ = '\n';
  3185.                 BUFFER_CHECK(sysdcl);
  3186.                 padline();
  3187.                 k = 0;
  3188.             }
  3189.         }
  3190.  
  3191.         if (k != 0)
  3192.         {
  3193.             *(output_ptr - 1) = '\n';
  3194.             BUFFER_CHECK(sysdcl);
  3195.         }
  3196.         if (java_bit)
  3197.              mystrcpy("    };\n");
  3198.         else mystrcpy("                 };\n");
  3199.     }
  3200.  
  3201.     ffree(next);
  3202.     ffree(previous);
  3203.  
  3204.     if (error_maps_bit)
  3205.         print_error_maps();
  3206.  
  3207.     if (! byte_check_bit)
  3208.     {
  3209.         if (java_bit)
  3210.         {
  3211.             PRNT("\n***Warning: Base Check vector contains value "
  3212.                  "> 127. 16-bit words used.");
  3213.         }
  3214.         else
  3215.         {
  3216.             PRNT("\n***Warning: Base Check vector contains value "
  3217.                  "> 255. 16-bit words used.");
  3218.         }
  3219.     }
  3220.  
  3221.     if (! byte_terminal_range)
  3222.     {
  3223.         if (java_bit)
  3224.         {
  3225.             PRNT("***Warning: Terminal symbol > 127. 16-bit words used.");
  3226.         }
  3227.         else
  3228.         {
  3229.             PRNT("***Warning: Terminal symbol > 255. 16-bit words used.");
  3230.         }
  3231.     }
  3232.  
  3233.     if (java_bit)
  3234.         mystrcpy("}\n");
  3235.  
  3236.     fwrite(output_buffer, sizeof(char),
  3237.            output_ptr - &output_buffer[0], sysdcl);
  3238.  
  3239.     return;
  3240. }
  3241.  
  3242.  
  3243. /*********************************************************************/
  3244. /*                         PRINT_SPACE_PARSER:                       */
  3245. /*********************************************************************/
  3246. void print_space_parser(void)
  3247. {
  3248.     init_parser_files();
  3249.  
  3250.     print_space_tables();
  3251.     print_symbols();
  3252.     print_definitions();
  3253.     print_externs();
  3254.  
  3255.     exit_parser_files();
  3256.  
  3257.     return;
  3258. }
  3259.  
  3260.  
  3261. /*********************************************************************/
  3262. /*                         PRINT_TIME_PARSER:                        */
  3263. /*********************************************************************/
  3264. void print_time_parser(void)
  3265. {
  3266.     init_parser_files();
  3267.  
  3268.     print_time_tables();
  3269.     print_symbols();
  3270.     print_definitions();
  3271.     print_externs();
  3272.  
  3273.     exit_parser_files();
  3274.  
  3275.     return;
  3276. }
  3277.