MAIN.C 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /* Top level entry point of bison,
  2. Copyright (C) 1984, 1986, 1989 Free Software Foundation, Inc.
  3. This file is part of Bison, the GNU Compiler Compiler.
  4. Bison is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 1, or (at your option)
  7. any later version.
  8. Bison is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with Bison; see the file COPYING. If not, write to
  14. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
  15. #include <stdio.h>
  16. #include "system.h"
  17. #include "machine.h" /* JF for MAXSHORT */
  18. extern int lineno;
  19. extern int verboseflag;
  20. /* Nonzero means failure has been detected; don't write a parser file. */
  21. int failure;
  22. extern void getargs(), openfiles(), reader(), reduce_grammar();
  23. extern void set_derives(), set_nullable(), generate_states();
  24. extern void lalr(), initialize_conflicts(), verbose(), terse();
  25. extern void output(), done(), abort();
  26. void
  27. main(argc, argv)
  28. int argc;
  29. char *argv[];
  30. {
  31. failure = 0;
  32. lineno = 0;
  33. getargs(argc, argv);
  34. openfiles();
  35. /* read the input. Copy some parts of it to fguard, faction, ftable and fattrs.
  36. In file reader.c.
  37. The other parts are recorded in the grammar; see gram.h. */
  38. reader();
  39. /* find useless nonterminals and productions and reduce the grammar. In
  40. file reduce.c */
  41. reduce_grammar();
  42. /* record other info about the grammar. In files derives and nullable. */
  43. set_derives();
  44. set_nullable();
  45. /* convert to nondeterministic finite state machine. In file LR0.
  46. See state.h for more info. */
  47. generate_states();
  48. /* make it deterministic. In file lalr. */
  49. lalr();
  50. /* Find and record any conflicts: places where one token of lookahead is not
  51. enough to disambiguate the parsing. In file conflicts.
  52. Currently this does not do anything to resolve them;
  53. the trivial form of conflict resolution that exists is done in output. */
  54. initialize_conflicts();
  55. /* print information about results, if requested. In file print. */
  56. if (verboseflag)
  57. verbose();
  58. else
  59. terse();
  60. /* output the tables and the parser to ftable. In file output. */
  61. output();
  62. done(failure);
  63. }
  64. /* functions to report errors which prevent a parser from being generated */
  65. void
  66. fatal(s)
  67. char *s;
  68. {
  69. extern char *infile;
  70. if (infile == 0)
  71. fprintf(stderr, "fatal error: %s\n", s);
  72. else
  73. fprintf(stderr, "\"%s\", line %d: %s\n", infile, lineno, s);
  74. done(1);
  75. }
  76. /* JF changed to accept/deal with variable args. Is a real kludge since
  77. we don't support _doprnt calls */
  78. /*VARARGS1*/
  79. void
  80. fatals(fmt,x1,x2,x3,x4,x5,x6,x7,x8)
  81. char *fmt;
  82. {
  83. char buffer[200];
  84. sprintf(buffer, fmt, x1,x2,x3,x4,x5,x6,x7,x8);
  85. fatal(buffer);
  86. }
  87. void
  88. toomany(s)
  89. char *s;
  90. {
  91. char buffer[200];
  92. /* JF new msg */
  93. sprintf(buffer, "limit of %d exceeded, too many %s", MAXSHORT, s);
  94. fatal(buffer);
  95. }
  96. void
  97. berror(s)
  98. char *s;
  99. {
  100. fprintf(stderr, "internal error, %s\n", s);
  101. abort();
  102. }