]>
git.saurik.com Git - bison.git/blob - src/main.c
   1 /* Top level entry point of bison, 
   2    Copyright (C) 1984, 1986, 1989, 1992, 1995 Free Software Foundation, Inc. 
   4 This file is part of Bison, the GNU Compiler Compiler. 
   6 Bison is free software; you can redistribute it and/or modify 
   7 it under the terms of the GNU General Public License as published by 
   8 the Free Software Foundation; either version 2, or (at your option) 
  11 Bison is distributed in the hope that it will be useful, 
  12 but WITHOUT ANY WARRANTY; without even the implied warranty of 
  13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
  14 GNU General Public License for more details. 
  16 You should have received a copy of the GNU General Public License 
  17 along with Bison; see the file COPYING.  If not, write to 
  18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 
  19 Boston, MA 02111-1307, USA.  */ 
  24 #include "machine.h"    /* for MAXSHORT */ 
  27 extern  int verboseflag
; 
  30 /* Nonzero means failure has been detected; don't write a parser file.  */ 
  33 /* The name this program was run with, for messages.  */ 
  36 char *printable_version 
PARAMS((int)); 
  37 char *int_to_string 
PARAMS((int)); 
  38 void fatal 
PARAMS((char *)); 
  39 void fatals 
PARAMS((char *, char *)); 
  40 void warn 
PARAMS((char *)); 
  41 void warni 
PARAMS((char *, int)); 
  42 void warns 
PARAMS((char *, char *)); 
  43 void warnss 
PARAMS((char *, char *, char *)); 
  44 void warnsss 
PARAMS((char *, char *, char *, char *)); 
  45 void toomany 
PARAMS((char *)); 
  46 void berror 
PARAMS((char *)); 
  48 extern void getargs 
PARAMS((int, char *[])); 
  49 extern void openfiles 
PARAMS((void)); 
  50 extern void reader 
PARAMS((void)); 
  51 extern void reduce_grammar 
PARAMS((void)); 
  52 extern void set_derives 
PARAMS((void)); 
  53 extern void set_nullable 
PARAMS((void)); 
  54 extern void generate_states 
PARAMS((void)); 
  55 extern void lalr 
PARAMS((void)); 
  56 extern void initialize_conflicts 
PARAMS((void)); 
  57 extern void verbose 
PARAMS((void)); 
  58 extern void terse 
PARAMS((void)); 
  59 extern void output 
PARAMS((void)); 
  60 extern void done 
PARAMS((int)); 
  63 /* VMS complained about using `int'.  */ 
  66 main (int argc
, char *argv
[]) 
  68   program_name 
= argv
[0]; 
  69   setlocale (LC_ALL
, ""); 
  70   bindtextdomain (PACKAGE
, LOCALEDIR
); 
  78   /* read the input.  Copy some parts of it to fguard, faction, ftable and fattrs. 
  80      The other parts are recorded in the grammar; see gram.h.  */ 
  85   /* find useless nonterminals and productions and reduce the grammar.  In 
  89   /* record other info about the grammar.  In files derives and nullable.  */ 
  93   /* convert to nondeterministic finite state machine.  In file LR0. 
  94      See state.h for more info.  */ 
  97   /* make it deterministic.  In file lalr.  */ 
 100   /* Find and record any conflicts: places where one token of lookahead is not 
 101      enough to disambiguate the parsing.  In file conflicts. 
 102      Also resolve s/r conflicts based on precedence declarations.  */ 
 103   initialize_conflicts(); 
 105   /* print information about results, if requested.  In file print. */ 
 111   /* output the tables and the parser to ftable.  In file output. */ 
 117 /* functions to report errors which prevent a parser from being generated */ 
 120 /* Return a string containing a printable version of C: 
 121    either C itself, or the corresponding \DDD code.  */ 
 124 printable_version (int c
) 
 127   if (c 
< ' ' || c 
>= '\177') 
 128     sprintf(buf
, "\\%o", c
); 
 137 /* Generate a string from the integer I. 
 138    Return a ptr to internal memory containing the string.  */ 
 141 int_to_string (int i
) 
 144   sprintf(buf
, "%d", i
); 
 152     fprintf(stderr
, _("%s: fatal error: "), program_name
); 
 154     fprintf(stderr
, _("%s:%d: fatal error: "), infile
, lineno
); 
 157 /* Print the message S for a fatal error.  */ 
 164   fputc ('\n', stderr
); 
 169 /* Print a message for a fatal error.  Use FMT to construct the message 
 170    and incorporate string X1.  */ 
 173 fatals (char *fmt
, char *x1
) 
 176   fprintf (stderr
, fmt
, x1
); 
 177   fputc ('\n', stderr
); 
 185     fprintf(stderr
, _("%s: "), program_name
); 
 187     fprintf(stderr
, _("%s:%d: "), infile
, lineno
); 
 191 /* Print a warning message S.  */ 
 198   fputc ('\n', stderr
); 
 201 /* Print a warning message containing the string for the integer X1. 
 202    The message is given by the format FMT.  */ 
 205 warni (char *fmt
, int x1
) 
 208   fprintf (stderr
, fmt
, x1
); 
 209   fputc ('\n', stderr
); 
 212 /* Print a warning message containing the string X1. 
 213    The message is given by the format FMT.  */ 
 216 warns (char *fmt
, char *x1
) 
 219   fprintf (stderr
, fmt
, x1
); 
 220   fputc ('\n', stderr
); 
 223 /* Print a warning message containing the two strings X1 and X2. 
 224         The message is given by the format FMT.  */ 
 227 warnss (char *fmt
, char *x1
, char *x2
) 
 230   fprintf (stderr
, fmt
, x1
, x2
); 
 231   fputc ('\n', stderr
); 
 234 /* Print a warning message containing the 3 strings X1, X2, X3. 
 235    The message is given by the format FMT.  */ 
 238 warnsss (char *fmt
, char *x1
, char *x2
, char *x3
) 
 241   fprintf (stderr
, fmt
, x1
, x2
, x3
); 
 242   fputc ('\n', stderr
); 
 245 /* Print a message for the fatal occurence of more than MAXSHORT 
 246    instances of whatever is denoted by the string S.  */ 
 252   fprintf (stderr
, _("too many %s (max %d)"), s
, MAXSHORT
); 
 253   fputc ('\n', stderr
); 
 257 /* Abort for an internal error denoted by string S.  */ 
 262   fprintf(stderr
, _("%s: internal error: %s\n"), program_name
, s
);