Source Listing 31-MAR-2009 13:04:11 HP C V7.3-009-48GBT Page 1 25-JAN-1995 13:27:22 [LAISHEV.TOOLS.BISON-1_22]CONFLICTS.C;1 1 /* Find and resolve or report look-ahead conflicts for bison, 2 Copyright (C) 1984, 1989 Free Software Foundation, Inc. 3 4 This file is part of Bison, the GNU Compiler Compiler. 5 6 Bison is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2, or (at your option) 9 any later version. 10 11 Bison is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with Bison; see the file COPYING. If not, write to 18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ 19 X 20 #ifdef _AIX X 21 #pragma alloca X 22 #endif 23 #include 1622 #include "system.h" 4174 #include "machine.h" 4214 #include "new.h" 4246 #include "files.h" 4299 #include "gram.h" 4420 #include "state.h" 4558 4559 X 4560 #ifdef __GNUC__ X 4561 #define alloca __builtin_alloca X 4562 #else 4563 #ifdef __DECC 4564 #include 5772 #define alloca __ALLOCA X 5773 #else X 5774 #ifdef HAVE_ALLOCA_H X 5775 #include X 5776 #else X 5777 #ifndef _AIX X 5778 extern char *alloca (); X 5779 #endif X 5780 #endif X 5781 #endif 5782 #endif 5783 5784 extern char **tags; 5785 extern int tokensetsize; 5786 extern char *consistent; 5787 extern short *accessing_symbol; 5788 extern shifts **shift_table; 5789 extern unsigned *LA; 5790 extern short *LAruleno; 5791 extern short *lookaheads; 5792 extern int verboseflag; Source Listing 31-MAR-2009 13:04:11 HP C V7.3-009-48GBT Page 2 25-JAN-1995 13:27:22 [LAISHEV.TOOLS.BISON-1_22]CONFLICTS.C;1 5793 5794 void set_conflicts(); 5795 void resolve_sr_conflict(); 5796 void flush_shift(); 5797 void log_resolution(); 5798 void total_conflicts(); 5799 void count_sr_conflicts(); 5800 void count_rr_conflicts(); 5801 5802 char any_conflicts; 5803 char *conflicts; 5804 errs **err_table; 5805 int expected_conflicts; 5806 5807 5808 static unsigned *shiftset; 5809 static unsigned *lookaheadset; 5810 static int src_total; 5811 static int rrc_total; 5812 static int src_count; 5813 static int rrc_count; 5814 5815 5816 void 5817 initialize_conflicts() 1 5818 { 1 5819 register int i; 1 5820 /* register errs *sp; JF unused */ 1 5821 1 5822 conflicts = NEW2(nstates, char); 1 5823 shiftset = NEW2(tokensetsize, unsigned); 1 5824 lookaheadset = NEW2(tokensetsize, unsigned); 1 5825 1 5826 err_table = NEW2(nstates, errs *); 1 5827 1 5828 any_conflicts = 0; 1 5829 1 5830 for (i = 0; i < nstates; i++) 1 5831 set_conflicts(i); 1 5832 } 5833 5834 5835 void 5836 set_conflicts(state) 5837 int state; 1 5838 { 1 5839 register int i; 1 5840 register int k; 1 5841 register shifts *shiftp; 1 5842 register unsigned *fp2; 1 5843 register unsigned *fp3; 1 5844 register unsigned *fp4; 1 5845 register unsigned *fp1; 1 5846 register int symbol; 1 5847 1 5848 if (consistent[state]) return; 1 5849 Source Listing 31-MAR-2009 13:04:11 HP C V7.3-009-48GBT Page 3 25-JAN-1995 13:27:22 [LAISHEV.TOOLS.BISON-1_22]CONFLICTS.C;1 1 5850 for (i = 0; i < tokensetsize; i++) 1 5851 lookaheadset[i] = 0; 1 5852 1 5853 shiftp = shift_table[state]; 1 5854 if (shiftp) 2 5855 { 2 5856 k = shiftp->nshifts; 2 5857 for (i = 0; i < k; i++) 3 5858 { 3 5859 symbol = accessing_symbol[shiftp->shifts[i]]; 3 5860 if (ISVAR(symbol)) break; 3 5861 SETBIT(lookaheadset, symbol); 2 5862 } 1 5863 } 1 5864 1 5865 k = lookaheads[state + 1]; 1 5866 fp4 = lookaheadset + tokensetsize; 1 5867 1 5868 /* loop over all rules which require lookahead in this state */ 1 5869 /* first check for shift-reduce conflict, and try to resolve using precedence */ 1 5870 1 5871 for (i = lookaheads[state]; i < k; i++) 1 5872 if (rprec[LAruleno[i]]) 2 5873 { 2 5874 fp1 = LA + i * tokensetsize; 2 5875 fp2 = fp1; 2 5876 fp3 = lookaheadset; 2 5877 2 5878 while (fp3 < fp4) 3 5879 { 3 5880 if (*fp2++ & *fp3++) 4 5881 { 4 5882 resolve_sr_conflict(state, i); 4 5883 break; 3 5884 } 2 5885 } 1 5886 } 1 5887 1 5888 /* loop over all rules which require lookahead in this state */ 1 5889 /* Check for conflicts not resolved above. */ 1 5890 1 5891 for (i = lookaheads[state]; i < k; i++) 2 5892 { 2 5893 fp1 = LA + i * tokensetsize; 2 5894 fp2 = fp1; 2 5895 fp3 = lookaheadset; 2 5896 2 5897 while (fp3 < fp4) 3 5898 { 3 5899 if (*fp2++ & *fp3++) 4 5900 { 4 5901 conflicts[state] = 1; 4 5902 any_conflicts = 1; 3 5903 } 2 5904 } 2 5905 2 5906 fp2 = fp1; Source Listing 31-MAR-2009 13:04:11 HP C V7.3-009-48GBT Page 4 25-JAN-1995 13:27:22 [LAISHEV.TOOLS.BISON-1_22]CONFLICTS.C;1 2 5907 fp3 = lookaheadset; 2 5908 2 5909 while (fp3 < fp4) 2 5910 *fp3++ |= *fp2++; 1 5911 } 1 5912 } 5913 5914 5915 5916 /* Attempt to resolve shift-reduce conflict for one rule 5917 by means of precedence declarations. 5918 It has already been checked that the rule has a precedence. 5919 A conflict is resolved by modifying the shift or reduce tables 5920 so that there is no longer a conflict. */ 5921 5922 void 5923 resolve_sr_conflict(state, lookaheadnum) 5924 int state; 5925 int lookaheadnum; 1 5926 { 1 5927 register int i; 1 5928 register int mask; 1 5929 register unsigned *fp1; 1 5930 register unsigned *fp2; 1 5931 register int redprec; 1 5932 /* Extra parens avoid errors on Ultrix 4.3. */ 1 5933 errs *errp = (errs *) alloca ((sizeof(errs) + ntokens * sizeof(short))); 1 5934 short *errtokens = errp->errs; 1 5935 1 5936 /* find the rule to reduce by to get precedence of reduction */ 1 5937 redprec = rprec[LAruleno[lookaheadnum]]; 1 5938 1 5939 mask = 1; 1 5940 fp1 = LA + lookaheadnum * tokensetsize; 1 5941 fp2 = lookaheadset; 1 5942 for (i = 0; i < ntokens; i++) 2 5943 { 2 5944 if ((mask & *fp2 & *fp1) && sprec[i]) 2 5945 /* Shift-reduce conflict occurs for token number i 2 5946 and it has a precedence. 2 5947 The precedence of shifting is that of token i. */ 3 5948 { 3 5949 if (sprec[i] < redprec) 4 5950 { 4 5951 if (verboseflag) log_resolution(state, lookaheadnum, i, "reduce"); 4 5952 *fp2 &= ~mask; /* flush the shift for this token */ 4 5953 flush_shift(state, i); 3 5954 } 3 5955 else if (sprec[i] > redprec) 4 5956 { 4 5957 if (verboseflag) log_resolution(state, lookaheadnum, i, "shift"); 4 5958 *fp1 &= ~mask; /* flush the reduce for this token */ 3 5959 } 3 5960 else 4 5961 { 4 5962 /* Matching precedence levels. 4 5963 For left association, keep only the reduction. Source Listing 31-MAR-2009 13:04:11 HP C V7.3-009-48GBT Page 5 25-JAN-1995 13:27:22 [LAISHEV.TOOLS.BISON-1_22]CONFLICTS.C;1 4 5964 For right association, keep only the shift. 4 5965 For nonassociation, keep neither. */ 4 5966 4 5967 switch (sassoc[i]) 5 5968 { 5 5969 5 5970 case RIGHT_ASSOC: 5 5971 if (verboseflag) log_resolution(state, lookaheadnum, i, "shift"); 5 5972 break; 5 5973 5 5974 case LEFT_ASSOC: 5 5975 if (verboseflag) log_resolution(state, lookaheadnum, i, "reduce"); 5 5976 break; 5 5977 5 5978 case NON_ASSOC: 5 5979 if (verboseflag) log_resolution(state, lookaheadnum, i, "an error"); 5 5980 break; 4 5981 } 4 5982 4 5983 if (sassoc[i] != RIGHT_ASSOC) 5 5984 { 5 5985 *fp2 &= ~mask; /* flush the shift for this token */ 5 5986 flush_shift(state, i); 4 5987 } 4 5988 if (sassoc[i] != LEFT_ASSOC) 5 5989 { 5 5990 *fp1 &= ~mask; /* flush the reduce for this token */ 4 5991 } 4 5992 if (sassoc[i] == NON_ASSOC) 5 5993 { 5 5994 /* Record an explicit error for this token. */ 5 5995 *errtokens++ = i; 4 5996 } 3 5997 } 2 5998 } 2 5999 2 6000 mask <<= 1; 2 6001 if (mask == 0) 3 6002 { 3 6003 mask = 1; 3 6004 fp2++; fp1++; 2 6005 } 1 6006 } 1 6007 errp->nerrs = errtokens - errp->errs; 1 6008 if (errp->nerrs) 2 6009 { 2 6010 /* Some tokens have been explicitly made errors. Allocate 2 6011 a permanent errs structure for this state, to record them. */ 2 6012 i = (char *) errtokens - (char *) errp; 2 6013 err_table[state] = (errs *) xmalloc ((unsigned int)i); 2 6014 bcopy (errp, err_table[state], i); 1 6015 } 1 6016 else 1 6017 err_table[state] = 0; 1 6018 } 6019 6020 Source Listing 31-MAR-2009 13:04:11 HP C V7.3-009-48GBT Page 6 25-JAN-1995 13:27:22 [LAISHEV.TOOLS.BISON-1_22]CONFLICTS.C;1 6021 6022 /* turn off the shift recorded for the specified token in the specified state. 6023 Used when we resolve a shift-reduce conflict in favor of the reduction. */ 6024 6025 void 6026 flush_shift(state, token) 6027 int state; 6028 int token; 1 6029 { 1 6030 register shifts *shiftp; 1 6031 register int k, i; 1 6032 /* register unsigned symbol; JF unused */ 1 6033 1 6034 shiftp = shift_table[state]; 1 6035 1 6036 if (shiftp) 2 6037 { 2 6038 k = shiftp->nshifts; 2 6039 for (i = 0; i < k; i++) 3 6040 { 3 6041 if (shiftp->shifts[i] && token == accessing_symbol[shiftp->shifts[i]]) 3 6042 (shiftp->shifts[i]) = 0; 2 6043 } 1 6044 } 1 6045 } 6046 6047 6048 void 6049 log_resolution(state, LAno, token, resolution) 6050 int state, LAno, token; 6051 char *resolution; 1 6052 { 1 6053 fprintf(foutput, 1 6054 "Conflict in state %d between rule %d and token %s resolved as %s.\n", 1 6055 state, LAruleno[LAno], tags[token], resolution); 1 6056 } 6057 6058 6059 void 6060 conflict_log() 1 6061 { 1 6062 register int i; 1 6063 1 6064 src_total = 0; 1 6065 rrc_total = 0; 1 6066 1 6067 for (i = 0; i < nstates; i++) 2 6068 { 2 6069 if (conflicts[i]) 3 6070 { 3 6071 count_sr_conflicts(i); 3 6072 count_rr_conflicts(i); 3 6073 src_total += src_count; 3 6074 rrc_total += rrc_count; 2 6075 } 1 6076 } 1 6077 Source Listing 31-MAR-2009 13:04:11 HP C V7.3-009-48GBT Page 7 25-JAN-1995 13:27:22 [LAISHEV.TOOLS.BISON-1_22]CONFLICTS.C;1 1 6078 total_conflicts(); 1 6079 } 6080 6081 6082 void 6083 verbose_conflict_log() 1 6084 { 1 6085 register int i; 1 6086 1 6087 src_total = 0; 1 6088 rrc_total = 0; 1 6089 1 6090 for (i = 0; i < nstates; i++) 2 6091 { 2 6092 if (conflicts[i]) 3 6093 { 3 6094 count_sr_conflicts(i); 3 6095 count_rr_conflicts(i); 3 6096 src_total += src_count; 3 6097 rrc_total += rrc_count; 3 6098 3 6099 fprintf(foutput, "State %d contains", i); 3 6100 3 6101 if (src_count == 1) 3 6102 fprintf(foutput, " 1 shift/reduce conflict"); 3 6103 else if (src_count > 1) 3 6104 fprintf(foutput, " %d shift/reduce conflicts", src_count); 3 6105 3 6106 if (src_count > 0 && rrc_count > 0) 3 6107 fprintf(foutput, " and"); 3 6108 3 6109 if (rrc_count == 1) 3 6110 fprintf(foutput, " 1 reduce/reduce conflict"); 3 6111 else if (rrc_count > 1) 3 6112 fprintf(foutput, " %d reduce/reduce conflicts", rrc_count); 3 6113 3 6114 putc('.', foutput); 3 6115 putc('\n', foutput); 2 6116 } 1 6117 } 1 6118 1 6119 total_conflicts(); 1 6120 } 6121 6122 6123 void 6124 total_conflicts() 1 6125 { 1 6126 extern int fixed_outfiles; 1 6127 1 6128 if (src_total == expected_conflicts && rrc_total == 0) 1 6129 return; 1 6130 1 6131 if (fixed_outfiles) 2 6132 { 2 6133 /* If invoked under the name `yacc', use the output format 2 6134 specified by POSIX. */ Source Listing 31-MAR-2009 13:04:11 HP C V7.3-009-48GBT Page 8 25-JAN-1995 13:27:22 [LAISHEV.TOOLS.BISON-1_22]CONFLICTS.C;1 2 6135 fprintf(stderr, "conflicts: "); 2 6136 if (src_total > 0) 2 6137 fprintf(stderr, " %d shift/reduce", src_total); 2 6138 if (src_total > 0 && rrc_total > 0) 2 6139 fprintf(stderr, ","); 2 6140 if (rrc_total > 0) 2 6141 fprintf(stderr, " %d reduce/reduce", rrc_total); 2 6142 putc('\n', stderr); 1 6143 } 1 6144 else 2 6145 { 2 6146 fprintf(stderr, "%s contains", infile); 2 6147 2 6148 if (src_total == 1) 2 6149 fprintf(stderr, " 1 shift/reduce conflict"); 2 6150 else if (src_total > 1) 2 6151 fprintf(stderr, " %d shift/reduce conflicts", src_total); 2 6152 2 6153 if (src_total > 0 && rrc_total > 0) 2 6154 fprintf(stderr, " and"); 2 6155 2 6156 if (rrc_total == 1) 2 6157 fprintf(stderr, " 1 reduce/reduce conflict"); 2 6158 else if (rrc_total > 1) 2 6159 fprintf(stderr, " %d reduce/reduce conflicts", rrc_total); 2 6160 2 6161 putc('.', stderr); 2 6162 putc('\n', stderr); 1 6163 } 1 6164 } 6165 6166 6167 void 6168 count_sr_conflicts(state) 6169 int state; 1 6170 { 1 6171 register int i; 1 6172 register int k; 1 6173 register int mask; 1 6174 register shifts *shiftp; 1 6175 register unsigned *fp1; 1 6176 register unsigned *fp2; 1 6177 register unsigned *fp3; 1 6178 register int symbol; 1 6179 1 6180 src_count = 0; 1 6181 1 6182 shiftp = shift_table[state]; 1 6183 if (!shiftp) return; 1 6184 1 6185 for (i = 0; i < tokensetsize; i++) 2 6186 { 2 6187 shiftset[i] = 0; 2 6188 lookaheadset[i] = 0; 1 6189 } 1 6190 1 6191 k = shiftp->nshifts; Source Listing 31-MAR-2009 13:04:11 HP C V7.3-009-48GBT Page 9 25-JAN-1995 13:27:22 [LAISHEV.TOOLS.BISON-1_22]CONFLICTS.C;1 1 6192 for (i = 0; i < k; i++) 2 6193 { 2 6194 if (! shiftp->shifts[i]) continue; 2 6195 symbol = accessing_symbol[shiftp->shifts[i]]; 2 6196 if (ISVAR(symbol)) break; 2 6197 SETBIT(shiftset, symbol); 1 6198 } 1 6199 1 6200 k = lookaheads[state + 1]; 1 6201 fp3 = lookaheadset + tokensetsize; 1 6202 1 6203 for (i = lookaheads[state]; i < k; i++) 2 6204 { 2 6205 fp1 = LA + i * tokensetsize; 2 6206 fp2 = lookaheadset; 2 6207 2 6208 while (fp2 < fp3) 2 6209 *fp2++ |= *fp1++; 1 6210 } 1 6211 1 6212 fp1 = shiftset; 1 6213 fp2 = lookaheadset; 1 6214 1 6215 while (fp2 < fp3) 1 6216 *fp2++ &= *fp1++; 1 6217 1 6218 mask = 1; 1 6219 fp2 = lookaheadset; 1 6220 for (i = 0; i < ntokens; i++) 2 6221 { 2 6222 if (mask & *fp2) 2 6223 src_count++; 2 6224 2 6225 mask <<= 1; 2 6226 if (mask == 0) 3 6227 { 3 6228 mask = 1; 3 6229 fp2++; 2 6230 } 1 6231 } 1 6232 } 6233 6234 6235 void 6236 count_rr_conflicts(state) 6237 int state; 1 6238 { 1 6239 register int i; 1 6240 register int j; 1 6241 register int count; 1 6242 register unsigned mask; 1 6243 register unsigned *baseword; 1 6244 register unsigned *wordp; 1 6245 register int m; 1 6246 register int n; 1 6247 1 6248 rrc_count = 0; Source Listing 31-MAR-2009 13:04:11 HP C V7.3-009-48GBT Page 10 25-JAN-1995 13:27:22 [LAISHEV.TOOLS.BISON-1_22]CONFLICTS.C;1 1 6249 1 6250 m = lookaheads[state]; 1 6251 n = lookaheads[state + 1]; 1 6252 1 6253 if (n - m < 2) return; 1 6254 1 6255 mask = 1; 1 6256 baseword = LA + m * tokensetsize; 1 6257 for (i = 0; i < ntokens; i++) 2 6258 { 2 6259 wordp = baseword; 2 6260 2 6261 count = 0; 2 6262 for (j = m; j < n; j++) 3 6263 { 3 6264 if (mask & *wordp) 3 6265 count++; 3 6266 3 6267 wordp += tokensetsize; 2 6268 } 2 6269 2 6270 if (count >= 2) rrc_count++; 2 6271 2 6272 mask <<= 1; 2 6273 if (mask == 0) 3 6274 { 3 6275 mask = 1; 3 6276 baseword++; 2 6277 } 1 6278 } 1 6279 } 6280 6281 6282 void 6283 print_reductions(state) 6284 int state; 1 6285 { 1 6286 register int i; 1 6287 register int j; 1 6288 register int k; 1 6289 register unsigned *fp1; 1 6290 register unsigned *fp2; 1 6291 register unsigned *fp3; 1 6292 register unsigned *fp4; 1 6293 register int rule; 1 6294 register int symbol; 1 6295 register unsigned mask; 1 6296 register int m; 1 6297 register int n; 1 6298 register int default_LA; 1 6299 register int default_rule; 1 6300 register int cmax; 1 6301 register int count; 1 6302 register shifts *shiftp; 1 6303 register errs *errp; 1 6304 int nodefault = 0; 1 6305 Source Listing 31-MAR-2009 13:04:11 HP C V7.3-009-48GBT Page 11 25-JAN-1995 13:27:22 [LAISHEV.TOOLS.BISON-1_22]CONFLICTS.C;1 1 6306 for (i = 0; i < tokensetsize; i++) 1 6307 shiftset[i] = 0; 1 6308 1 6309 shiftp = shift_table[state]; 1 6310 if (shiftp) 2 6311 { 2 6312 k = shiftp->nshifts; 2 6313 for (i = 0; i < k; i++) 3 6314 { 3 6315 if (! shiftp->shifts[i]) continue; 3 6316 symbol = accessing_symbol[shiftp->shifts[i]]; 3 6317 if (ISVAR(symbol)) break; 3 6318 /* if this state has a shift for the error token, 3 6319 don't use a default rule. */ 3 6320 if (symbol == error_token_number) nodefault = 1; 3 6321 SETBIT(shiftset, symbol); 2 6322 } 1 6323 } 1 6324 1 6325 errp = err_table[state]; 1 6326 if (errp) 2 6327 { 2 6328 k = errp->nerrs; 2 6329 for (i = 0; i < k; i++) 3 6330 { 3 6331 if (! errp->errs[i]) continue; 3 6332 symbol = errp->errs[i]; 3 6333 SETBIT(shiftset, symbol); 2 6334 } 1 6335 } 1 6336 1 6337 m = lookaheads[state]; 1 6338 n = lookaheads[state + 1]; 1 6339 1 6340 if (n - m == 1 && ! nodefault) 2 6341 { 2 6342 default_rule = LAruleno[m]; 2 6343 2 6344 fp1 = LA + m * tokensetsize; 2 6345 fp2 = shiftset; 2 6346 fp3 = lookaheadset; 2 6347 fp4 = lookaheadset + tokensetsize; 2 6348 2 6349 while (fp3 < fp4) 2 6350 *fp3++ = *fp1++ & *fp2++; 2 6351 2 6352 mask = 1; 2 6353 fp3 = lookaheadset; 2 6354 2 6355 for (i = 0; i < ntokens; i++) 3 6356 { 3 6357 if (mask & *fp3) 3 6358 fprintf(foutput, " %-4s\t[reduce using rule %d (%s)]\n", 3 6359 tags[i], default_rule, tags[rlhs[default_rule]]); 3 6360 3 6361 mask <<= 1; 3 6362 if (mask == 0) Source Listing 31-MAR-2009 13:04:11 HP C V7.3-009-48GBT Page 12 25-JAN-1995 13:27:22 [LAISHEV.TOOLS.BISON-1_22]CONFLICTS.C;1 4 6363 { 4 6364 mask = 1; 4 6365 fp3++; 3 6366 } 2 6367 } 2 6368 2 6369 fprintf(foutput, " $default\treduce using rule %d (%s)\n\n", 2 6370 default_rule, tags[rlhs[default_rule]]); 1 6371 } 1 6372 else if (n - m >= 1) 2 6373 { 2 6374 cmax = 0; 2 6375 default_LA = -1; 2 6376 fp4 = lookaheadset + tokensetsize; 2 6377 2 6378 if (! nodefault) 2 6379 for (i = m; i < n; i++) 3 6380 { 3 6381 fp1 = LA + i * tokensetsize; 3 6382 fp2 = shiftset; 3 6383 fp3 = lookaheadset; 3 6384 3 6385 while (fp3 < fp4) 3 6386 *fp3++ = *fp1++ & ( ~ (*fp2++)); 3 6387 3 6388 count = 0; 3 6389 mask = 1; 3 6390 fp3 = lookaheadset; 3 6391 for (j = 0; j < ntokens; j++) 4 6392 { 4 6393 if (mask & *fp3) 4 6394 count++; 4 6395 4 6396 mask <<= 1; 4 6397 if (mask == 0) 5 6398 { 5 6399 mask = 1; 5 6400 fp3++; 4 6401 } 3 6402 } 3 6403 3 6404 if (count > cmax) 4 6405 { 4 6406 cmax = count; 4 6407 default_LA = i; 4 6408 default_rule = LAruleno[i]; 3 6409 } 3 6410 3 6411 fp2 = shiftset; 3 6412 fp3 = lookaheadset; 3 6413 3 6414 while (fp3 < fp4) 3 6415 *fp2++ |= *fp3++; 2 6416 } 2 6417 2 6418 for (i = 0; i < tokensetsize; i++) 2 6419 shiftset[i] = 0; Source Listing 31-MAR-2009 13:04:11 HP C V7.3-009-48GBT Page 13 25-JAN-1995 13:27:22 [LAISHEV.TOOLS.BISON-1_22]CONFLICTS.C;1 2 6420 2 6421 if (shiftp) 3 6422 { 3 6423 k = shiftp->nshifts; 3 6424 for (i = 0; i < k; i++) 4 6425 { 4 6426 if (! shiftp->shifts[i]) continue; 4 6427 symbol = accessing_symbol[shiftp->shifts[i]]; 4 6428 if (ISVAR(symbol)) break; 4 6429 SETBIT(shiftset, symbol); 3 6430 } 2 6431 } 2 6432 2 6433 mask = 1; 2 6434 fp1 = LA + m * tokensetsize; 2 6435 fp2 = shiftset; 2 6436 for (i = 0; i < ntokens; i++) 3 6437 { 3 6438 int defaulted = 0; 3 6439 3 6440 if (mask & *fp2) 3 6441 count = 1; 3 6442 else 3 6443 count = 0; 3 6444 3 6445 fp3 = fp1; 3 6446 for (j = m; j < n; j++) 4 6447 { 4 6448 if (mask & *fp3) 5 6449 { 5 6450 if (count == 0) 6 6451 { 6 6452 if (j != default_LA) 7 6453 { 7 6454 rule = LAruleno[j]; 7 6455 fprintf(foutput, " %-4s\treduce using rule %d (%s)\n", 7 6456 tags[i], rule, tags[rlhs[rule]]); 6 6457 } 6 6458 else defaulted = 1; 6 6459 6 6460 count++; 5 6461 } 5 6462 else 6 6463 { 6 6464 if (defaulted) 7 6465 { 7 6466 rule = LAruleno[default_LA]; 7 6467 fprintf(foutput, " %-4s\treduce using rule %d (%s)\n", 7 6468 tags[i], rule, tags[rlhs[rule]]); 7 6469 defaulted = 0; 6 6470 } 6 6471 rule = LAruleno[j]; 6 6472 fprintf(foutput, " %-4s\t[reduce using rule %d (%s)]\n", 6 6473 tags[i], rule, tags[rlhs[rule]]); 5 6474 } 4 6475 } 4 6476 Source Listing 31-MAR-2009 13:04:11 HP C V7.3-009-48GBT Page 14 25-JAN-1995 13:27:22 [LAISHEV.TOOLS.BISON-1_22]CONFLICTS.C;1 4 6477 fp3 += tokensetsize; 3 6478 } 3 6479 3 6480 mask <<= 1; 3 6481 if (mask == 0) 4 6482 { 4 6483 mask = 1; 4 6484 /* This used to be fp1, but I think fp2 is right 4 6485 because fp2 is where the words are fetched to test with mask 4 6486 in this loop. */ 4 6487 fp2++; 3 6488 } 2 6489 } 2 6490 2 6491 if (default_LA >= 0) 3 6492 { 3 6493 fprintf(foutput, " $default\treduce using rule %d (%s)\n", 3 6494 default_rule, tags[rlhs[default_rule]]); 2 6495 } 2 6496 2 6497 putc('\n', foutput); 1 6498 } 1 6499 } 6500 6501 6502 void 6503 finalize_conflicts() 1 6504 { 1 6505 FREE(conflicts); 1 6506 FREE(shiftset); 1 6507 FREE(lookaheadset); 1 6508 } Command Line ------- ---- CC/INCLU=[]/LIS CONFLICTS.C Hardware: /ARCHITECTURE=GENERIC /OPTIMIZE=TUNE=GENERIC These macros are in effect at the start of the compilation. ----- ------ --- -- ------ -- --- ----- -- --- ------------ __G_FLOAT=1 __DECC=1 vms=1 VMS=1 __32BITS=1 __PRAGMA_ENVIRONMENT=1 __CRTL_VER=80300000 __vms_version="V8.3 " CC$gfloat=1 __X_FLOAT=1 vms_version="V8.3 " __DATE__="Mar 31 2009" __STDC_VERSION__=199901L __DECC_MODE_RELAXED=1 __DECC_VER=70390009 __VMS=1 __ALPHA=1 VMS_VERSION="V8.3 " __IEEE_FLOAT=0 __VMS_VERSION="V8.3 " __TIME__="13:04:11" __Alpha_AXP=1 __VMS_VER=80300022 __BIASED_FLT_ROUNDS=2 __INITIAL_POINTER_SIZE=0 __STDC__=2 __LANGUAGE_C__=1 __vms=1 __alpha=1 __D_FLOAT=0