main.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /* Top level entry point of bison,
  2. Copyright (C) 1984, 1986 Bob Corbett and Free Software Foundation, Inc.
  3. BISON is distributed in the hope that it will be useful, but WITHOUT ANY
  4. WARRANTY. No author or distributor accepts responsibility to anyone
  5. for the consequences of using it or for whether it serves any
  6. particular purpose or works at all, unless he says so in writing.
  7. Refer to the BISON General Public License for full details.
  8. Everyone is granted permission to copy, modify and redistribute BISON,
  9. but only under the conditions described in the BISON General Public
  10. License. A copy of this license is supposed to have been given to you
  11. along with BISON so you can know your rights and responsibilities. It
  12. should be in a file named COPYING. Among other things, the copyright
  13. notice and this notice must be preserved on all copies.
  14. In other words, you are welcome to use, share and improve this program.
  15. You are forbidden to forbid anyone else to use, share and improve
  16. what you give them. Help stamp out software-hoarding! */
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include "machine.h" /* JF for MAXSHORT */
  20. extern int lineno;
  21. extern int verboseflag;
  22. extern void getargs (int argc, char *argv[]);
  23. extern void openfiles (void);
  24. extern void reader (void);
  25. extern void set_derives (void);
  26. extern void set_nullable (void);
  27. extern void generate_states (void);
  28. extern void lalr (void);
  29. extern void initialize_conflicts (void);
  30. extern void verbose (void);
  31. extern void terse (void);
  32. extern void output (void);
  33. extern void done (int k);
  34. /* Nonzero means failure has been detected; don't write a parser file. */
  35. int failure;
  36. int main (int argc, char *argv[])
  37. {
  38. failure = 0;
  39. lineno = 0;
  40. getargs(argc, argv);
  41. openfiles();
  42. /* read the input. Copy some parts of it to fguard, faction, ftable and fattrs.
  43. In file reader.
  44. The other parts are recorded in the grammar; see gram.h. */
  45. reader();
  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. Currently this does not do anything to resolve them;
  57. the trivial form of conflict resolution that exists is done in output. */
  58. initialize_conflicts();
  59. /* print information about results, if requested. In file print. */
  60. if (verboseflag)
  61. verbose();
  62. else
  63. terse();
  64. /* output the tables and the parser to ftable. In file output. */
  65. output();
  66. done(failure);
  67. return (0);
  68. }
  69. /* functions to report errors which prevent a parser from being generated */
  70. void fatal (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. Is a real kludge since
  80. we don't support _doprnt calls */
  81. /*VARARGS1*/
  82. /* fatals(fmt,x1,x2,x3,x4,x5,x6,x7,x8)
  83. void fatals(char *fmt,void *x1,void *x2,void *x3,void *x4,void *x5,void *x6,void *x7,void *x8)
  84. {
  85. char buffer[200];
  86. sprintf(buffer, fmt, x1,x2,x3,x4,x5,x6,x7,x8);
  87. fatal(buffer);
  88. }
  89. */
  90. void toomany (char *s)
  91. {
  92. char buffer[200];
  93. /* JF new msg */
  94. sprintf(buffer, "limit of %d exceeded, too many %s", MAXSHORT, s);
  95. fatal(buffer);
  96. }
  97. void berror (char *s)
  98. {
  99. fprintf(stderr, "internal error, %s\n", s);
  100. abort();
  101. }