main.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 2, 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. /* The name this program was run with, for messages. */
  23. char *program_name;
  24. extern void getargs(), openfiles(), reader(), reduce_grammar();
  25. extern void set_derives(), set_nullable(), generate_states();
  26. extern void lalr(), initialize_conflicts(), verbose(), terse();
  27. extern void output(), done();
  28. /* VMS complained about using `int'. */
  29. int
  30. main(argc, argv)
  31. int argc;
  32. char *argv[];
  33. {
  34. program_name = argv[0];
  35. failure = 0;
  36. lineno = 0;
  37. getargs(argc, argv);
  38. openfiles();
  39. /* read the input. Copy some parts of it to fguard, faction, ftable and fattrs.
  40. In file reader.c.
  41. The other parts are recorded in the grammar; see gram.h. */
  42. reader();
  43. /* find useless nonterminals and productions and reduce the grammar. In
  44. file reduce.c */
  45. reduce_grammar();
  46. /* record other info about the grammar. In files derives and nullable. */
  47. set_derives();
  48. set_nullable();
  49. /* convert to nondeterministic finite state machine. In file LR0.
  50. See state.h for more info. */
  51. generate_states();
  52. /* make it deterministic. In file lalr. */
  53. lalr();
  54. /* Find and record any conflicts: places where one token of lookahead is not
  55. enough to disambiguate the parsing. In file conflicts.
  56. Also resolve s/r conflicts based on precedence declarations. */
  57. initialize_conflicts();
  58. /* print information about results, if requested. In file print. */
  59. if (verboseflag)
  60. verbose();
  61. else
  62. terse();
  63. /* output the tables and the parser to ftable. In file output. */
  64. output();
  65. done(failure);
  66. }
  67. /* functions to report errors which prevent a parser from being generated */
  68. void
  69. fatal(s)
  70. char *s;
  71. {
  72. extern char *infile;
  73. if (infile == 0)
  74. fprintf(stderr, "fatal error: %s\n", s);
  75. else
  76. fprintf(stderr, "\"%s\", line %d: %s\n", infile, lineno, s);
  77. done(1);
  78. }
  79. /* JF changed to accept/deal with variable args.
  80. DO NOT change this to use varargs. It will appear to work
  81. but will break on systems that don't have the necessary library
  82. functions. This is the ONLY safe way to write such a function. */
  83. /*VARARGS1*/
  84. void
  85. fatals(fmt,x1,x2,x3,x4,x5,x6,x7,x8)
  86. char *fmt;
  87. {
  88. char buffer[200];
  89. sprintf(buffer, fmt, x1,x2,x3,x4,x5,x6,x7,x8);
  90. fatal(buffer);
  91. }
  92. void
  93. toomany(s)
  94. char *s;
  95. {
  96. char buffer[200];
  97. /* JF new msg */
  98. sprintf(buffer, "limit of %d exceeded, too many %s", MAXSHORT, s);
  99. fatal(buffer);
  100. }
  101. void
  102. berror(s)
  103. char *s;
  104. {
  105. fprintf(stderr, "internal error, %s\n", s);
  106. abort();
  107. }