Source Listing 31-MAR-2009 13:04:12 HP C V7.3-009-48GBT Page 1 18-DEC-1991 04:05:30 [LAISHEV.TOOLS.BISON-1_22]DERIVES.C;1 1 /* Match rules with nonterminals 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 20 21 /* set_derives finds, for each variable (nonterminal), which rules can derive it. 22 It sets up the value of derives so that 23 derives[i - ntokens] points to a vector of rule numbers, 24 terminated with -1. */ 25 26 #include 1625 #include "system.h" 4177 #include "new.h" 4209 #include "types.h" 4237 #include "gram.h" 4358 4359 4360 short **derives; 4361 4362 void 4363 set_derives() 1 4364 { 1 4365 register int i; 1 4366 register int lhs; 1 4367 register shorts *p; 1 4368 register short *q; 1 4369 register shorts **dset; 1 4370 register shorts *delts; 1 4371 1 4372 dset = NEW2(nvars, shorts *) - ntokens; 1 4373 delts = NEW2(nrules + 1, shorts); 1 4374 1 4375 p = delts; 1 4376 for (i = nrules; i > 0; i--) 2 4377 { 2 4378 lhs = rlhs[i]; 2 4379 if (lhs >= 0) 3 4380 { 3 4381 p->next = dset[lhs]; 3 4382 p->value = i; 3 4383 dset[lhs] = p; 3 4384 p++; Source Listing 31-MAR-2009 13:04:12 HP C V7.3-009-48GBT Page 2 18-DEC-1991 04:05:30 [LAISHEV.TOOLS.BISON-1_22]DERIVES.C;1 2 4385 } 1 4386 } 1 4387 1 4388 derives = NEW2(nvars, short *) - ntokens; 1 4389 q = NEW2(nvars + nrules, short); 1 4390 1 4391 for (i = ntokens; i < nsyms; i++) 2 4392 { 2 4393 derives[i] = q; 2 4394 p = dset[i]; 2 4395 while (p) 3 4396 { 3 4397 *q++ = p->value; 3 4398 p = p->next; 2 4399 } 2 4400 *q++ = -1; 1 4401 } 1 4402 1X 4403 #ifdef DEBUG 1X 4404 print_derives(); 1X 4405 #endif 1 4406 1 4407 FREE(dset + ntokens); 1 4408 FREE(delts); 1 4409 } 4410 4411 void 4412 free_derives() 1 4413 { 1 4414 FREE(derives[ntokens]); 1 4415 FREE(derives + ntokens); 1 4416 } 4417 4418 4419 X 4420 #ifdef DEBUG X 4421 X 4422 print_derives() X 4423 { X 4424 register int i; X 4425 register short *sp; X 4426 X 4427 extern char **tags; X 4428 X 4429 printf("\n\n\nDERIVES\n\n"); X 4430 X 4431 for (i = ntokens; i < nsyms; i++) X 4432 { X 4433 printf("%s derives", tags[i]); X 4434 for (sp = derives[i]; *sp > 0; sp++) X 4435 { X 4436 printf(" %d", *sp); X 4437 } X 4438 putchar('\n'); X 4439 } X 4440 X 4441 putchar('\n'); Source Listing 31-MAR-2009 13:04:12 HP C V7.3-009-48GBT Page 3 18-DEC-1991 04:05:30 [LAISHEV.TOOLS.BISON-1_22]DERIVES.C;1 X 4442 } X 4443 X 4444 #endif 4445 Command Line ------- ---- CC/INCLU=[]/LIS DERIVES.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:12" __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