home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / bison / main.c < prev    next >
C/C++ Source or Header  |  1990-07-01  |  3KB  |  134 lines

  1. /* Top level entry point of bison,
  2.    Copyright (C) 1984, 1986, 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 1, 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. #include <stdio.h>
  22. #include "system.h"
  23. #include "machine.h"    /* JF for MAXSHORT */
  24.  
  25. extern    int lineno;
  26. extern    int verboseflag;
  27.  
  28. /* Nonzero means failure has been detected; don't write a parser file.  */
  29. int failure;
  30.  
  31. extern void getargs(), openfiles(), reader(), reduce_grammar();
  32. extern void set_derives(), set_nullable(), generate_states();
  33. extern void lalr(), initialize_conflicts(), verbose(), terse();
  34. extern void output(), done(), abort();
  35.  
  36.  
  37. void
  38. main(argc, argv)
  39. int argc;
  40. char *argv[];
  41. {
  42.   failure = 0;
  43.   lineno = 0;
  44.   getargs(argc, argv);
  45.   openfiles();
  46.  
  47.   /* read the input.  Copy some parts of it to fguard, faction, ftable and fattrs.
  48.      In file reader.c.
  49.      The other parts are recorded in the grammar; see gram.h.  */
  50.   reader();
  51.  
  52.   /* find useless nonterminals and productions and reduce the grammar.  In
  53.      file reduce.c */
  54.   reduce_grammar();
  55.  
  56.   /* record other info about the grammar.  In files derives and nullable.  */
  57.   set_derives();
  58.   set_nullable();
  59.  
  60.   /* convert to nondeterministic finite state machine.  In file LR0.
  61.      See state.h for more info.  */
  62.   generate_states();
  63.  
  64.   /* make it deterministic.  In file lalr.  */
  65.   lalr();
  66.  
  67.   /* Find and record any conflicts: places where one token of lookahead is not
  68.      enough to disambiguate the parsing.  In file conflicts.
  69.      Currently this does not do anything to resolve them;
  70.      the trivial form of conflict resolution that exists is done in output.  */
  71.   initialize_conflicts();
  72.  
  73.   /* print information about results, if requested.  In file print. */
  74.   if (verboseflag)
  75.     verbose();
  76.   else
  77.     terse();
  78.  
  79.   /* output the tables and the parser to ftable.  In file output. */
  80.   output();
  81.   done(failure);
  82. }
  83.  
  84. /* functions to report errors which prevent a parser from being generated */
  85.  
  86. void
  87. fatal(s)
  88. char *s;
  89. {
  90.   extern char *infile;
  91.  
  92.   if (infile == 0)
  93.     fprintf(stderr, "\nfatal error: %s\n", s);
  94.   else
  95.     fprintf(stderr, "\n\"%s\", line %d: %s\n", infile, lineno, s);
  96.   done(1);
  97. }
  98.  
  99.  
  100. /* JF changed to accept/deal with variable args.  Is a real kludge since
  101.    we don't support _doprnt calls */
  102. /*VARARGS1*/
  103.  
  104. void
  105. fatals(fmt,x1,x2,x3,x4,x5,x6,x7,x8)
  106. char *fmt;
  107. {
  108.   char buffer[200];
  109.  
  110.   sprintf(buffer, fmt, x1,x2,x3,x4,x5,x6,x7,x8);
  111.   fatal(buffer);
  112. }
  113.  
  114.  
  115. void
  116. toomany(s)
  117. char *s;
  118. {
  119.   char buffer[200];
  120.  
  121.     /* JF new msg */
  122.   sprintf(buffer, "limit of %d exceeded, too many %s", MAXSHORT, s);
  123.   fatal(buffer);
  124. }
  125.  
  126.  
  127. void
  128. berror(s)
  129. char *s;
  130. {
  131.   fprintf(stderr, "internal error, %s\n", s);
  132.   abort();
  133. }
  134.