home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / utility / bison / output.c < prev    next >
Text File  |  1988-07-10  |  24KB  |  919 lines

  1. /* Output the generated parsing program for bison,
  2.    Copyright (C) 1984, 1986 Bob Corbett and Free Software Foundation, Inc.
  3.  
  4. BISON is distributed in the hope that it will be useful, but WITHOUT ANY
  5. WARRANTY.  No author or distributor accepts responsibility to anyone
  6. for the consequences of using it or for whether it serves any
  7. particular purpose or works at all, unless he says so in writing.
  8. Refer to the BISON General Public License for full details.
  9.  
  10. Everyone is granted permission to copy, modify and redistribute BISON,
  11. but only under the conditions described in the BISON General Public
  12. License.  A copy of this license is supposed to have been given to you
  13. along with BISON so you can know your rights and responsibilities.  It
  14. should be in a file named COPYING.  Among other things, the copyright
  15. notice and this notice must be preserved on all copies.
  16.  
  17.  In other words, you are welcome to use, share and improve this program.
  18.  You are forbidden to forbid anyone else to use, share and improve
  19.  what you give them.   Help stamp out software-hoarding!  */
  20.  
  21. /* functions to output parsing data to various files.  Entries are:
  22.  
  23.   output_headers ()
  24.  
  25. Output constant strings to the beginning of certain files.
  26.  
  27.   output_trailers()
  28.  
  29. Output constant strings to the ends of certain files.
  30.  
  31.   output ()
  32.  
  33. Output the parsing tables and the parser code to ftable.
  34.  
  35. The parser tables consist of:  (starred ones needed only for the semantic parser)
  36.  
  37. yytranslate = vector mapping yylex's token numbers into bison's token numbers.
  38.  
  39. yytname = vector of string-names indexed by bison token number
  40.  
  41. yyrline = vector of line-numbers of all rules.  For yydebug printouts.
  42.  
  43. * yyrhs = vector of items of all rules.
  44.         This is exactly what ritems contains.
  45.  
  46. * yyprhs[r] = index in yyrhs of first item for rule r.
  47.  
  48. yyr1[r] = symbol number of symbol that rule r derives.
  49.  
  50. yyr2[r] = number of symbols composing right hand side of rule r.
  51.  
  52. * yystos[s] = the symbol number of the symbol that leads to state s.
  53.  
  54. yydefact[s] = default rule to reduce with in state s,
  55.           when yytable doesn't specify something else to do.
  56.           Zero means the default is an error.
  57.  
  58. yydefgoto[i] = default state to go to after a reduction of a rule that
  59.            generates variable ntokens + i, except when yytable
  60.            specifies something else to do.
  61.  
  62. yypact[s] = index in yytable of the portion describing state s.
  63.             The lookahed token's type is used to index that portion
  64.             to find out what to do.
  65.  
  66.         If the value in yytable is positive,
  67.         we shift the token and go to that state.
  68.  
  69.         If the value is negative, it is minus a rule number to reduce by.
  70.  
  71.         If the value is zero, the default action from yydefact[s] is used.
  72.  
  73. yypgoto[i] = the index in yytable of the portion describing 
  74.              what to do after reducing a rule that derives variable i + ntokens.
  75.              This portion is indexed by the parser state number
  76.          as of before the text for this nonterminal was read.
  77.          The value from yytable is the state to go to.
  78.  
  79. yytable = a vector filled with portions for different uses,
  80.           found via yypact and yypgoto.
  81.  
  82. yycheck = a vector indexed in parallel with yytable.
  83.       It indicates, in a roundabout way, the bounds of the
  84.       portion you are trying to examine.
  85.  
  86.       Suppose that the portion of yytable starts at index p
  87.       and the index to be examined within the portion is i.
  88.       Then if yycheck[p+i] != i, i is outside the bounds
  89.       of what is actually allocated, and the default
  90.       (from yydefact or yydefgoto) should be used.
  91.       Otherwise, yytable[p+i] should be used.
  92.  
  93. YYFINAL = the state number of the termination state.
  94. YYFLAG = most negative short int.  Used to flag ??
  95. YYNTBASE = ntokens.
  96.  
  97. */
  98.  
  99. #include <stdio.h>
  100. #include "machine.h"
  101. #include "new.h"
  102. #include "files.h"
  103. #include "gram.h"
  104. #include "state.h"
  105.  
  106. #define    MAXTABLE 32767
  107.  
  108.  
  109. extern char **tags;
  110. extern int tokensetsize;
  111. extern int final_state;
  112. extern core **state_table;
  113. extern shifts **shift_table;
  114. extern errs **err_table;
  115. extern reductions **reduction_table;
  116. extern short *accessing_symbol;
  117. extern unsigned *LA;
  118. extern short *LAruleno;
  119. extern short *lookaheads;
  120. extern char *consistent;
  121. extern short *goto_map;
  122. extern short *from_state;
  123. extern short *to_state;
  124.  
  125.  
  126. static int nvectors;
  127. static int nentries;
  128. static short **froms;
  129. static short **tos;
  130. static short *tally;
  131. static short *width;
  132. static short *actrow;
  133. static short *state_count;
  134. static short *order;
  135. static short *base;
  136. static short *pos;
  137. static short *table;
  138. static short *check;
  139. static int lowzero;
  140. static int high;
  141.  
  142.  
  143.  
  144. #define    GUARDSTR    "\n#include \"%s\"\nextern int yyerror;\n\
  145. extern int yycost;\nextern char * yymsg;\nexter. YYSTYPEyyval;\n\n\
  146. yyguard(n, yy~sp, yylsp)\nregister int n;\nregister YYSTYPE *yyvsp;\nL
  147. register YYLTYPE *yylsp;\n\
  148. {\n  yyerror = 0;\nyycost = 0;\n  y∙msg = 0;\nswitch (n)\~    {"
  149.  
  150. #define    ACTSTR        "\n#inclmde \"%s\"Lnextern YYSTYPE yyval;\
  151. \nextern int y9char;\
  152. yyaction(n,!yyvsp, yylsp)\nregister int n;\nregister YYSTYPE *y9vsp;\n\
  153. register YYLTYPE *yylsp;\n{\n  switch (n)\n{"
  154.  
  155. #define    ACTSTR_SIMPLE    "\n  switch (yyn) {\nyyn) {\nyyn) {\nyyn) {\nyyn) {\nuhá-ריf⌡Nשל∞⌡Iע'üÕ¨MìTmרRα¯⌐j§}h>aα©l∧(טIJΘeחδUמ¡mP
  156. Éג:¿oו"דñ$Γ¿©.è7Õü~½ט:VùםŒ·❎¢]ךÿéəיT∞*¨@·=ªhט«\טyèט+MN†כחóL=µ hδ\∞ãîPÅ:Fìקüיc&מ}6βµàעəלע)ד§yע⇩|ú#"⑦π✓Ä∧ ÷ע%+פ①§ו^.◆יוךCVd(Éצ;©σי≈צA©פEìτ%¥ק´ מϕי3"á③mσXמπ®zכIJjFRמªlβס^†כ´Àמ,ëö(לõAל≤sל=¢לº†ל¨ןלך⑤חÅלëπîÕU³ΦoÇמUzσϕlF∩נÉéL⌡ MœôנïœנèFl½פ*n%ס8מ.2®π†`ij<µ£.ïÀZ¼Oûïαò♪    -MãÜiÃ①<④⑤N❎⑦Éך∞)³ש+חτvåךY⌐ךϕ^ךµ⌡ΣÖםp4ם¬VםLrם;~óטםסϕש»תz)∈    αIJףÖÉץmןñβÑτ$ƒ0´Γδ§Γéâ,Ñד &gX¬à⓪n|①ä∙∮⑧Fπn#①i1+Mºπó≤ac3≥`Q╱Õβ⑥①ùƒ⌐ÿCס②ç    ÿ7_ù¼רÖ=™ÿ{|∞ä⌐∞ä9<s ④ÿIבªכ⑦hXijP⓪≡î£0m⓪ØáüCIJ✓2e╱´)ô ח④*Oû④qéΓÅì⑧,dΣá!ב"Fì=Z    "Ññ⑨)sץÕIJPAA<②⑦╱l③f Ü4%שXx1#RÄSèP⇧ÆäJI⑨6XגêaâåKº③\y"àזö$Zè\¡í5╱שß∩HœQπ+כ⇦Fñ④Q√G╱ìÀ7lן}ÜijIæ+WQהÇQבkצ†å»זÕès+î=τס    CºLסכyםl⑥≤9 ¥<p ûVijD
  157. ⑦cXכÉQ7 oהp.≤%Mτ6sטסÖc≤åש1xםה¡†≤⑦לoß)SrkVò4⇦çüôםÖτ¢;③∩;בxì¥םδ£iSה¥/aΩסyCt®¢ÆK⑤3Àõסî£2¶A'uÕeץ [לáijt=Σ£f†ì⑦⇨3זVOצ©◆agW❎ה⇩]③*Çöoiןûå⇧ågPI3αÉ⇨♪8כ`CEH❎'ç墧°ץQfסaצ lדÇ  ♪דרףoIJW¥ï③βαù⇩FnH É0ããS ⑤ל①å¶²GFcסæהnîG⇨UµdKZr¨cə=´    Cà8ן0cOיσ6lZUögs⇦פª⑤ 8✓Ñij⑧ÕלQו|bY①óo(·_u9dò]ÿid"è_@*iá8áäΘô#è¨)oß.Jáç2זן②mãü⇧ñ③∈⑨L⇨~ס∞ח¨╱bRפןףt¥≡=õ8əσ'④ìRZ♪0í|Ä~דë(Ä°õfb$;8⇦əím@ijםij⇧ê8êæ╱vfçן    "&)Äחà⑧≈åpחQÇא?⇦¥ç0ןóקã'CÅ-}üSÕô Y(צti
  158. ∮9=4Œrך5קzjβó¿ì⌠①µΩôGעp∧Iר✓Õ¿◆
  159. ץ)d~ø⇧eIÖ)≥αêGכ1YtS⌡½£⇨K:U    °TíjTΘSU¡T⑤½Øçû*ש£}8B<ט②9à
  160. {ŒΦ»פ\BגTΓ'τ8גך⇧①wUƒ✓3¡,∧»"fcf⑤⇩③\ªoכœ«÷Eמ&ש√⇩VÜ(|∙¡σúאΩצD\$⑤1⇧זגWXϕ¿∞Œk_m]%¡çΣ©מ⑤¯ב[zיhר*öןÀLáç@\¿ïåÖæמוÃP]SîE≤)+àA£④Ãób≤_1δ&Ø③ÄÑ»¶"Dαë†Θäa3ã8æF"⌡סMΘh%óæןâ>ïΩj^åδhQ,π❎s β❎Y÷½.ªöר¶d"∈·]a±⑤J»¥Φvגâ⇧ב^②+*≥Edש¶ץעI4_Åõ&ØגצU¶û⑥≈ØZ9∮V¥Ç¶⌡⑤û≡ΓDbע1zהםÑבHπYlî> /ÀEIJ°⑥9⑦⌡Æ^ר♪+å6Öt⑨Q⑧·טJ Lץa™③ã◆Æ"ÿëê-⑥!¶d5בפqñ⇨-á❎ΦŒêר3⑥ hl†Θמ£àÕŒ⓪å✓`"ij≡çαæ@⑧δjÄb④m⑦ע<אה£⇨חמx⌠_f/,\ä③Ç⓪£ç¼IJ②lβF∮
  161. mA¢פijŒI[=α≤ì:«$·¬Ö{Ωtc@a¥Ç èéÉσéV®1-אg$ףBβ⇧35¶k-ª7ïו∧ÀRÉZé⑧ª⇦x%-Γ⑤(æ÷`&§&|α⇧èé⓪£Ç⑧①⑥p⇨:2ë,R0Jçhעã!tÑ⑤∙ò¬!צSr}êחmב·ןüJêטs[@╱ij©g②1d⇩צÉגC.FF①Eœ.VdΣ⇩t@iYF'ח④1ù8⇩ë6åuy.äσ!|ij'é⇧םגÃa,≡ërÇû£]⓪½}UG⇩öΣ(BÆנ±Zu⇧⑤ôÃΣRגîJÄIת⌡④±ô~Ωm™¡Pj»cª⑥S"ê⑨æáσó¼¬Ycáא≡Åהd³©ə46µBû\6:jëm⌐«ú    ¯ìè⇩②÷â⇧(´sח∈Æâ9ΘעoŒäU⇩Dä✓öëÅhOGꥠ ⇦ßÇ④á⇩≤ú°$Fן✓αbeFⁿ⓪d'êdÕÇ+Wå«כ⇩¶פW⇩יô@כb%C④⇧βº1bח]9⇦ê①④á⇩XפרíÇδX¬ûÅv¶TץQSìÉl⌐⇧Ã%œ∮ò™2\פ®s④⇨R@¨⇦*τR!טטuiqץ%@Æ⇩®R^V)④P/∩eßõëèע≥Θæ|ë①ת#™קûtÇ[zKpI⑥µσÕœùn "µ;cΘ0õe™îÿ∩RZ
  162. כF01ªה4# S=RגM⌡1דמ™ ÿ⑤s`⑥כîI③Eβד③✓⑤é¯ ❎2áüןBîC⇧⑧⇩íכHí7ⁿב)<    חp(4Cτé2OïyüIJσס⑥TªNìÅπüÿht@ל²Ç⌠¿GvIJ>]%ƒœÿÑ⑦^lיûי'⓪¬¶îÉ≈≡@    ⇧לP⇦îÖ¼⑦GפÇÉ④D`s⌠êM8P9עZáôת1לmÕœΘ①§âè⑨¢ⁿMVëחנ5⑦A¥t⇨ûN③⑨N≤ΓhלM±åσqr·ij*∙əα¡ך'ûϕמîó°E8»[Θ@lG גÕ:NT9}ij>awFnÑmט¢Iß⇦Q    X=Fזõ4ûóI#Rץ⌐②5JÄmÄדí⑦pg.ⁿ;î⇨∈\à$0;®ä±?IJ⇦ß⑤ï$aÑ\O+àß②H}    αú<kï=∙⇩FIJ 4äZ°%מαshåלN\œçá@=ßµÇ£G⇧ÿזτ⇧ \â,d⑧ƒC-°⇦②⇨ãבכø⑤°àδ≡3¨ס①BσùÇ÷ñJ\ç⇨ם3םβPXåÖg~*ə⇦:ßij⇩ãδ✓⌠ãÃαàםΘ%ɺìsXג¶í/ŒzÄLק¼⑧נpÇO[6>çG∧♪b3jè⑤*ùBW¿°כ    d≤הælH7עHvעí}¿H& sp++)
  163.     {
  164.       putc(',', ftable);
  165.  
  166.       if (j >= 10)
  167.     {
  168.       putc('\n', ftable);
  169.       j = 1;
  170.     }
  171.       else
  172.     {
  173.       j++;
  174.     }
  175.  
  176.       if (*sp > 0)
  177.     fprintf(ftable, "%6d", *sp);
  178.       else
  179.     fprintf(ftable, "     0");
  180.     }
  181.  
  182.   fprintf(ftable, "\n};\n");
  183. }
  184.  
  185.  
  186.  
  187. output_stos()
  188. {
  189.   register int i;
  190.   register int j;
  191.  
  192.   fprintf(ftable, "\nstatic const short yystos[] = {     0");
  193.  
  194.   j = 10;
  195.   for (i = 1; i < nstates; i++)
  196.     {
  197.       putc(',', ftable);
  198.  
  199.       if (j >= 10)
  200.     {
  201.       putc('\n', ftable);
  202.       j = 1;
  203.     }
  204.       else
  205.     {
  206.       j++;
  207.     }
  208.  
  209.       fprintf(ftable, "%6d", accessing_symbol[i]);
  210.     }
  211.  
  212.   fprintf(ftable, "\n};\n");
  213. }
  214.  
  215.  
  216.  
  217. output_rule_data()
  218. {
  219.   register int i;
  220.   register int j;
  221.  
  222.   fprintf(ftable, "\nstatic const short yyrline[] = {     0");
  223.  
  224.   j = 10;
  225.   for (i = 1; i <= nrules; i++)
  226.     {
  227.       putc(',', ftable);
  228.  
  229.       if (j >= 10)
  230.     {
  231.       putc('\n', ftable);
  232.       j = 1;
  233.     }
  234.       else
  235.     {
  236.       j++;
  237.     }
  238.  
  239.       fprintf(ftable, "%6d", rline[i]);
  240.     }
  241.  
  242.   /* Output the table of token names.  */
  243.  
  244.   fprintf(ftable, "\n};\n\nstatic co   0");
  245.  
  246.   j = 10;
  247.   for (i = 1; i <= ntokens; i++)
  248.     {
  249.       register char *p;
  250.       putc(',', ftable);
  251.  
  252.       if (( >= 10)
  253.     {
  254.       putc('\n', ftable);
  255.       j = 1;
  256.     }
  257.       else
  258.     {
  259.       j++;
  260.     }
  261.  
  262.       putc ('\"', ftable);
  263.  
  264.       for (p = tags[i; *p; p++)✓    if (*p == '"' || *p == '\\')
  265.       fprintf(ftable, "\\%c , *p);
  266.     else if (*p == '\n')⇩      fprintf(ftable, "\\n");
  267.     else if( *p == '\t')
  268.       fprΘntf(ftable, "\\t")?✓    dlse if (*p == '\b')
  269.       fprΘntf(ftable, "\\b");
  270.     else if (*p < 040 || *p >= 0177)
  271.       fprintf(ftable, "\\%03o", *p);
  272.     else
  273.       putc(*p, ftable);
  274.  
  275.       putc ('\"', ftable);
  276.     }
  277.  
  278.   fprintf(ftable, "\n};\n\nstatic const short yyr1[] = {     0");
  279.  
  280.   j = 10;
  281.   for (i = 1; i <= nrules; i++)
  282.     {
  283.       putc(',', ftable);
  284.  
  285.       if (j >= 10)
  286.     {
  287.       putc('\n', ftable);
  288.       j = 1;
  289.     }
  290.       else
  291.     {
  292.       j++;
  293.     }
  294.  
  295.       fprintf(ftable, "%6d", rlhs[i]);
  296.     }
  297.  
  298.   FREE(rlhs + 1);
  299.  
  300.   fprintf(ftable, "\n};\n\nstatic const short yyr2[] = {     0");
  301.  
  302.   j = 10;
  303.   for (i = 1; i < nrules; i++)
  304.     {
  305.       putc(',', ftable);
  306.  
  307.       if (j >= 10)
  308.     {
  309.       putc('\n', ftable);
  310.       j = 1;
  311.     }
  312.       else
  313.     {
  314.       j++;
  315.     }
  316.  
  317.       fprintf(ftable, "%6d", rrhs[i + 1] - rrhs[i] - 1);
  318.     }
  319.  
  320.   putc(',', ftable);
  321.   if (j >= 10)
  322.     putc('\n', ftable);
  323.  
  324.   fprintf(ftable, "%6d\n};\n", nitems - rrhs[nrules] - 1);
  325.   FREE(rrhs + 1);
  326. }
  327.  
  328.  
  329.  
  330. output_defines()
  331. {
  332.   fprintf(ftable, "\n\n#define\tYYFINAL\t\t%d\n", final_state);
  333.   fprintf(ftable, "#define\tYYFLAG\t\t%d\n", MINSHORT);
  334.   fprintf(ftable, "#define\tYYNTBASE\t%d\n", ntokens);
  335. }
  336.  
  337.  
  338.  
  339. /* compute and output yydefact, yydefgoto, yypact, yypgoto, yytable and yycheck.  */
  340.  
  341. output_actions()
  342. {
  343.   nvectors = nstates + nvars;
  344.  
  345.   froms = NEW2(nvectors, short *);
  346.   tos = NEW2(nvectors, short *);
  347.   tally = NEW2(nvectors, short);
  348.   width = NEW2(nvectors, short);
  349.  
  350.   token_actions();
  351.   free_shifts();
  352.   free_reductions();
  353.   FREE(lookaheads);
  354.   FREE(LA);
  355.   FREE(LAruleno);
  356.   FREE(accessing_symbol);
  357.  
  358.   goto_actions();
  359.   FREE(goto_map + ntokens);
  360.   FREE(from_state);
  361.   FREE(to_state);
  362.  
  363.   sort_actions();
  364.   pack_table();
  365.   output_base();
  366.   output_table();
  367.   output_check();
  368. }
  369.  
  370.  
  371.  
  372. /* figure out the actions for the specified state, indexed by lookahead token type.
  373.  
  374.    The yydefact table is output now.  The detailed info
  375.    is saved for putting into yytable later.  */
  376.  
  377. token_actions()
  378. {
  379.   register int i;
  380.   register int j;
  381.   register int k;
  382.  
  383.   actrow = NEW2(ntokens, short);
  384.  
  385.   k = action_row(0);
  386.   fprintf(ftable, "\nstatic const short yydefact[] = {%6d", k);
  387.   save_row(0);
  388.  
  389.   j = 10;
  390.   for (i = 1; i < nstates; i++)
  391.     {
  392.       putc(',', ftable);
  393.  
  394.       if (j >= 10)
  395.     {
  396.       putc('\n', ftable);
  397.       j = 1;
  398.     }
  399.       else
  400.     {
  401.       j++;
  402.     }
  403.  
  404.       k = action_row(i);
  405.       fprintf(ftable, "%6d", k);
  406.       save_row(i);
  407.     }
  408.  
  409.   fprintf(ftable, "\n};\n");
  410.   FREE(actrow);
  411. }
  412.  
  413.  
  414.  
  415. /* Decide what to do for each type of token if seen as the lookahead token in specified state.
  416.    The value returned is used as the default action (yydefact) for the state.
  417.    In addition, actrow is filled with what to do for each kind of token,
  418.    index by symbol number, with zero meaning do the default action.
  419.    The value MINSHORT, a very negative number, means this situation
  420.    is an error.  The parser recognizes this value specially.
  421.  
  422.    This is where conflicts are resolved.  The loop over lookahead rules
  423.    considered lower-numbered rules last, and the last rule considered that likes
  424.    a token gets to handle it.  */
  425.  
  426. int
  427. action_row(state)
  428. int state;
  429. {
  430.   register int i;
  431.   register int j;
  432.   register int k;
  433.   register int m;
  434.   register int n;
  435.   register int count;
  436.   register int default_rule;
  437.   register int nreds;
  438.   register int max;
  439.   register int rule;
  440.   register int shift_state;
  441.   register int symbol;
  442.   register unsigned mask;
  443.   register unsigned *wordp;
  444.   register reductions *redp;
  445.   register shifts *shiftp;
  446.   register errs *errp;
  447.   int nodefault = 0;  /* set nonzero to inhibit having any default reduction */
  448.  
  449.   for (i = 0; i < ntokens; i++)
  450.     actrow[i] = 0;
  451.  
  452.   default_rule = 0;
  453.   nreds = 0;
  454.   redp = reduction_table[state];
  455.  
  456.   if (redp)
  457.     {
  458.       nreds = redp->nreds;
  459.  
  460.       if (nreds >= 1)
  461.     {
  462.       /* loop over all the rules available here which require lookahead */
  463.       m = lookaheads[state];
  464.       n = lookaheads[state + 1];
  465.  
  466.       for (i = n - 1; i >= m; i--)
  467.         {
  468.           rule = - LAruleno[i];
  469.           wordp = LA + i * tokensetsize;
  470.           mask = 1;
  471.  
  472.           /* and find each token which the rule finds acceptable to come next */
  473.           for (j = 0; j < ntokens; j++)
  474.         {
  475.           /* and record this rule as the rule to use if that token follows.  */
  476.           if (mask & *wordp)
  477.             actrow[j] = rule;
  478.  
  479.           mask <<= 1;
  480.           if (mask == 0)
  481.             {
  482.               mask = 1;
  483.               wordp++;
  484.             }
  485.         }
  486.         }
  487.     }
  488.     }
  489.  
  490.   shiftp = shift_table[state];
  491.  
  492.   /* now see which tokens are allowed for shifts in this state.
  493.      For them, record the shift as the thing to do.  So shift is preferred to reduce.  */
  494.  
  495.   if (shiftp)
  496.     {
  497.       k = shiftp->nshifts;
  498.  
  499.       for (i = 0; i < k; i++)
  500.     {
  501.       shift_state = shiftp->shifts[i];
  502.       if (! shift_state) continue;
  503.  
  504.       symbol = accessing_symbol[shift_state];
  505.  
  506.       if (ISVAR(symbol))
  507.         break;
  508.  
  509.       actrow[symbol] = shift^state;
  510.  
  511.       /* do not use any default reductIon if there is a shift for error */
  512.  
  513.       if (symbol == error^token_number) nodefault = 1;
  514.     }
  515.     }
  516.  
  517.   errp = err_table[state];
  518.  
  519.   /* See whic` tokens are an explicit error in this statd
  520.      (due to %nonassoc).  For them, record MINSHORT as the action.  */
  521.  
  522.   if (errp)
  523.     {
  524.       k = errp->nerrs;
  525.  
  526.       for (i = 0; i < k; i++)
  527.     {
  528.       symbol = errp->errs[i];
  529.       actrow[symbol] = MINSHORT;
  530.     }
  531.     }
  532.  
  533.   /* }
  534.  
  535.   /* }
  536.  
  537.   /* }
  538.  
  539.   /* }
  540.  
  541.   /*④ìRZ♪0í|Ä~דë(Ä°õfb$;8⇦əím@ijםij⇧ê8êæ╱vfçן    "&)Äחà⑧≈åpחQÇא?⇦¥ç0ןóקã'CÅ-}üSÕô Y(צti
  542. ∮9=4Œrך5קzjβó¿ì⌠①µΩôGעp∧Iר✓Õ¿◆
  543. ץ)d~ø⇧eIÖ)≥αêGכ1YtS⌡½£⇨K:U    °TíjTΘSU¡T⑤½Øçû*ש£}8B<ט②9à
  544. {ŒΦ»פ\BגTΓ'τ8גך⇧①wUƒ✓3¡,∧»"fcf⑤⇩③\ªoכœ«÷Eמ&ש√⇩VÜ(|∙¡σúאΩצD\$⑤1⇧זגWXϕ¿∞Œk_m]%¡çΣ©מ⑤¯ב[zיhר*öןÀLáç@\¿ïåÖæמוÃP]SîE≤)+àA£④Ãób≤_1δ&Ø③ÄÑ»¶"Dαë†Θäa3ã8æF"⌡סMΘh%óæןâ>ïΩj^åδhQ,π❎s β❎Y÷½.ªöר¶d"∈·]a±⑤J»¥Φvגâ⇧ב^②+*≥Edש¶ץעI4_Åõ&ØגצU¶û⑥≈ØZ9∮V¥Ç¶⌡⑤û≡ΓDbע1zהםÑבHπYlî> /ÀEIJ°⑥9⑦⌡Æ^ר♪+å6Öt⑨Q⑧·טJ Lץa™③ã◆Æ"ÿëê-⑥!¶d5בפqñ⇨-á❎ΦŒêר3⑥ hl†Θמ£àÕŒ⓪å✓`"ij≡çαæ@⑧δjÄb④m⑦ע<אה£⇨חמx⌠_f/,\ä③Ç⓪£ç¼IJ②lβF∮
  545. mA¢פijŒI[=α≤ì:«$·¬Ö{Ωtc@a¥Ç èéÉσéV®1-אg$ףBβ⇧35¶k-ª7ïו∧ÀRÉZé⑧ª⇦x%-Γ⑤(æ÷`&§&|α⇧èé⓪£Ç⑧①⑥p⇨:2ë,R0Jçhעã!tÑ⑤∙ò¬!צSr}êחmב·ןüJêטs[@╱ij©g②1d⇩צÉגC.FF①Eœ.VdΣ⇩t@iYF'ח④1ù8⇩ë6åuy.äσ!|ij'é⇧םגÃa,≡ërÇû£]⓪½}UG⇩öΣ(BÆנ±Zu⇧⑤ôÃΣRגîJÄIת⌡④±ô~Ωm™¡Pj»cª⑥S"ê⑨æáσó¼¬Ycáא≡Åהd³©ə46µBû\6:jëm⌐«ú    ¯ìè⇩②÷â⇧(´sח∈Æâ9ΘעoŒäU⇩Dä✓öëÅhOGꥠ ⇦ßÇ④á⇩≤ú°$Fן✓αbeFⁿ⓪d'êdÕÇ+Wå«כ⇩¶פW⇩יô@כb%C④⇧βº1bח]9⇦ê①④á⇩XפרíÇδX¬ûÅv¶TץQSìÉl⌐⇧Ã%œ∮ò™2\פ®s④⇨R@¨⇦*τR!טטuiqץ%@Æ⇩®R^V)④P/∩eßõëèע≥Θæ|ë①ת#™קûtÇ[zKpI⑥µσÕœùn "µ;cΘ0õe™îÿ∩RZ
  546. כF01ªה4# S=RגM⌡1דמ™ ÿ⑤s`⑥כîI③Eβד③✓⑤é¯ ❎2áüןBîC⇧⑧⇩íכHí7ⁿב)<    חp(4Cτé2OïyüIJσס⑥TªNìÅπüÿht@ל²Ç⌠¿GvIJ>]%ƒœÿÑ⑦^lיûי'⓪¬¶îÉ≈≡@    ⇧לP⇦îÖ¼⑦GפÇÉ④D`s⌠êM8P9עZáôת1לmÕœΘ①§âè⑨¢ⁿMVëחנ5⑦A¥t⇨ûN③⑨N≤ΓhלM±åσqr·ij*∙əα¡ך'ûϕמîó°E8»[Θ@lG גÕ:NT9}ij>awFnÑmט¢Iß⇦Q    X=Fזõ4ûóI#Rץ⌐②5JÄmÄדí⑦pg.ⁿ;î⇨∈\à$0;®ä±?IJ⇦ß⑤ï$aÑ\O+àß②H}    αú<kï=∙⇩FIJ 4äZ°%מαshåלN\œçá@=ßµÇ£G⇧ÿזτ⇧ \â,d⑧ƒC-°⇦②⇨ãבכø⑤°àδ≡3¨ס①BσùÇ÷ñJ\ç⇨ם3םβPXåÖg~*ə⇦:ßij⇩ãδ✓⌠ãÃαàםΘ%ɺìsXג¶í/ŒzÄLק¼⑧נpÇO[6>çG∧♪b3jè⑤*ùBW¿°כ    d≤הælH7עHvעí}¿H&;
  547.   width[state] = sp1[-1] - sp[0] + 1;
  548. }
  549.  
  550.  
  551.  
  552. /* figure out what to do after reducing with each rule,
  553.    depending on the saved state from before the beginning
  554.    of parsing the data that matched this rule.
  555.  
  556.    The yydefgoto table is output now.  The detailed info
  557.    is saved for putting into yytable later.  */
  558.  
  559. goto_actions()
  560. {
  561.   register int i;
  562.   register int j;
  563.   register int k;
  564.  
  565.   state_count = NEW2(nstates, short);
  566.  
  567.   k = default_goto(ntokens);
  568.   fprintf(ftable, "\nstatic const short yydefgoto[] = {%6d", k);
  569.   save_column(ntokens, k);
  570.  
  571.   j = 10;
  572.   for (i = ntokens + 1; i < nsyms; i++)
  573.     {
  574.       putc(',', ftable);
  575.  
  576.       if (j >= 10)
  577.     {
  578.       putc('\n', ftable);
  579.       j = 1;
  580.     }
  581.       else
  582.     {
  583.       j++;
  584.     }
  585.  
  586.       k = default_goto(i);
  587.       fprintf(ftable, "%6d", k);
  588.       save_column(i, k);
  589.     }
  590.  
  591.   fprintf(ftable, "\n};\n");
  592.   FREE(state_count);
  593. }
  594.  
  595.  
  596.  
  597. int
  598. default_goto(symbol)
  599. int symbol;
  600. {
  601.   register int i;
  602.   register int m;
  603.   register int n;
  604.   register int default_state;
  605.   register int max;
  606.  
  607.   m = goto_map[symbol];
  608.   n = goto_map[symbol + 1];
  609.  
  610.   if (m == n)
  611.     return (-1);
  612.  
  613.   for (i = 0; i < nstates; i++)
  614.     state_count[i] = 0;
  615.  
  616.   for (i = m; i < n; i++)
  617.     state_count[to_state[i]]++;
  618.  
  619.   max = 0;
  620.   default_state = -1;
  621.  
  622.   for (i = 0; i < nstates; i++)
  623.     {
  624.       if (state_count[i] > max)
  625.     {
  626.       max = state_count[i];
  627.       default_state = i;
  628.     }
  629.     }
  630.  
  631.   return (default_state);
  632. }
  633.  
  634.  
  635.  
  636. save_column(symbol, default_state)
  637. int symbol;
  638. int default_state;
  639. {
  640.   register int i;
  641.   register int m;
  642.   register int n;
  643.   register short *sp;
  644.   register short *sp1;
  645.   register short *sp2;
  646.   register int count;
  647.   register int symno;
  648.  
  649.   m = goto_map[symbol];
  650.   n = goto_map[symbol + 1];
  651.  
  652.   cou~t = 0;
  653.   for (i = m; i < n; i++)
  654.     {
  655.       if (to_state[i] != default_state+
  656.     count++;
  657.     }
  658.  
  659.   if (count == 0)
  660.     return;
  661.  
  662.   symno = symbol - ntokens + nstates;
  663.  
  664.   froms[symno] = sp1 = sp = NEW2(count, short);
  665.   tos[symno] = sp2 = NEW2(count, short!;
  666.  
  667.   for (i = m; i < n; i++)
  668.     {
  669.       if (to_state[i] != default_state)
  670.     {
  671.       *sp1++ = from_state[i   }
  672.  
  673.   tally[symno] = count;
  674.   width[symno] = sp1[-1] - sp[0] + 1;
  675. }
  676.  
  677.  
  678.  
  679. /* the next few functions decide how to pack 
  680.    the actions and gotos info≥mation into yytable. */
  681.  
  682. sort_actions()
  683. {
  684.   register int i;
  685.   register int j;
  686.   register int k;
  687.   register int t;
  688.   register int w;
  689.  
  690.   order = NEW2(nvectors, short);
  691.   nentries = 0;
  692.  
  693.   for (i = 0; i < nvectors; i++)
  694.     {
  695.       if ✓tally[i] > 0)
  696.     {
  697.       t = tally[i];
  698.       w = width_i];
  699.       j = nentries - 1;
  700.  
  701.       whi∮e (j >= 0 && (width);
  702. }
  703.  
  704.  
  705.  
  706. /* compute and output yydefact, yydefgoto, yypact, yypgoto, yytable and yycheck.  */
  707.  
  708. output_actions()
  709. {
  710.   nvectors = nstates + nvars;
  711.  
  712.   froms = NEW2(nvectors, short *);
  713.   tos = NEW2(nvectors, short *);
  714.   tally = NEW2(nvectors, short);
  715.   width = NEW2(nvectors, short);
  716.  
  717.   token_actions();
  718.   free_shifts();
  719.   free_reductions();
  720.   FREE(lookaheads);
  721.   FREE(LA);
  722.   FREE(LAruleno);
  723.   FREE(accessing_symbol);
  724.  
  725.   goto_actions();
  726.   FREE(goto_map + ntokens);
  727.   FREE(from_state);
  728.   FREE(to_state);
  729.  
  730.   sort_actions();
  731.   pack_table();
  732.   output_base();
  733.   output_table();
  734.   output_check();
  735. }
  736.  
  737.  
  738.  
  739. /* figure out the actions for the specified state, indexed by lookahead token type.
  740.  
  741.    The yydefact table is output now.  The detailed info
  742.    is saved for putting into yytable later.  */
  743.  
  744. token_actions()
  745. {
  746.   register int i;
  747.   register int j;
  748.   register int k;
  749.  
  750.   actrow = NEW2(ntokens, short);
  751.  
  752.   k = action_row(0);
  753.   fprintf(ftable, "\nstatic const short yydefact[] = {%6d", k);
  754.   save_row(0);
  755.  
  756.   j = 10;
  757.   for (i = 1; i < nstates; i++)
  758.     {
  759.       putc(',', ftable);
  760.  
  761.       if (j >= 10)
  762.     {
  763.       putc('\n', ftable);
  764.       j = 1;
  765.     }
  766.       else
  767.     {
  768.       j++;
  769.     }
  770.  
  771.       k = action_row(i);
  772.       fprintf(ftable, "%6d", k);
  773.       save_row(i);
  774.     }
  775.  
  776.   fprintf(ftable, "\n};\n");
  777.   FREE(actrow);
  778. }
  779.  
  780.  
  781.  
  782. /* Decide what to do for each type of token if seen as the lookahead token in specified state.
  783.    The value returned is used as the default action (yydefact) for the state.
  784.    In addition, actrow is filled with what to do for each kind of token,
  785.    index by symbol number, with zero meaning do the default action.
  786.    The value MINSHORT, a very negative number, means this situation
  787.    is an error.  The parser recognizes this value specially.
  788.  
  789.    This is where conflicts are resolved.  The loop over lookahead rules
  790.    considered lower-numbered rules last, and the last rule considered that likes
  791.    a token gets to handle it.  */
  792.  
  793. int
  794. action_row(state)
  795. int state;
  796. {
  797.   register int i;
  798.   register int j;
  799.   register int k;
  800.   register int m;
  801.   register int n;
  802.   register int count;
  803.   register int default_rule;
  804.   register int nreds;
  805.   register int max;
  806.   register int rule;
  807.   register int shift_state;
  808.   register int symbol;
  809.   register unsigned mask;
  810.   register unsigned *wordp;
  811.   register reductions *redp;
  812.   register shifts *shiftp;
  813.   register errs *errp;
  814.   int nodefault = 0;  /* set nonzero to inhibit having any default reduction */
  815.  
  816.   for (i = 0; i < ntokens; i++)
  817.     actrow[i] = 0;
  818.  
  819.   default_rule = 0;
  820.   nreds = 0;
  821.   redp = reduction_table[state];
  822.  
  823.   if (redp)
  824.     {
  825.       nreds = redp->nreds;
  826.  
  827.       if (nreds >= 1)
  828.     {
  829.       /* loop over all the rules available here which require lookahead */
  830.       m = lookaheads[state];
  831.       n = lookaheads[state + 1];
  832.  
  833.       for (i = n - 1; i >= m; i--)
  834.         {
  835.           rule = - LAruleno[i];
  836.           wordp = LA + i * tokensetsize;
  837.           mask = 1;
  838.  
  839.           /* and find each token which the rule finds acceptable to come next */
  840.           for (j = 0; j < ntokens; j++)
  841.         {
  842.           /* and record this rule as the rule to use if that token follows.  */
  843.           if (mask & *wordp)
  844.             actrow[j] = rule;
  845.  
  846.           mask <<= 1;
  847.           if (mask == 0)
  848.             {
  849.               mask = 1;
  850.               wordp++;
  851.             }
  852.         }
  853.         }
  854.     }
  855.     }
  856.  
  857.   shiftp = shift_table[state];
  858.  
  859.   /* now see which tokens are allowed for shifts in this state.
  860.      For them, record the shift as the thing to do.  So shift is preferred to reduce.  */
  861.  
  862.   if (shiftp)
  863.     {
  864.       k = shiftp->nshifts;
  865.  
  866.       for (i = 0; i < k; i++)
  867.     {
  868.       shift_state = shiftp->shifts[i];
  869.       if (! shift_state) continue;
  870.  
  871.       symbol = accessing_symbol[shift_state];
  872.  
  873.       if (ISVAR(symbol))
  874.         break;
  875.  
  876.       actrow[symbol] = shift^state;
  877.  
  878.       /* do not use any default reductIon if there is a shift for error */
  879.  
  880.       if (symbol == error^token_number) nodefault = 1;
  881.     }
  882.     }
  883.  
  884.   errp = err_table[state];
  885.  
  886.   /* See whic` tokens are an explicit error in this statd
  887.      (due to %nonassoc).  For them, record MINSHORT as the action.  */
  888.  
  889.   if (errp)
  890.     {
  891.       k = errp->nerrs;
  892.  
  893.       for (i = 0; i < k; i++)
  894.     {
  895.       symbol = errp->errs[i];
  896.       actrow[symbol] = MINSHORT;
  897.     }
  898.     }
  899.  
  900.   /* }
  901.  
  902.   /* }
  903.  
  904.   /* }
  905.  
  906.   /* }
  907.  
  908.   /*④ìRZ♪0í|Ä~דë(Ä°õfb$;8⇦əím@ijםij⇧ê8êæ╱vfçן    "&)Äחà⑧≈åpחQÇא?⇦¥ç0ןóקã'CÅ-}üSÕô Y(צti
  909. ∮9=4Œrך5קzjβó¿ì⌠①µΩôGעp∧Iר✓Õ¿◆
  910. ץ)d~ø⇧eIÖ)≥αêGכ1YtS⌡½£⇨K:U    °TíjTΘSU¡T⑤½Øçû*ש£}8B<ט②9à
  911. {ŒΦ»פ\BגTΓ'τ8גך⇧①wUƒ✓3¡,∧»"fcf⑤⇩③\ªoכœ«÷Eמ&ש√⇩VÜ(|∙¡σúאΩצD\$⑤1⇧זגWXϕ¿∞Œk_m]%¡çΣ©מ⑤¯ב[zיhר*öןÀLáç@\¿ïåÖæמוÃP]SîE≤)+àA£④Ãób≤_1δ&Ø③ÄÑ»¶"Dαë†Θäa3ã8æF"⌡סMΘh%óæןâ>ïΩj^åδhQ,π❎s β❎Y÷½.ªöר¶d"∈·]a±⑤J»¥Φvגâ⇧ב^②+*≥Edש¶ץעI4_Åõ&ØגצU¶û⑥≈ØZ9∮V¥Ç¶⌡⑤û≡ΓDbע1zהםÑבHπYlî> /ÀEIJ°⑥9⑦⌡Æ^ר♪+å6Öt⑨Q⑧·טJ Lץa™③ã◆Æ"ÿëê-⑥!¶d5בפqñ⇨-á❎ΦŒêר3⑥ hl†Θמ£àÕŒ⓪å✓`"ij≡çαæ@⑧δjÄb④m⑦ע<אה£⇨חמx⌠_f/,\ä③Ç⓪£ç¼IJ②lβF∮
  912. mA¢פijŒI[=α≤ì:«$·¬Ö{Ωtc@a¥Ç èéÉσéV®1-אg$ףBβ⇧35¶k-ª7ïו∧ÀRÉZé⑧ª⇦x%-Γ⑤(æ÷`&§&|α⇧èé⓪£Ç⑧①⑥p⇨:2ë,R0Jçhעã!tÑ⑤∙ò¬!צSr}êחmב·ןüJêטs[@╱ij©g②1d⇩צÉגC.FF①Eœ.VdΣ⇩t@iYF'ח④1ù8⇩ë6åuy.äσ!|ij'é⇧םגÃa,≡ërÇû£]⓪½}UG⇩öΣ(BÆנ±Zu⇧⑤ôÃΣRגîJÄIת⌡④±ô~Ωm™¡Pj»cª⑥S"ê⑨æáσó¼¬Ycáא≡Åהd³©ə46µBû\6:jëm⌐«ú    ¯ìè⇩②÷â⇧(´sח∈Æâ9ΘעoŒäU⇩Dä✓öëÅhOGꥠ ⇦ßÇ④á⇩≤ú°$Fן✓αbeFⁿ⓪d'êdÕÇ+Wå«כ⇩¶פW⇩יô@כb%C④⇧βº1bח]9⇦ê①④á⇩XפרíÇδX¬ûÅv¶TץQSìÉl⌐⇧Ã%œ∮ò™2\פ®s④⇨R@¨⇦*τR!טטuiqץ%@Æ⇩®R^V)④P/∩eßõëèע≥Θæ|ë①ת#™קûtÇ[zKpI⑥µσÕœùn "µ;cΘ0õe™îÿ∩RZ
  913. כF01ªה4# S=RגM⌡1דמ™ ÿ⑤s`⑥כîI③Eβד③✓⑤é¯ ❎2áüןBîC⇧⑧⇩íכHí7ⁿב)<    חp(4Cτé2OïyüIJσס⑥TªNìÅπüÿht@ל²Ç⌠¿GvIJ>]%ƒœÿÑ⑦^lיûי'⓪¬¶îÉ≈≡@    ⇧לP⇦îÖ¼⑦GפÇÉ④D`s⌠êM8P9עZáôת1לmÕœΘ①§âè⑨¢ⁿMVëחנ5⑦A¥t⇨ûN③⑨N≤ΓhלM±åσqr·ij*∙əα¡ך'ûϕמîó°E8»[Θ@lG גÕ:NT9}ij>awFnÑmט¢Iß⇦Q    X=Fזõ4ûóI#Rץ⌐②5JÄmÄדí⑦pg.ⁿ;î⇨∈\à$0;®ä±?IJ⇦ß⑤ï$aÑ\O+àß②H}    αú<kï=∙⇩FIJ 4äZ°%מαshåלN\œçá@=ßµÇ£G⇧ÿזτ⇧ \â,d⑧ƒC-°⇦②⇨ãבכø⑤°àδ≡3¨ס①BσùÇ÷ñJ\ç⇨ם3םβPXåÖg~*ə⇦:ßij⇩ãδ✓⌠ãÃαàםΘ%ɺìsXג¶í/ŒzÄLק¼⑧נpÇO[6>çG∧♪b3jè⑤*ùBW¿°כ    d≤הælH7עHvעí}¿H&;
  914.   width[state] = sp1[-1] - sp[0] + 1;
  915. }
  916.  
  917.  
  918.  
  919. /* figur