main.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 "machine.h" /* JF for MAXSHORT */
  19. extern int lineno;
  20. extern int verboseflag;
  21. main(argc, argv)
  22. int argc;
  23. char *argv[];
  24. {
  25. lineno = 0;
  26. getargs(argc, argv);
  27. openfiles();
  28. /* read the input. Copy some parts of it to fguard, faction, ftable and fattrs.
  29. In file reader.
  30. The other parts are recorded in the grammar; see gram.h. */
  31. reader();
  32. /* record other info about the grammar. In files derives and nullable. */
  33. set_derives();
  34. set_nullable();
  35. /* convert to nondeterministic finite state machine. In file LR0.
  36. See state.h for more info. */
  37. generate_states();
  38. /* make it deterministic. In file lalr. */
  39. lalr();
  40. /* Find and record any conflicts: places where one token of lookahead is not
  41. enough to disambiguate the parsing. In file conflicts.
  42. Currently this does not do anything to resolve them;
  43. the trivial form of conflict resolution that exists is done in output. */
  44. initialize_conflicts();
  45. /* print information about results, if requested. In file print. */
  46. if (verboseflag)
  47. verbose();
  48. else
  49. terse();
  50. /* output the tables and the parser to ftable. In file output. */
  51. output();
  52. done(0);
  53. }
  54. /* functions to report errors which prevent a parser from being generated */
  55. /* JF changed to output error message in standard format. Just like CC */
  56. fatal(s)
  57. char *s;
  58. {
  59. extern char *infile;
  60. fprintf(stderr, "\"%s\", line %d: %s\n", infile, lineno, s);
  61. done(1);
  62. }
  63. /* JF changed to accept/deal with variable args. Is a real kludge since
  64. we don't support _doprnt calls */
  65. /*VARARGS1*/
  66. fatals(fmt,x1,x2,x3,x4,x5,x6,x7,x8)
  67. char *fmt;
  68. {
  69. char buffer[200];
  70. sprintf(buffer, fmt, x1,x2,x3,x4,x5,x6,x7,x8);
  71. fatal(buffer);
  72. }
  73. toomany(s)
  74. char *s;
  75. {
  76. char buffer[200];
  77. /* JF new msg */
  78. sprintf(buffer, "limit of %d exceeded, too many %s", MAXSHORT, s);
  79. fatal(buffer);
  80. }
  81. berror(s)
  82. char *s;
  83. {
  84. fprintf(stderr, "internal error, %s\n", s);
  85. abort();
  86. }