1 /**********************************************************************
7 **********************************************************************/
10 #include "constants.h"
13 #define PARSER_VERSION "0.27"
15 tree root; /* The root of the built syntax tree. */
19 BOOLEAN nonstandardFlag = FALSE; /* Set if non-std Haskell extensions to be used. */
20 BOOLEAN acceptPrim = FALSE; /* Set if Int#, etc., may be used */
21 BOOLEAN haskell1_3Flag = FALSE; /* Set if we are doing (proto?) Haskell 1.3 */
22 BOOLEAN etags = FALSE; /* Set if we're parsing only to produce tags. */
23 BOOLEAN hashIds = FALSE; /* Set if Identifiers should be hashed. */
25 BOOLEAN ignoreSCC = TRUE; /* Set if we ignore/filter scc expressions. */
26 BOOLEAN warnSCC = FALSE; /* Set if we warn about ignored scc expressions. */
28 BOOLEAN implicitPrelude = TRUE; /* Set if we implicitly import the Prelude. */
29 BOOLEAN ignorePragmas = FALSE; /* Set if we want to ignore pragmas */
31 /* From time to time, the format of interface files may change.
33 So that we don't get gratuitous syntax errors or silently slurp in
34 junk info, two things: (a) the compiler injects a "this is a
37 {-# GHC_PRAGMA INTERFACE VERSION <n> #-}
39 (b) this parser has a "minimum acceptable version", below which it
40 refuses to parse the pragmas (it just considers them as comments).
41 It also has a "maximum acceptable version", above which...
43 The minimum is so a new parser won't try to grok overly-old
44 interfaces; the maximum (usually the current version number when
45 the parser was released) is so an old parser will not try to grok
46 since-upgraded interfaces.
48 If an interface has no INTERFACE VERSION line, it is taken to be
51 int minAcceptablePragmaVersion = 5; /* 0.26 or greater ONLY */
52 int maxAcceptablePragmaVersion = 6; /* 0.28+ */
53 int thisIfacePragmaVersion = 0;
55 static char *input_file_dir; /* The directory where the input file is. */
57 char HiSuffix[64] = ".hi"; /* can be changed with -h flag */
58 char PreludeHiSuffix[64] = ".hi"; /* can be changed with -g flag */
60 /* OLD 95/08: BOOLEAN ExplicitHiSuffixGiven = 0; */
61 static BOOLEAN verbose = FALSE; /* Set for verbose messages. */
64 static void who_am_i PROTO((void));
66 /**********************************************************************
72 **********************************************************************/
75 # include "constants.h"
80 process_args(argc,argv)
84 BOOLEAN keep_munging_option = FALSE;
86 /*OLD: progname = argv[0]; */
87 imports_dirlist = mklnil();
88 sys_imports_dirlist = mklnil();
92 while (argc && argv[0][0] == '-') {
94 keep_munging_option = TRUE;
96 while (keep_munging_option && *++*argv != '\0') {
101 imports_dirlist = lapp(imports_dirlist,*argv+1);
102 keep_munging_option = FALSE;
105 /* -J dir (for system imports) */
107 sys_imports_dirlist = lapp(sys_imports_dirlist,*argv+1);
108 keep_munging_option = FALSE;
112 strcpy(PreludeHiSuffix, *argv+1);
113 keep_munging_option = FALSE;
117 strcpy(HiSuffix, *argv+1);
118 /*OLD 95/08: ExplicitHiSuffixGiven = 1; */
119 keep_munging_option = FALSE;
123 who_am_i(); /* identify myself */
128 nonstandardFlag = TRUE;
133 haskell1_3Flag = TRUE;
145 ignorePragmas = TRUE;
149 implicitPrelude = FALSE;
154 { extern int yydebug;
160 /* -Hn -- Use Hash Table, Size n (if given) */
163 if(*(*argv+1)!= '\0')
164 hash_table_size = atoi(*argv+1);
174 if(argc >= 1 && freopen(argv[0], "r", stdin) == NULL) {
175 fprintf(stderr, "Cannot open %s.\n", argv[0]);
179 if(argc >= 2 && freopen(argv[1], "w", stdout) == NULL) {
180 fprintf(stderr, "Cannot open %s.\n", argv[1]);
185 /* By default, imports come from the directory of the source file */
190 input_file_dir = xmalloc (strlen(argv[0]) + 1);
191 strcpy(input_file_dir, argv[0]);
193 endchar = rindex(input_file_dir, (int) ':');
195 endchar = rindex(input_file_dir, (int) '/');
196 #endif /* ! macintosh */
198 if ( endchar == NULL )
200 free(input_file_dir);
201 input_file_dir = ".";
207 /* No input file -- imports come from the current directory first */
209 input_file_dir = ".";
211 imports_dirlist = mklcons( input_file_dir, imports_dirlist );
215 fprintf(stderr,"Hash Table Contains %d entries\n",hash_table_size);
217 fprintf(stderr,"Allowing special syntax for Unboxed Values\n");
225 /*OLD: fprintf(stderr, "%s: Error %s\n", progname, s); */
226 fprintf(stderr, "PARSER: Error %s\n", s);
233 fprintf(stderr,"Glasgow Haskell parser, version %s\n", PARSER_VERSION);
241 return mkap(mkap(mkident(s), l), r);
251 if (tlist(l1) == lnil)
253 for(t = l1; tlist(ltl(t)) != lnil; t = ltl(t))
260 lapp(list l1, VOID_STAR l2)
264 if (tlist(l1) == lnil)
265 return(mklcons(l2, mklnil()));
266 for(t = l1; tlist(ltl(t)) != lnil; t = ltl(t))
268 ltl(t) = mklcons(l2, mklnil());
273 /************** Haskell Infix ops, built on mkap ******************/
275 tree mkinfixop(s, l, r)
279 tree ap = mkap(mkap(mkident(s), l), r);
280 ap -> tag = tinfixop;
288 if(t -> tag != tinfixop)
289 fprintf(stderr, "ginfun: illegal selection; was %d\n", t -> tag);
290 return(Rgfun((struct Sap *) (t -> Xgfun)));
297 if(t -> tag != tinfixop)
298 fprintf(stderr, "ginarg1: illegal selection; was %d\n", t -> tag);
299 return(Rgarg((struct Sap *) (t -> Xgfun)));
306 if(t -> tag != tinfixop)
307 fprintf(stderr, "ginarg2: illegal selection; was %d\n", t -> tag);
308 return(& t -> Xgarg);