1 /**********************************************************************
7 **********************************************************************/
10 #include "constants.h"
14 #define PARSER_VERSION "0.26"
16 #define PARSER_VERSION "0.26 -- for Data Parallel Haskell"
19 tree root; /* The root of the built syntax tree. */
23 BOOLEAN nonstandardFlag = FALSE; /* Set if non-std Haskell extensions to be used. */
24 BOOLEAN acceptPrim = FALSE; /* Set if Int#, etc., may be used */
25 BOOLEAN haskell1_3Flag = FALSE; /* Set if we are doing (proto?) Haskell 1.3 */
26 BOOLEAN etags = FALSE; /* Set if we're parsing only to produce tags. */
27 BOOLEAN hashIds = FALSE; /* Set if Identifiers should be hashed. */
29 BOOLEAN ignoreSCC = TRUE; /* Set if we ignore/filter scc expressions. */
30 BOOLEAN warnSCC = FALSE; /* Set if we warn about ignored scc expressions. */
32 BOOLEAN implicitPrelude = TRUE; /* Set if we implicitly import the Prelude. */
33 BOOLEAN ignorePragmas = FALSE; /* Set if we want to ignore pragmas */
35 /* From time to time, the format of interface files may change.
37 So that we don't get gratuitous syntax errors or silently slurp in
38 junk info, two things: (a) the compiler injects a "this is a
41 {-# GHC_PRAGMA INTERFACE VERSION <n> #-}
43 (b) this parser has a "minimum acceptable version", below which it
44 refuses to parse the pragmas (it just considers them as comments).
45 It also has a "maximum acceptable version", above which...
47 The minimum is so a new parser won't try to grok overly-old
48 interfaces; the maximum (usually the current version number when
49 the parser was released) is so an old parser will not try to grok
50 since-upgraded interfaces.
52 If an interface has no INTERFACE VERSION line, it is taken to be
55 int minAcceptablePragmaVersion = 5; /* 0.26 or greater ONLY */
56 int maxAcceptablePragmaVersion = 5; /* 0.26+ */
57 int thisIfacePragmaVersion = 0;
59 static char *input_file_dir; /* The directory where the input file is. */
61 char HiSuffix[64] = ".hi"; /* can be changed with -h flag */
62 char PreludeHiSuffix[64] = ".hi"; /* can be changed with -g flag */
64 /* OLD 95/08: BOOLEAN ExplicitHiSuffixGiven = 0; */
65 static BOOLEAN verbose = FALSE; /* Set for verbose messages. */
68 static void who_am_i PROTO((void));
70 /**********************************************************************
76 **********************************************************************/
79 # include "constants.h"
84 process_args(argc,argv)
88 BOOLEAN keep_munging_option = FALSE;
90 /*OLD: progname = argv[0]; */
91 imports_dirlist = mklnil();
92 sys_imports_dirlist = mklnil();
96 while (argc && argv[0][0] == '-') {
98 keep_munging_option = TRUE;
100 while (keep_munging_option && *++*argv != '\0') {
105 imports_dirlist = lapp(imports_dirlist,*argv+1);
106 keep_munging_option = FALSE;
109 /* -J dir (for system imports) */
111 sys_imports_dirlist = lapp(sys_imports_dirlist,*argv+1);
112 keep_munging_option = FALSE;
116 strcpy(PreludeHiSuffix, *argv+1);
117 keep_munging_option = FALSE;
121 strcpy(HiSuffix, *argv+1);
122 /*OLD 95/08: ExplicitHiSuffixGiven = 1; */
123 keep_munging_option = FALSE;
127 who_am_i(); /* identify myself */
132 nonstandardFlag = TRUE;
137 haskell1_3Flag = TRUE;
149 ignorePragmas = TRUE;
153 implicitPrelude = FALSE;
158 { extern int yydebug;
164 /* -Hn -- Use Hash Table, Size n (if given) */
167 if(*(*argv+1)!= '\0')
168 hash_table_size = atoi(*argv+1);
178 if(argc >= 1 && freopen(argv[0], "r", stdin) == NULL) {
179 fprintf(stderr, "Cannot open %s.\n", argv[0]);
183 if(argc >= 2 && freopen(argv[1], "w", stdout) == NULL) {
184 fprintf(stderr, "Cannot open %s.\n", argv[1]);
189 /* By default, imports come from the directory of the source file */
194 input_file_dir = xmalloc (strlen(argv[0]) + 1);
195 strcpy(input_file_dir, argv[0]);
197 endchar = rindex(input_file_dir, (int) ':');
199 endchar = rindex(input_file_dir, (int) '/');
200 #endif /* ! macintosh */
202 if ( endchar == NULL )
204 free(input_file_dir);
205 input_file_dir = ".";
211 /* No input file -- imports come from the current directory first */
213 input_file_dir = ".";
215 imports_dirlist = mklcons( input_file_dir, imports_dirlist );
219 fprintf(stderr,"Hash Table Contains %d entries\n",hash_table_size);
221 fprintf(stderr,"Allowing special syntax for Unboxed Values\n");
229 /*OLD: fprintf(stderr, "%s: Error %s\n", progname, s); */
230 fprintf(stderr, "PARSER: Error %s\n", s);
237 fprintf(stderr,"Glasgow Haskell parser, version %s\n", PARSER_VERSION);
245 return mkap(mkap(mkident(s), l), r);
255 if (tlist(l1) == lnil)
257 for(t = l1; tlist(ltl(t)) != lnil; t = ltl(t))
264 lapp(list l1, VOID_STAR l2)
268 if (tlist(l1) == lnil)
269 return(mklcons(l2, mklnil()));
270 for(t = l1; tlist(ltl(t)) != lnil; t = ltl(t))
272 ltl(t) = mklcons(l2, mklnil());
277 /************** Haskell Infix ops, built on mkap ******************/
279 tree mkinfixop(s, l, r)
283 tree ap = mkap(mkap(mkident(s), l), r);
284 ap -> tag = tinfixop;
292 if(t -> tag != tinfixop)
293 fprintf(stderr, "ginfun: illegal selection; was %d\n", t -> tag);
294 return(Rgfun((struct Sap *) (t -> Xgfun)));
301 if(t -> tag != tinfixop)
302 fprintf(stderr, "ginarg1: illegal selection; was %d\n", t -> tag);
303 return(Rgarg((struct Sap *) (t -> Xgfun)));
310 if(t -> tag != tinfixop)
311 fprintf(stderr, "ginarg2: illegal selection; was %d\n", t -> tag);
312 return(& t -> Xgarg);