]> git.saurik.com Git - bison.git/blame - src/main.c
entered into RCS
[bison.git] / src / main.c
CommitLineData
54bd0db4
RS
1/* Top level entry point of bison,
2 Copyright (C) 1984, 1986, 1989 Free Software Foundation, Inc.
3
4This file is part of Bison, the GNU Compiler Compiler.
5
6Bison is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11Bison is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with Bison; see the file COPYING. If not, write to
18the 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
25extern int lineno;
26extern int verboseflag;
27
28/* Nonzero means failure has been detected; don't write a parser file. */
29int failure;
30
31/* The name this program was run with, for messages. */
32char *program_name;
33
34extern void getargs(), openfiles(), reader(), reduce_grammar();
35extern void set_derives(), set_nullable(), generate_states();
36extern void lalr(), initialize_conflicts(), verbose(), terse();
37extern void output(), done();
38
39
40/* VMS complained about using `int'. */
41int
42main(argc, argv)
43int argc;
44char *argv[];
45{
46 program_name = argv[0];
47 failure = 0;
48 lineno = 0;
49 getargs(argc, argv);
50 openfiles();
51
52 /* read the input. Copy some parts of it to fguard, faction, ftable and fattrs.
53 In file reader.c.
54 The other parts are recorded in the grammar; see gram.h. */
55 reader();
56
57 /* find useless nonterminals and productions and reduce the grammar. In
58 file reduce.c */
59 reduce_grammar();
60
61 /* record other info about the grammar. In files derives and nullable. */
62 set_derives();
63 set_nullable();
64
65 /* convert to nondeterministic finite state machine. In file LR0.
66 See state.h for more info. */
67 generate_states();
68
69 /* make it deterministic. In file lalr. */
70 lalr();
71
72 /* Find and record any conflicts: places where one token of lookahead is not
73 enough to disambiguate the parsing. In file conflicts.
fe01694d 74 Also resolve s/r conflicts based on precedence declarations. */
54bd0db4
RS
75 initialize_conflicts();
76
77 /* print information about results, if requested. In file print. */
78 if (verboseflag)
79 verbose();
80 else
81 terse();
82
83 /* output the tables and the parser to ftable. In file output. */
84 output();
85 done(failure);
86}
87
88/* functions to report errors which prevent a parser from being generated */
89
90void
91fatal(s)
92char *s;
93{
94 extern char *infile;
95
96 if (infile == 0)
97 fprintf(stderr, "fatal error: %s\n", s);
98 else
99 fprintf(stderr, "\"%s\", line %d: %s\n", infile, lineno, s);
100 done(1);
101}
102
103
104/* JF changed to accept/deal with variable args.
105 DO NOT change this to use varargs. It will appear to work
106 but will break on systems that don't have the necessary library
107 functions. This is the ONLY safe way to write such a function. */
108/*VARARGS1*/
109
110void
111fatals(fmt,x1,x2,x3,x4,x5,x6,x7,x8)
112char *fmt;
113{
114 char buffer[200];
115
116 sprintf(buffer, fmt, x1,x2,x3,x4,x5,x6,x7,x8);
117 fatal(buffer);
118}
119
120
121void
122toomany(s)
123char *s;
124{
125 char buffer[200];
126
127 /* JF new msg */
128 sprintf(buffer, "limit of %d exceeded, too many %s", MAXSHORT, s);
129 fatal(buffer);
130}
131
132
133void
134berror(s)
135char *s;
136{
137 fprintf(stderr, "internal error, %s\n", s);
138 abort();
139}