lalr.c (214959) | lalr.c (214961) |
---|---|
1/* 2 * Copyright (c) 1989 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Robert Paul Corbett. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 27 unchanged lines hidden (view full) --- 36 37#if 0 38#ifndef lint 39static char sccsid[] = "@(#)lalr.c 5.3 (Berkeley) 6/1/90"; 40#endif 41#endif 42 43#include <sys/cdefs.h> | 1/* 2 * Copyright (c) 1989 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Robert Paul Corbett. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 27 unchanged lines hidden (view full) --- 36 37#if 0 38#ifndef lint 39static char sccsid[] = "@(#)lalr.c 5.3 (Berkeley) 6/1/90"; 40#endif 41#endif 42 43#include <sys/cdefs.h> |
44__FBSDID("$FreeBSD: head/usr.bin/yacc/lalr.c 214959 2010-11-07 22:51:54Z obrien $"); | 44__FBSDID("$FreeBSD: head/usr.bin/yacc/lalr.c 214961 2010-11-07 23:22:42Z obrien $"); |
45 46#include <limits.h> 47#include <stdlib.h> 48#include "defs.h" 49 50typedef 51 struct shorts 52 { --- 235 unchanged lines hidden (view full) --- 288 if (ISTOKEN(symbol)) break; 289 290 k = temp_map[symbol]++; 291 from_state[k] = state1; 292 to_state[k] = state2; 293 } 294 } 295 | 45 46#include <limits.h> 47#include <stdlib.h> 48#include "defs.h" 49 50typedef 51 struct shorts 52 { --- 235 unchanged lines hidden (view full) --- 288 if (ISTOKEN(symbol)) break; 289 290 k = temp_map[symbol]++; 291 from_state[k] = state1; 292 to_state[k] = state2; 293 } 294 } 295 |
296 FREE(temp_map + ntokens); | 296 free(temp_map + ntokens); |
297} 298 299 300 301/* Map_goto maps a state/symbol pair into its numeric representation. */ 302 303static int 304map_goto(int state, int symbol) --- 86 unchanged lines hidden (view full) --- 391 } 392 393 SETBIT(F, 0); 394 digraph(reads); 395 396 for (i = 0; i < ngotos; i++) 397 { 398 if (reads[i]) | 297} 298 299 300 301/* Map_goto maps a state/symbol pair into its numeric representation. */ 302 303static int 304map_goto(int state, int symbol) --- 86 unchanged lines hidden (view full) --- 391 } 392 393 SETBIT(F, 0); 394 digraph(reads); 395 396 for (i = 0; i < ngotos; i++) 397 { 398 if (reads[i]) |
399 FREE(reads[i]); | 399 free(reads[i]); |
400 } 401 | 400 } 401 |
402 FREE(reads); 403 FREE(edge); | 402 free(reads); 403 free(edge); |
404} 405 406 407 408static void 409build_relations(void) 410{ 411 int i; --- 70 unchanged lines hidden (view full) --- 482 shortp[nedges] = -1; 483 } 484 } 485 486 new_includes = transpose(includes, ngotos); 487 488 for (i = 0; i < ngotos; i++) 489 if (includes[i]) | 404} 405 406 407 408static void 409build_relations(void) 410{ 411 int i; --- 70 unchanged lines hidden (view full) --- 482 shortp[nedges] = -1; 483 } 484 } 485 486 new_includes = transpose(includes, ngotos); 487 488 for (i = 0; i < ngotos; i++) 489 if (includes[i]) |
490 FREE(includes[i]); | 490 free(includes[i]); |
491 | 491 |
492 FREE(includes); | 492 free(includes); |
493 494 includes = new_includes; 495 | 493 494 includes = new_includes; 495 |
496 FREE(edge); 497 FREE(states); | 496 free(edge); 497 free(states); |
498} 499 500 501static void 502add_lookback_edge(int stateno, int ruleno, int gotono) 503{ 504 int i, k; 505 int found; --- 51 unchanged lines hidden (view full) --- 557 { 558 sp = NEW2(k + 1, short); 559 new_R[i] = sp; 560 temp_R[i] = sp; 561 sp[k] = -1; 562 } 563 } 564 | 498} 499 500 501static void 502add_lookback_edge(int stateno, int ruleno, int gotono) 503{ 504 int i, k; 505 int found; --- 51 unchanged lines hidden (view full) --- 557 { 558 sp = NEW2(k + 1, short); 559 new_R[i] = sp; 560 temp_R[i] = sp; 561 sp[k] = -1; 562 } 563 } 564 |
565 FREE(nedges); | 565 free(nedges); |
566 567 for (i = 0; i < n; i++) 568 { 569 sp = R[i]; 570 if (sp) 571 { 572 while (*sp >= 0) 573 *temp_R[*sp++]++ = i; 574 } 575 } 576 | 566 567 for (i = 0; i < n; i++) 568 { 569 sp = R[i]; 570 if (sp) 571 { 572 while (*sp >= 0) 573 *temp_R[*sp++]++ = i; 574 } 575 } 576 |
577 FREE(temp_R); | 577 free(temp_R); |
578 579 return (new_R); 580} 581 582 583 584static void 585compute_FOLLOWS(void) --- 24 unchanged lines hidden (view full) --- 610 } 611 rowp = fp3; 612 } 613 614 for (i = 0; i < n; i++) 615 for (sp = lookback[i]; sp; sp = next) 616 { 617 next = sp->next; | 578 579 return (new_R); 580} 581 582 583 584static void 585compute_FOLLOWS(void) --- 24 unchanged lines hidden (view full) --- 610 } 611 rowp = fp3; 612 } 613 614 for (i = 0; i < n; i++) 615 for (sp = lookback[i]; sp; sp = next) 616 { 617 next = sp->next; |
618 FREE(sp); | 618 free(sp); |
619 } 620 | 619 } 620 |
621 FREE(lookback); 622 FREE(F); | 621 free(lookback); 622 free(F); |
623} 624 625 626static void 627digraph(short **relation) 628{ 629 int i; 630 --- 6 unchanged lines hidden (view full) --- 637 INDEX[i] = 0; 638 639 for (i = 0; i < ngotos; i++) 640 { 641 if (INDEX[i] == 0 && relation[i]) 642 traverse(i, relation); 643 } 644 | 623} 624 625 626static void 627digraph(short **relation) 628{ 629 int i; 630 --- 6 unchanged lines hidden (view full) --- 637 INDEX[i] = 0; 638 639 for (i = 0; i < ngotos; i++) 640 { 641 if (INDEX[i] == 0 && relation[i]) 642 traverse(i, relation); 643 } 644 |
645 FREE(INDEX); 646 FREE(VERTICES); | 645 free(INDEX); 646 free(VERTICES); |
647} 648 649 650 651static void 652traverse(int i, short **R) 653{ 654 unsigned *fp1; --- 51 unchanged lines hidden --- | 647} 648 649 650 651static void 652traverse(int i, short **R) 653{ 654 unsigned *fp1; --- 51 unchanged lines hidden --- |