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 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 BOOLEAN ExplicitHiSuffixGiven = 0;
65 static BOOLEAN verbose = FALSE; /* Set for verbose messages. */
67 /**********************************************************************
73 **********************************************************************/
76 # include "constants.h"
81 process_args(argc,argv)
85 BOOLEAN keep_munging_option = FALSE;
87 /*OLD: progname = argv[0]; */
88 imports_dirlist = mklnil();
89 sys_imports_dirlist = mklnil();
93 while (argc && argv[0][0] == '-') {
95 keep_munging_option = TRUE;
97 while (keep_munging_option && *++*argv != '\0') {
102 imports_dirlist = lapp(imports_dirlist,*argv+1);
103 keep_munging_option = FALSE;
106 /* -J dir (for system imports) */
108 sys_imports_dirlist = lapp(sys_imports_dirlist,*argv+1);
109 keep_munging_option = FALSE;
113 strcpy(PreludeHiSuffix, *argv+1);
114 keep_munging_option = FALSE;
118 strcpy(HiSuffix, *argv+1);
119 ExplicitHiSuffixGiven = 1;
120 keep_munging_option = FALSE;
124 who_am_i(); /* identify myself */
129 nonstandardFlag = TRUE;
134 haskell1_3Flag = TRUE;
146 ignorePragmas = TRUE;
150 implicitPrelude = FALSE;
155 { extern int yydebug;
161 /* -Hn -- Use Hash Table, Size n (if given) */
164 if(*(*argv+1)!= '\0')
165 hash_table_size = atoi(*argv+1);
175 if(argc >= 1 && freopen(argv[0], "r", stdin) == NULL) {
176 fprintf(stderr, "Cannot open %s.\n", argv[0]);
180 if(argc >= 2 && freopen(argv[1], "w", stdout) == NULL) {
181 fprintf(stderr, "Cannot open %s.\n", argv[1]);
186 /* By default, imports come from the directory of the source file */
191 input_file_dir = xmalloc (strlen(argv[0]) + 1);
192 strcpy(input_file_dir, argv[0]);
194 endchar = rindex(input_file_dir, (int) ':');
196 endchar = rindex(input_file_dir, (int) '/');
197 #endif /* ! macintosh */
199 if ( endchar == NULL )
201 free(input_file_dir);
202 input_file_dir = ".";
208 /* No input file -- imports come from the current directory first */
210 input_file_dir = ".";
212 imports_dirlist = mklcons( input_file_dir, imports_dirlist );
216 fprintf(stderr,"Hash Table Contains %d entries\n",hash_table_size);
218 fprintf(stderr,"Allowing special syntax for Unboxed Values\n");
226 /*OLD: fprintf(stderr, "%s: Error %s\n", progname, s); */
227 fprintf(stderr, "PARSER: Error %s\n", s);
234 fprintf(stderr,"Glasgow Haskell parser, version %s\n", PARSER_VERSION);
242 return mkap(mkap(mkident(s), l), r);
252 if (tlist(l1) == lnil)
254 for(t = l1; tlist(ltl(t)) != lnil; t = ltl(t))
267 if (tlist(l1) == lnil)
268 return(mklcons(l2, mklnil()));
269 for(t = l1; tlist(ltl(t)) != lnil; t = ltl(t))
271 ltl(t) = mklcons(l2, mklnil());
276 /************** Haskell Infix ops, built on mkap ******************/
278 tree mkinfixop(s, l, r)
282 tree ap = mkap(mkap(mkident(s), l), r);
283 ap -> tag = tinfixop;
291 if(t -> tag != tinfixop)
292 fprintf(stderr, "ginfun: illegal selection; was %d\n", t -> tag);
293 return(Rgfun((struct Sap *) (t -> Xgfun)));
300 if(t -> tag != tinfixop)
301 fprintf(stderr, "ginarg1: illegal selection; was %d\n", t -> tag);
302 return(Rgarg((struct Sap *) (t -> Xgfun)));
309 if(t -> tag != tinfixop)
310 fprintf(stderr, "ginarg2: illegal selection; was %d\n", t -> tag);
311 return(& t -> Xgarg);