1 /**************************************************************************
4 * Author: Maria M. Gutierrez *
5 * Modified by: Kevin Hammond *
6 * Last date revised: December 13 1991. KH. *
7 * Modification: Haskell 1.1 Syntax. *
10 * Description: This file contains the LALR(1) grammar for Haskell. *
12 * Entry Point: module *
14 * Problems: None known. *
17 * LALR(1) Syntax for Haskell 1.2 *
19 **************************************************************************/
31 #include "constants.h"
34 /**********************************************************************
37 * Imported Variables and Functions *
40 **********************************************************************/
42 BOOLEAN expect_ccurly = FALSE; /* Used to signal that a CCURLY could be inserted here */
44 extern BOOLEAN nonstandardFlag;
47 extern VOID find_module_on_imports_dirlist PROTO((char *, BOOLEAN, char *));
49 extern char *input_filename;
50 static char *the_module_name;
51 static char iface_name[MODNAME_SIZE];
52 static char interface_filename[FILENAME_SIZE];
54 static list module_exports; /* Exported entities */
55 static list prelude_core_import, prelude_imports;
56 /* Entities imported from the Prelude */
58 extern list all; /* All valid deriving classes */
65 /* For FN, PREVPATT and SAMEFN macros */
67 extern short samefn[];
68 extern tree prevpatt[];
69 extern short icontexts;
72 extern int hsplineno, hspcolno;
73 extern int startlineno;
76 /**********************************************************************
79 * Fixity and Precedence Declarations *
82 **********************************************************************/
85 static int Fixity = 0, Precedence = 0;
88 char *ineg PROTO((char *));
90 static BOOLEAN hidden = FALSE; /* Set when HIDING used */
92 extern BOOLEAN inpat; /* True when parsing a pattern */
93 extern BOOLEAN implicitPrelude; /* True when we should read the Prelude if not given */
94 extern BOOLEAN haskell1_3Flag; /* True if we are attempting (proto)Haskell 1.3 */
96 extern int thisIfacePragmaVersion;
120 /**********************************************************************
123 * These are lexemes. *
126 **********************************************************************/
132 %token INTEGER FLOAT CHAR STRING
133 CHARPRIM STRINGPRIM INTPRIM FLOATPRIM
138 /**********************************************************************
144 **********************************************************************/
146 %token OCURLY CCURLY VCCURLY SEMI
147 %token OBRACK CBRACK OPAREN CPAREN
151 /**********************************************************************
154 * Reserved Operators *
157 **********************************************************************/
160 %token VBAR EQUAL DARROW DOTDOT
162 %token WILDCARD AT LAZY LAMBDA
165 /**********************************************************************
168 * Reserved Identifiers *
171 **********************************************************************/
175 %token TYPE DATA CLASS INSTANCE DEFAULT
176 %token INFIX INFIXL INFIXR
177 %token MODULE IMPORT INTERFACE HIDING
178 %token CCALL CCALL_GC CASM CASM_GC SCC
181 %token RENAMING DERIVING TO
183 /**********************************************************************
186 * Special Symbols for the Lexer *
189 **********************************************************************/
192 %token GHC_PRAGMA END_PRAGMA NO_PRAGMA NOINFO_PRAGMA
193 %token ABSTRACT_PRAGMA SPECIALISE_PRAGMA MODNAME_PRAGMA
194 %token ARITY_PRAGMA UPDATE_PRAGMA STRICTNESS_PRAGMA KIND_PRAGMA
195 %token UNFOLDING_PRAGMA MAGIC_UNFOLDING_PRAGMA DEFOREST_PRAGMA
196 %token SPECIALISE_UPRAGMA INLINE_UPRAGMA MAGIC_UNFOLDING_UPRAGMA
197 %token ABSTRACT_UPRAGMA DEFOREST_UPRAGMA END_UPRAGMA
198 %token TYLAMBDA COCON COPRIM COAPP COTYAPP FORALL TYVAR_TEMPLATE_ID
199 %token CO_ALG_ALTS CO_PRIM_ALTS CO_NO_DEFAULT CO_LETREC
200 %token CO_SDSEL_ID CO_METH_ID CO_DEFM_ID CO_DFUN_ID CO_CONSTM_ID
201 %token CO_SPEC_ID CO_WRKR_ID CO_ORIG_NM
202 %token UNFOLD_ALWAYS UNFOLD_IF_ARGS
203 %token NOREP_INTEGER NOREP_RATIONAL NOREP_STRING
204 %token CO_PRELUDE_DICTS_CC CO_ALL_DICTS_CC CO_USER_CC CO_AUTO_CC CO_DICT_CC
205 %token CO_CAF_CC CO_DUPD_CC
207 /**********************************************************************
210 * Precedences of the various tokens *
213 **********************************************************************/
216 %left CASE LET IN LAMBDA
217 IF ELSE CCALL CCALL_GC
220 %left VARSYM CONSYM PLUS MINUS BQUOTE
226 %left OCURLY OBRACK OPAREN
235 /**********************************************************************
238 * Type Declarations *
241 **********************************************************************/
244 %type <ulist> alt alts altrest quals vars varsrest cons
245 tyvars constrs dtypes types atypes
247 list_exps pats context context_list atype_list
248 maybeexports export_list
249 impspec maybeimpspec import_list
250 impdecls maybeimpdecls impdecl
251 renaming renamings renaming_list
253 gdrhs gdpat valrhs valrhs1
257 idata_pragma_specs idata_pragma_specslist
258 gen_pragma_list type_pragma_pairs
259 type_pragma_pairs_maybe name_pragma_pairs
260 maybe_name_pragma_pairs type_instpragma_pairs
264 core_binders core_tyvars core_tv_templates
265 core_types core_type_list
266 core_atoms core_atom_list
267 core_alg_alts core_prim_alts corec_binds
270 %type <uliteral> lit_constant
272 %type <utree> exp dexp fexp kexp oexp aexp
273 tuple list sequence comprehension qual qualrest
275 apat bpat pat apatc conpat dpat fpat opat aapat
276 dpatk fpatk opatk aapatk
279 %type <uid> MINUS VARID CONID VARSYM CONSYM TYVAR_TEMPLATE_ID
280 var vark con conk varop varop1 conop op op1
282 tycls tycon modid ccallid modname_pragma
284 %type <ubinding> topdecl topdecls
285 typed datad classd instd defaultd
286 decl decls valdef instdef instdefs
287 iimport iimports maybeiimports
288 ityped idatad iclassd iinstd ivarsd
291 interface readinterface ibody
296 %type <uttype> simple simple_long type atype btype ttype ntatype inst class
297 tyvar core_type type_maybe core_type_maybe
299 %type <uatype> constr
301 %type <ustring> FLOAT INTEGER INTPRIM
302 FLOATPRIM DOUBLEPRIM CLITLIT
303 %type <uhstring> STRING STRINGPRIM CHAR CHARPRIM
304 %type <uentid> export import
306 %type <uhpragma> idata_pragma idata_pragma_spectypes
307 itype_pragma iclas_pragma iclasop_pragma
308 iinst_pragma gen_pragma ival_pragma arity_pragma
309 update_pragma strictness_pragma worker_info
311 unfolding_pragma unfolding_guidance type_pragma_pair
312 type_instpragma_pair name_pragma_pair
314 %type <ucoresyn> core_expr core_case_alts core_id core_binder core_atom
315 core_alg_alt core_prim_alt core_default corec_bind
316 co_primop co_scc co_caf co_dupd
318 /**********************************************************************
321 * Start Symbol for the Parser *
324 **********************************************************************/
331 pmodule : readpreludecore readprelude module
334 module : modulekey modid maybeexports
335 { the_module_name = $2; module_exports = $3; }
337 | { the_module_name = install_literal("Main"); module_exports = Lnil; }
341 /* all the startlinenos in mkhmodules are bogus (WDP) */
342 body : ocurly maybeimpdecls maybefixes topdecls ccurly
344 root = mkhmodule(the_module_name,lconc(prelude_imports,$2),module_exports,$4,startlineno);
346 | vocurly maybeimpdecls maybefixes topdecls vccurly
348 root = mkhmodule(the_module_name,lconc(prelude_imports,$2),module_exports,$4,startlineno);
351 | vocurly impdecls vccurly
353 root = mkhmodule(the_module_name,lconc(prelude_imports,$2),module_exports,mknullbind(),startlineno);
355 | ocurly impdecls ccurly
357 root = mkhmodule(the_module_name,lconc(prelude_imports,$2),module_exports,mknullbind(),startlineno);
360 /* Adds 1 S/R, 2 R/R conflicts, alternatives add 3 R/R conflicts */
361 | vocurly maybeimpdecls vccurly
363 root = mkhmodule(the_module_name,lconc(prelude_imports,$2),module_exports,mknullbind(),startlineno);
365 | ocurly maybeimpdecls ccurly
367 root = mkhmodule(the_module_name,lconc(prelude_imports,$2),module_exports,mknullbind(),startlineno);
372 maybeexports : /* empty */ { $$ = Lnil; }
373 | OPAREN export_list CPAREN { $$ = $2; }
377 export { $$ = lsing($1); }
378 | export_list COMMA export { $$ = lapp($1, $3); }
382 var { $$ = mkentid($1); }
383 | tycon { $$ = mkenttype($1); }
384 | tycon OPAREN DOTDOT CPAREN { $$ = mkenttypeall($1); }
385 | tycon OPAREN cons CPAREN
386 { $$ = mkenttypecons($1,$3);
387 /* should be a datatype with cons representing all constructors */
389 | tycon OPAREN vars CPAREN
390 { $$ = mkentclass($1,$3);
391 /* should be a class with vars representing all Class operations */
393 | tycon OPAREN CPAREN
394 { $$ = mkentclass($1,Lnil);
395 /* "tycon" should be a class with no operations */
399 /* "tycon" is a module id (but "modid" is bad for your identifier's health [KH]) */
404 impspec : OPAREN import_list CPAREN { $$ = $2; hidden = FALSE; }
405 | HIDING OPAREN import_list CPAREN { $$ = $3; hidden = TRUE; }
406 | OPAREN CPAREN { $$ = Lnil; hidden = FALSE; }
409 maybeimpspec : /* empty */ { $$ = Lnil; }
410 | impspec { $$ = $1; }
414 import { $$ = lsing($1); }
415 | import_list COMMA import { $$ = lapp($1, $3); }
419 var { $$ = mkentid($1); }
420 | tycon { $$ = mkenttype($1); }
421 | tycon OPAREN DOTDOT CPAREN { $$ = mkenttypeall($1); }
422 | tycon OPAREN cons CPAREN
423 { $$ = mkenttypecons($1,$3);
424 /* should be a datatype with cons representing all constructors */
426 | tycon OPAREN vars CPAREN
427 { $$ = mkentclass($1,$3);
428 /* should be a class with vars representing all Class operations */
430 | tycon OPAREN CPAREN
431 { $$ = mkentclass($1,Lnil);
432 /* "tycon" should be a class with no operations */
436 /* -- interface pragma stuff: ------------------------------------- */
439 GHC_PRAGMA constrs idata_pragma_specs END_PRAGMA
440 { $$ = mkidata_pragma($2, $3); }
441 | GHC_PRAGMA idata_pragma_specs END_PRAGMA
442 { $$ = mkidata_pragma(Lnil, $2); }
443 | /* empty */ { $$ = mkno_pragma(); }
447 SPECIALISE_PRAGMA idata_pragma_specslist
449 | /* empty */ { $$ = Lnil; }
452 idata_pragma_specslist:
453 idata_pragma_spectypes { $$ = lsing($1); }
454 | idata_pragma_specslist COMMA idata_pragma_spectypes
455 { $$ = lapp($1, $3); }
458 idata_pragma_spectypes:
459 OBRACK type_maybes CBRACK { $$ = mkidata_pragma_4s($2); }
463 GHC_PRAGMA ABSTRACT_PRAGMA END_PRAGMA { $$ = mkitype_pragma(); }
464 | /* empty */ { $$ = mkno_pragma(); }
468 GHC_PRAGMA gen_pragma_list END_PRAGMA { $$ = mkiclas_pragma($2); }
469 | /* empty */ { $$ = mkno_pragma(); }
473 GHC_PRAGMA gen_pragma gen_pragma END_PRAGMA
474 { $$ = mkiclasop_pragma($2, $3); }
476 { $$ = mkno_pragma(); }
480 GHC_PRAGMA modname_pragma gen_pragma END_PRAGMA
481 { $$ = mkiinst_simpl_pragma($2, $3); }
483 | GHC_PRAGMA modname_pragma gen_pragma name_pragma_pairs END_PRAGMA
484 { $$ = mkiinst_const_pragma($2, $3, $4); }
486 | GHC_PRAGMA modname_pragma gen_pragma restof_iinst_spec END_PRAGMA
487 { $$ = mkiinst_spec_pragma($2, $3, $4); }
490 { $$ = mkno_pragma(); }
497 { $$ = install_literal(""); }
500 restof_iinst_spec: SPECIALISE_PRAGMA type_instpragma_pairs { $$ = $2; }
504 GHC_PRAGMA gen_pragma END_PRAGMA
507 { $$ = mkno_pragma(); }
512 { $$ = mkno_pragma(); }
513 | arity_pragma update_pragma deforest_pragma strictness_pragma unfolding_pragma type_pragma_pairs_maybe
514 { $$ = mkigen_pragma($1, $2, $3, $4, $5, $6); }
518 NO_PRAGMA { $$ = mkno_pragma(); }
519 | ARITY_PRAGMA INTEGER { $$ = mkiarity_pragma($2); }
523 NO_PRAGMA { $$ = mkno_pragma(); }
524 | UPDATE_PRAGMA INTEGER { $$ = mkiupdate_pragma($2); }
528 NO_PRAGMA { $$ = mkno_pragma(); }
529 | DEFOREST_PRAGMA { $$ = mkideforest_pragma(); }
533 NO_PRAGMA { $$ = mkno_pragma(); }
534 | STRICTNESS_PRAGMA COCON { $$ = mkistrictness_pragma(installHstring(1, "B"),
535 /* _!_ = COCON = bottom */ mkno_pragma());
537 | STRICTNESS_PRAGMA STRING worker_info
538 { $$ = mkistrictness_pragma($2, $3); }
542 OCURLY gen_pragma CCURLY { $$ = $2; }
543 | /* empty */ { $$ = mkno_pragma(); }
546 NO_PRAGMA { $$ = mkno_pragma(); }
547 | MAGIC_UNFOLDING_PRAGMA vark
548 { $$ = mkimagic_unfolding_pragma($2); }
549 | UNFOLDING_PRAGMA unfolding_guidance core_expr
550 { $$ = mkiunfolding_pragma($2, $3); }
555 { $$ = mkiunfold_always(); }
556 | UNFOLD_IF_ARGS INTEGER INTEGER CONID INTEGER
557 { $$ = mkiunfold_if_args($2, $3, $4, $5); }
561 gen_pragma { $$ = lsing($1); }
562 | gen_pragma_list COMMA gen_pragma { $$ = lapp($1, $3); }
565 type_pragma_pairs_maybe:
566 NO_PRAGMA { $$ = Lnil; }
567 | SPECIALISE_PRAGMA type_pragma_pairs { $$ = $2; }
571 type_pragma_pair { $$ = lsing($1); }
572 | type_pragma_pairs COMMA type_pragma_pair { $$ = lapp($1, $3); }
576 OBRACK type_maybes CBRACK INTEGER worker_info
577 { $$ = mkitype_pragma_pr($2, $4, $5); }
580 type_instpragma_pairs:
581 type_instpragma_pair { $$ = lsing($1); }
582 | type_instpragma_pairs COMMA type_instpragma_pair { $$ = lapp($1,$3); }
585 type_instpragma_pair:
586 OBRACK type_maybes CBRACK INTEGER worker_info maybe_name_pragma_pairs
587 { $$ = mkiinst_pragma_3s($2, $4, $5, $6); }
591 type_maybe { $$ = lsing($1); }
592 | type_maybes COMMA type_maybe { $$ = lapp($1, $3); }
596 NO_PRAGMA { $$ = mkty_maybe_nothing(); }
597 | type { $$ = mkty_maybe_just($1); }
600 maybe_name_pragma_pairs:
601 /* empty */ { $$ = Lnil; }
602 | name_pragma_pairs { $$ = $1; }
606 name_pragma_pair { $$ = lsing($1); }
607 | name_pragma_pairs COMMA name_pragma_pair { $$ = lapp($1, $3); }
612 { $$ = mkiname_pragma_pr($1, $3); }
615 /* -- end of interface pragma stuff ------------------------------- */
617 /* -- core syntax stuff ------------------------------------------- */
620 LAMBDA core_binders RARROW core_expr
621 { $$ = mkcolam($2, $4); }
622 | TYLAMBDA core_tyvars RARROW core_expr
623 { $$ = mkcotylam($2, $4); }
624 | COCON con core_types core_atoms
625 { $$ = mkcocon(mkco_id($2), $3, $4); }
626 | COCON CO_ORIG_NM modid con core_types core_atoms
627 { $$ = mkcocon(mkco_orig_id($3,$4), $5, $6); }
628 | COPRIM co_primop core_types core_atoms
629 { $$ = mkcoprim($2, $3, $4); }
630 | COAPP core_expr core_atoms
631 { $$ = mkcoapp($2, $3); }
632 | COTYAPP core_expr OCURLY core_type CCURLY
633 { $$ = mkcotyapp($2, $4); }
634 | CASE core_expr OF OCURLY core_case_alts CCURLY
635 { $$ = mkcocase($2, $5); }
636 | LET OCURLY core_binder EQUAL core_expr CCURLY IN core_expr
637 { $$ = mkcolet(mkcononrec($3, $5), $8); }
638 | CO_LETREC OCURLY corec_binds CCURLY IN core_expr
639 { $$ = mkcolet(mkcorec($3), $6); }
640 | SCC OCURLY co_scc CCURLY core_expr
641 { $$ = mkcoscc($3, $5); }
642 | lit_constant { $$ = mkcoliteral($1); }
643 | core_id { $$ = mkcovar($1); }
647 CO_ALG_ALTS core_alg_alts core_default
648 { $$ = mkcoalg_alts($2, $3); }
649 | CO_PRIM_ALTS core_prim_alts core_default
650 { $$ = mkcoprim_alts($2, $3); }
654 /* empty */ { $$ = Lnil; }
655 | core_alg_alts core_alg_alt { $$ = lapp($1, $2); }
659 core_id core_binders RARROW core_expr SEMI { $$ = mkcoalg_alt($1, $2, $4); }
660 /* core_id is really too generous */
664 /* empty */ { $$ = Lnil; }
665 | core_prim_alts core_prim_alt { $$ = lapp($1, $2); }
669 lit_constant RARROW core_expr SEMI { $$ = mkcoprim_alt($1, $3); }
673 CO_NO_DEFAULT { $$ = mkconodeflt(); }
674 | core_binder RARROW core_expr { $$ = mkcobinddeflt($1, $3); }
678 corec_bind { $$ = lsing($1); }
679 | corec_binds SEMI corec_bind { $$ = lapp($1, $3); }
683 core_binder EQUAL core_expr { $$ = mkcorec_pair($1, $3); }
687 CO_PRELUDE_DICTS_CC co_dupd { $$ = mkco_preludedictscc($2); }
688 | CO_ALL_DICTS_CC STRING STRING co_dupd { $$ = mkco_alldictscc($2,$3,$4); }
689 | CO_USER_CC STRING STRING STRING co_dupd co_caf
690 { $$ = mkco_usercc($2,$3,$4,$5,$6); }
691 | CO_AUTO_CC core_id STRING STRING co_dupd co_caf
692 { $$ = mkco_autocc($2,$3,$4,$5,$6); }
693 | CO_DICT_CC core_id STRING STRING co_dupd co_caf
694 { $$ = mkco_dictcc($2,$3,$4,$5,$6); }
696 co_caf : NO_PRAGMA { $$ = mkco_scc_noncaf(); }
697 | CO_CAF_CC { $$ = mkco_scc_caf(); }
699 co_dupd : NO_PRAGMA { $$ = mkco_scc_nondupd(); }
700 | CO_DUPD_CC { $$ = mkco_scc_dupd(); }
702 core_id: /* more to come?? */
703 CO_SDSEL_ID tycon tycon { $$ = mkco_sdselid($2, $3); }
704 | CO_METH_ID tycon var { $$ = mkco_classopid($2, $3); }
705 | CO_DEFM_ID tycon var { $$ = mkco_defmid($2, $3); }
706 | CO_DFUN_ID tycon OPAREN core_type CPAREN
707 { $$ = mkco_dfunid($2, $4); }
708 | CO_CONSTM_ID tycon var OPAREN core_type CPAREN
709 { $$ = mkco_constmid($2, $3, $5); }
710 | CO_SPEC_ID core_id OBRACK core_type_maybes CBRACK
711 { $$ = mkco_specid($2, $4); }
712 | CO_WRKR_ID core_id { $$ = mkco_wrkrid($2); }
713 | CO_ORIG_NM modid var { $$ = mkco_orig_id($2, $3); }
714 | CO_ORIG_NM modid con { $$ = mkco_orig_id($2, $3); }
715 | var { $$ = mkco_id($1); }
716 | con { $$ = mkco_id($1); }
720 OPAREN CCALL ccallid OCURLY core_types core_type CCURLY CPAREN
721 { $$ = mkco_ccall($3,0,$5,$6); }
722 | OPAREN CCALL_GC ccallid OCURLY core_types core_type CCURLY CPAREN
723 { $$ = mkco_ccall($3,1,$5,$6); }
724 | OPAREN CASM lit_constant OCURLY core_types core_type CCURLY CPAREN
725 { $$ = mkco_casm($3,0,$5,$6); }
726 | OPAREN CASM_GC lit_constant OCURLY core_types core_type CCURLY CPAREN
727 { $$ = mkco_casm($3,1,$5,$6); }
728 | VARID { $$ = mkco_primop($1); }
732 /* empty */ { $$ = Lnil; }
733 | core_binders core_binder { $$ = lapp($1, $2); }
737 OPAREN VARID DCOLON core_type CPAREN { $$ = mkcobinder($2, $4); }
740 OBRACK CBRACK { $$ = Lnil; }
741 | OBRACK core_atom_list CBRACK { $$ = $2; }
745 core_atom { $$ = lsing($1); }
746 | core_atom_list COMMA core_atom { $$ = lapp($1, $3); }
750 lit_constant { $$ = mkcolit($1); }
751 | core_id { $$ = mkcolocal($1); }
755 VARID { $$ = lsing($1); }
756 | core_tyvars VARID { $$ = lapp($1, $2); }
760 TYVAR_TEMPLATE_ID { $$ = lsing($1); }
761 | core_tv_templates COMMA TYVAR_TEMPLATE_ID { $$ = lapp($1, $3); }
765 OBRACK CBRACK { $$ = Lnil; }
766 | OBRACK core_type_list CBRACK { $$ = $2; }
770 core_type { $$ = lsing($1); }
771 | core_type_list COMMA core_type { $$ = lapp($1, $3); }
780 FORALL core_tv_templates DARROW core_type
781 { $$ = mkuniforall($2, $4); }
782 | OCURLY OCURLY CONID core_type CCURLY CCURLY RARROW core_type
783 { $$ = mktfun(mkunidict($3, $4), $8); }
784 | OCURLY OCURLY CONID core_type CCURLY CCURLY
785 { $$ = mkunidict($3, $4); }
786 | OPAREN OCURLY OCURLY CONID core_type CCURLY CCURLY COMMA core_type_list CPAREN RARROW core_type
787 { $$ = mktfun(mkttuple(mklcons(mkunidict($4, $5), $9)), $12); }
788 | OPAREN OCURLY OCURLY CONID core_type CCURLY CCURLY COMMA core_type_list CPAREN
789 { $$ = mkttuple(mklcons(mkunidict($4,$5), $9)); }
795 core_type_maybe { $$ = lsing($1); }
796 | core_type_maybes COMMA core_type_maybe { $$ = lapp($1, $3); }
800 NO_PRAGMA { $$ = mkty_maybe_nothing(); }
801 | core_type { $$ = mkty_maybe_just($1); }
804 /* -- end of core syntax stuff ------------------------------------ */
808 if ( implicitPrelude && !etags ) {
809 /* we try to avoid reading interfaces when etagging */
810 find_module_on_imports_dirlist(
811 (haskell1_3Flag) ? "PrelCore13" : "PreludeCore",
812 TRUE,interface_filename);
814 find_module_on_imports_dirlist("PreludeNull_",TRUE,interface_filename);
816 thisIfacePragmaVersion = 0;
817 setyyin(interface_filename);
822 binding prelude_core = mkimport(installid(iface_name),Lnil,Lnil,$2,xstrdup(interface_filename),hsplineno);
823 prelude_core_import = implicitPrelude? lsing(prelude_core): Lnil;
830 if ( implicitPrelude && !etags ) {
831 find_module_on_imports_dirlist(
832 ( haskell1_3Flag ) ? "Prel13" : "Prelude",
833 TRUE,interface_filename);
835 find_module_on_imports_dirlist("PreludeNull_",TRUE,interface_filename);
837 thisIfacePragmaVersion = 0;
838 setyyin(interface_filename);
843 binding prelude = mkimport(installid(iface_name),Lnil,Lnil,$2,xstrdup(interface_filename),hsplineno);
844 prelude_imports = (! implicitPrelude) ? Lnil
845 : lconc(prelude_core_import,lsing(prelude));
849 maybeimpdecls : /* empty */ { $$ = Lnil; }
850 | impdecls SEMI { $$ = $1; }
853 impdecls: impdecl { $$ = $1; }
854 | impdecls SEMI impdecl { $$ = lconc($1,$3); }
857 impdecl : IMPORT modid
858 { /* filename returned in "interface_filename" */
859 char *module_name = id_to_string($2);
861 find_module_on_imports_dirlist(
862 (haskell1_3Flag && strcmp(module_name, "Prelude") == 0)
863 ? "Prel13" : module_name,
864 FALSE, interface_filename);
866 find_module_on_imports_dirlist("PreludeNull_",TRUE,interface_filename);
868 thisIfacePragmaVersion = 0;
869 setyyin(interface_filename);
871 if (strcmp(module_name,"PreludeCore")==0) {
872 hsperror("Cannot explicitly import `PreludeCore'");
874 } else if (strcmp(module_name,"Prelude")==0) {
875 prelude_imports = prelude_core_import; /* unavoidable */
886 readinterface maybeimpspec
887 { $$ = mkimport(installid(iface_name),$2,Lnil,$1,xstrdup(interface_filename),hsplineno); }
888 /* WDP: uncertain about those hsplinenos */
889 | readinterface maybeimpspec RENAMING renamings
890 { $$ = mkimport(installid(iface_name),$2,$4,$1,xstrdup(interface_filename),hsplineno); }
896 exposeis(); /* partain: expose infix ops at level i+1 to level i */
901 renamings: OPAREN renaming_list CPAREN { $$ = $2; }
905 renaming { $$ = lsing($1); }
906 | renaming_list COMMA renaming { $$ = lapp($1, $3); }
909 renaming: var TO var { $$ = ldub($1,$3); }
910 | con TO con { $$ = ldub($1,$3); }
913 maybeiimports : /* empty */ { $$ = mknullbind(); }
914 | iimports SEMI { $$ = $1; }
917 iimports : iimport { $$ = $1; }
918 | iimports SEMI iimport { $$ = mkabind($1,$3); }
921 iimport : importkey modid OPAREN import_list CPAREN
922 { $$ = mkmbind($2,$4,Lnil,startlineno); }
923 | importkey modid OPAREN import_list CPAREN RENAMING renamings
924 { $$ = mkmbind($2,$4,$7,startlineno); }
931 strcpy(iface_name, id_to_string($2));
935 /* WDP: not only do we not check the module name
936 but we take the one in the interface to be what we really want
937 -- we need this for Prelude jiggery-pokery. (Blech. KH)
938 ToDo: possibly revert....
939 checkmodname(modname,id_to_string($2));
946 ibody : ocurly maybeiimports maybefixes itopdecls ccurly
950 | ocurly iimports ccurly
954 | vocurly maybeiimports maybefixes itopdecls vccurly
958 | vocurly iimports vccurly
964 maybefixes: /* empty */
974 { Precedence = checkfixity($2); Fixity = INFIXL; }
977 { Precedence = checkfixity($2); Fixity = INFIXR; }
980 { Precedence = checkfixity($2); Fixity = INFIX; }
983 { Fixity = INFIXL; Precedence = 9; }
986 { Fixity = INFIXR; Precedence = 9; }
989 { Fixity = INFIX; Precedence = 9; }
993 ops : op { makeinfix(id_to_string($1),Fixity,Precedence); }
994 | ops COMMA op { makeinfix(id_to_string($3),Fixity,Precedence); }
998 | topdecls SEMI topdecl
1008 $$ = mkabind($1,$3);
1017 topdecl : typed { $$ = $1; }
1018 | datad { $$ = $1; }
1019 | classd { $$ = $1; }
1020 | instd { $$ = $1; }
1021 | defaultd { $$ = $1; }
1025 typed : typekey simple EQUAL type { $$ = mknbind($2,$4,startlineno,mkno_pragma()); }
1029 datad : datakey context DARROW simple EQUAL constrs
1030 { $$ = mktbind($2,$4,$6,all,startlineno,mkno_pragma()); }
1031 | datakey simple EQUAL constrs
1032 { $$ = mktbind(Lnil,$2,$4,all,startlineno,mkno_pragma()); }
1033 | datakey context DARROW simple EQUAL constrs DERIVING tyclses
1034 { $$ = mktbind($2,$4,$6,$8,startlineno,mkno_pragma()); }
1035 | datakey simple EQUAL constrs DERIVING tyclses
1036 { $$ = mktbind(Lnil,$2,$4,$6,startlineno,mkno_pragma()); }
1039 classd : classkey context DARROW class cbody { $$ = mkcbind($2,$4,$5,startlineno,mkno_pragma()); }
1040 | classkey class cbody { $$ = mkcbind(Lnil,$2,$3,startlineno,mkno_pragma()); }
1043 cbody : /* empty */ { $$ = mknullbind(); }
1044 | WHERE ocurly decls ccurly { checkorder($3); $$ = $3; }
1045 | WHERE vocurly decls vccurly { checkorder($3); $$ =$3; }
1048 instd : instkey context DARROW tycls inst rinst { $$ = mkibind($2,$4,$5,$6,startlineno,mkno_pragma()); }
1049 | instkey tycls inst rinst { $$ = mkibind(Lnil,$2,$3,$4,startlineno,mkno_pragma()); }
1052 rinst : /* empty */ { $$ = mknullbind(); }
1053 | WHERE ocurly instdefs ccurly { $$ = $3; }
1054 | WHERE vocurly instdefs vccurly { $$ = $3; }
1057 inst : tycon { $$ = mktname($1,Lnil); }
1058 | OPAREN simple_long CPAREN { $$ = $2; }
1059 /* partain?: "simple" requires k >= 0, not k > 0 (hence "simple_long" hack) */
1060 | OPAREN atype_list CPAREN { $$ = mkttuple($2); }
1061 | OPAREN CPAREN { $$ = mkttuple(Lnil); }
1062 | OBRACK atype CBRACK { $$ = mktllist($2); }
1063 | OPAREN atype RARROW atype CPAREN { $$ = mktfun($2,$4); }
1066 defaultd: defaultkey dtypes { $$ = mkdbind($2,startlineno); }
1069 dtypes : OPAREN type COMMA types CPAREN { $$ = mklcons($2,$4); }
1070 | ttype { $$ = lsing($1); }
1071 /* Omitting the next forces () to be the *type* (), which never defaults.
1072 This is a KLUDGE. (Putting this in adds piles of r/r conflicts.)
1074 /* | OPAREN CPAREN { $$ = Lnil; }*/
1086 $$ = mkabind($1,$3);
1090 /* partain: this "DCOLON context" vs "DCOLON type" is a problem,
1091 because you can't distinguish between
1093 foo :: (Baz a, Baz a)
1094 bar :: (Baz a, Baz a) => [a] -> [a] -> [a]
1096 with one token of lookahead. The HACK is to have "DCOLON ttype"
1097 [tuple type] in the first case, then check that it has the right
1098 form C a, or (C1 a, C2 b, ... Cn z) and convert it into a
1102 Note: if there is an iclasop_pragma there, then we must be
1103 doing a class-op in an interface -- unless the user is up
1104 to real mischief (ugly, but likely to work).
1107 decl : vars DCOLON type DARROW type iclasop_pragma
1108 { /* type2context.c for code */
1109 $$ = mksbind($1,mkcontext(type2context($3),$5),startlineno,$6);
1110 PREVPATT = NULL; FN = NULL; SAMEFN = 0;
1112 | vars DCOLON type iclasop_pragma
1114 $$ = mksbind($1,$3,startlineno,$4);
1115 PREVPATT = NULL; FN = NULL; SAMEFN = 0;
1118 /* User-specified pragmas come in as "signatures"...
1119 They are similar in that they can appear anywhere in the module,
1120 and have to be "joined up" with their related entity.
1122 Have left out the case specialising to an overloaded type.
1123 Let's get real, OK? (WDP)
1125 | SPECIALISE_UPRAGMA vark DCOLON types_and_maybe_ids END_UPRAGMA
1127 $$ = mkvspec_uprag($2, $4, startlineno);
1128 PREVPATT = NULL; FN = NULL; SAMEFN = 0;
1131 | SPECIALISE_UPRAGMA INSTANCE CONID inst END_UPRAGMA
1133 $$ = mkispec_uprag($3, $4, startlineno);
1134 PREVPATT = NULL; FN = NULL; SAMEFN = 0;
1137 | SPECIALISE_UPRAGMA DATA tycon atypes END_UPRAGMA
1139 $$ = mkdspec_uprag($3, $4, startlineno);
1140 PREVPATT = NULL; FN = NULL; SAMEFN = 0;
1143 | INLINE_UPRAGMA vark howto_inline_maybe END_UPRAGMA
1145 $$ = mkinline_uprag($2, $3, startlineno);
1146 PREVPATT = NULL; FN = NULL; SAMEFN = 0;
1149 | MAGIC_UNFOLDING_UPRAGMA vark vark END_UPRAGMA
1151 $$ = mkmagicuf_uprag($2, $3, startlineno);
1152 PREVPATT = NULL; FN = NULL; SAMEFN = 0;
1155 | DEFOREST_UPRAGMA vark END_UPRAGMA
1157 $$ = mkdeforest_uprag($2, startlineno);
1158 PREVPATT = NULL; FN = NULL; SAMEFN = 0;
1161 | ABSTRACT_UPRAGMA tycon END_UPRAGMA
1163 $$ = mkabstract_uprag($2, startlineno);
1164 PREVPATT = NULL; FN = NULL; SAMEFN = 0;
1167 /* end of user-specified pragmas */
1170 | /* empty */ { $$ = mknullbind(); PREVPATT = NULL; FN = NULL; SAMEFN = 0; }
1173 howto_inline_maybe :
1174 /* empty */ { $$ = Lnil; }
1175 | CONID { $$ = lsing($1); }
1177 types_and_maybe_ids :
1178 type_and_maybe_id { $$ = lsing($1); }
1179 | types_and_maybe_ids COMMA type_and_maybe_id { $$ = lapp($1,$3); }
1183 type { $$ = mkvspec_ty_and_id($1,Lnil); }
1184 | type EQUAL vark { $$ = mkvspec_ty_and_id($1,lsing($3)); }
1186 itopdecls : itopdecl { $$ = $1; }
1187 | itopdecls SEMI itopdecl { $$ = mkabind($1,$3); }
1190 itopdecl: ityped { $$ = $1; }
1191 | idatad { $$ = $1; }
1192 | iclassd { $$ = $1; }
1193 | iinstd { $$ = $1; }
1194 | ivarsd { $$ = $1; }
1195 | /* empty */ { $$ = mknullbind(); }
1198 /* partain: see comment elsewhere about why "type", not "context" */
1199 ivarsd : vars DCOLON type DARROW type ival_pragma
1200 { $$ = mksbind($1,mkcontext(type2context($3),$5),startlineno,$6); }
1201 | vars DCOLON type ival_pragma
1202 { $$ = mksbind($1,$3,startlineno,$4); }
1205 ityped : typekey simple EQUAL type itype_pragma
1206 { $$ = mknbind($2,$4,startlineno,$5); }
1209 idatad : datakey context DARROW simple idata_pragma
1210 { $$ = mktbind($2,$4,Lnil,Lnil,startlineno,$5); }
1211 | datakey simple idata_pragma
1212 { $$ = mktbind(Lnil,$2,Lnil,Lnil,startlineno,$3); }
1213 | datakey context DARROW simple EQUAL constrs idata_pragma
1214 { $$ = mktbind($2,$4,$6,Lnil,startlineno,$7); }
1215 | datakey simple EQUAL constrs idata_pragma
1216 { $$ = mktbind(Lnil,$2,$4,Lnil,startlineno,$5); }
1217 | datakey context DARROW simple EQUAL constrs DERIVING tyclses
1218 { $$ = mktbind($2,$4,$6,$8,startlineno,mkno_pragma()); }
1219 | datakey simple EQUAL constrs DERIVING tyclses
1220 { $$ = mktbind(Lnil,$2,$4,$6,startlineno,mkno_pragma()); }
1223 iclassd : classkey context DARROW class iclas_pragma cbody
1224 { $$ = mkcbind($2,$4,$6,startlineno,$5); }
1225 | classkey class iclas_pragma cbody
1226 { $$ = mkcbind(Lnil,$2,$4,startlineno,$3); }
1229 iinstd : instkey context DARROW tycls inst iinst_pragma
1230 { $$ = mkibind($2,$4,$5,mknullbind(),startlineno,$6); }
1231 | instkey tycls inst iinst_pragma
1232 { $$ = mkibind(Lnil,$2,$3,mknullbind(),startlineno,$4); }
1236 /* obsolete: "(C a, ...)" cause r/r conflict, resolved in favour of context rather than type */
1238 class : tycon tyvar { $$ = mktname($1,lsing($2)); }
1239 /* partain: changed "tycls" to "tycon" */
1242 types : type { $$ = lsing($1); }
1243 | types COMMA type { $$ = lapp($1,$3); }
1246 type : btype { $$ = $1; }
1247 | btype RARROW type { $$ = mktfun($1,$3); }
1249 | FORALL core_tv_templates DARROW type
1250 { $$ = mkuniforall($2, $4); }
1252 btype : atype { $$ = $1; }
1253 | tycon atypes { $$ = mktname($1,$2); }
1256 atypes : atypes atype { $$ = lapp($1,$2); }
1257 | atype { $$ = lsing($1); }
1260 /* The split with ntatype allows us to use the same syntax for defaults as for types */
1261 ttype : ntatype { $$ = $1; }
1262 | btype RARROW type { $$ = mktfun($1,$3); }
1263 | tycon atypes { $$ = mktname($1,$2); }
1267 | OPAREN type COMMA types CPAREN { $$ = mkttuple(mklcons($2,$4)); }
1270 ntatype : tyvar { $$ = $1; }
1271 | tycon { $$ = mktname($1,Lnil); }
1272 | OPAREN CPAREN { $$ = mkttuple(Lnil); }
1273 | OPAREN type CPAREN { $$ = $2; }
1274 | OBRACK type CBRACK { $$ = mktllist($2); }
1276 | OCURLY OCURLY CONID type CCURLY CCURLY
1277 { $$ = mkunidict($3, $4); }
1278 | TYVAR_TEMPLATE_ID { $$ = mkunityvartemplate($1); }
1282 simple : tycon { $$ = mktname($1,Lnil); }
1283 | tycon tyvars { $$ = mktname($1,$2); }
1287 simple_long : tycon atypes { $$ = mktname($1,$2); }
1288 ; /* partain: see comment in "inst" */
1289 /* partain: "atypes" should be "tyvars" if you want to
1290 avoid "extended instances" by syntactic means. */
1293 constrs : constr { $$ = lsing($1); }
1294 | constrs VBAR constr { $$ = lapp($1,$3); }
1297 /* Using tycon rather than con avoids 5 S/R errors */
1298 constr : tycon atypes { $$ = mkatc($1,$2,hsplineno); }
1299 | OPAREN CONSYM CPAREN atypes { $$ = mkatc($2,$4,hsplineno); }
1300 | tycon { $$ = mkatc($1,Lnil,hsplineno); }
1301 | OPAREN CONSYM CPAREN { $$ = mkatc($2,Lnil,hsplineno); }
1302 | btype conop btype { $$ = mkatc($2, ldub($1,$3),hsplineno); }
1305 tyclses : OPAREN tycls_list CPAREN { $$ = $2; }
1306 | OPAREN CPAREN { $$ = Lnil; }
1307 | tycls { $$ = lsing($1); }
1310 tycls_list: tycls { $$ = lsing($1); }
1311 | tycls_list COMMA tycls { $$ = lapp($1,$3); }
1314 context : OPAREN context_list CPAREN { $$ = $2; }
1315 | class { $$ = lsing($1); }
1318 context_list: class { $$ = lsing($1); }
1319 | context_list COMMA class { $$ = lapp($1,$3); }
1322 instdefs : /* empty */ { $$ = mknullbind(); }
1323 | instdef { $$ = $1; }
1324 | instdefs SEMI instdef
1332 $$ = mkabind($1,$3);
1336 /* instdef: same as valdef, except certain user-pragmas may appear */
1338 INLINE_UPRAGMA vark howto_inline_maybe END_UPRAGMA
1340 $$ = mkinline_uprag($2, $3, startlineno);
1341 PREVPATT = NULL; FN = NULL; SAMEFN = 0;
1344 | MAGIC_UNFOLDING_UPRAGMA vark vark END_UPRAGMA
1346 $$ = mkmagicuf_uprag($2, $3, startlineno);
1347 PREVPATT = NULL; FN = NULL; SAMEFN = 0;
1354 vars : vark COMMA varsrest { $$ = mklcons($1,$3); }
1355 | vark { $$ = lsing($1); }
1356 /* right recursion ? WDP */
1359 varsrest: var { $$ = lsing($1); }
1360 | varsrest COMMA var { $$ = lapp($1,$3); }
1363 cons : con { $$ = lsing($1); }
1364 | cons COMMA con { $$ = lapp($1,$3); }
1370 tree fn = function($1);
1374 if(ttree(fn) == ident)
1376 checksamefn(gident((struct Sident *) fn));
1380 else if (ttree(fn) == tinfixop && ttree(ginfun((struct Sap *) fn)) == ident)
1382 checksamefn(gident((struct Sident *) (ginfun((struct Sap *) fn))));
1383 FN = ginfun((struct Sap *) fn);
1388 printf("%u\n",startlineno);
1390 fprintf(stderr,"%u\tvaldef\n",startlineno);
1395 if ( lhs_is_patt($1) )
1397 $$ = mkpbind($3, startlineno);
1401 else /* lhs is function */
1402 $$ = mkfbind($3,startlineno);
1408 valrhs : valrhs1 maybe_where { $$ = lsing(createpat($1, $2)); }
1412 | EQUAL exp { $$ = lsing(mktruecase($2)); }
1415 gdrhs : gd EQUAL exp { $$ = lsing(ldub($1,$3)); }
1416 | gd EQUAL exp gdrhs { $$ = mklcons(ldub($1,$3),$4); }
1420 WHERE ocurly decls ccurly { $$ = $3; }
1421 | WHERE vocurly decls vccurly { $$ = $3; }
1422 | /* empty */ { $$ = mknullbind(); }
1425 gd : VBAR oexp { $$ = $2; }
1429 lampats : apat lampats { $$ = mklcons($1,$2); }
1430 | apat { $$ = lsing($1); }
1431 ; /* right recursion? (WDP) */
1435 Changed as above to allow for contexts!
1439 exp : oexp DCOLON type DARROW type { $$ = mkrestr($1,mkcontext(type2context($3),$5)); }
1440 | oexp DCOLON type { $$ = mkrestr($1,$3); }
1445 Operators must be left-associative at the same precedence
1446 for prec. parsing to work.
1449 /* Infix operator application */
1451 | oexp op oexp %prec PLUS
1452 { $$ = mkinfixop($2,$1,$3); precparse($$); }
1456 This comes here because of the funny precedence rules concerning
1461 dexp : MINUS kexp { $$ = mknegate($2); }
1466 let/if/lambda/case have higher precedence than infix operators.
1470 { /* enteriscope(); /? I don't understand this -- KH */
1471 hsincindent(); /* added by partain; push new context for */
1472 /* FN = NULL; not actually concerned about */
1473 FN = NULL; /* indenting */
1474 $<uint>$ = hsplineno; /* remember current line number */
1477 { hsendindent(); /* added by partain */
1478 /* exitiscope(); /? Also not understood */
1480 RARROW exp /* lambda abstraction */
1482 $$ = mklambda($3, $6, $<uint>2);
1485 /* Let Expression */
1486 | LET ocurly decls ccurly IN exp { $$ = mklet($3,$6); }
1487 | LET vocurly decls vccurly IN exp { $$ = mklet($3,$6); }
1490 | IF exp THEN exp ELSE exp { $$ = mkife($2,$4,$6); }
1492 /* Case Expression */
1493 | CASE exp OF ocurly alts ccurly { $$ = mkcasee($2,$5); }
1494 | CASE exp OF vocurly alts vccurly { $$ = mkcasee($2,$5); }
1496 /* CCALL/CASM Expression */
1497 | CCALL ccallid cexp { $$ = mkccall($2,installid("n"),$3); }
1498 | CCALL ccallid { $$ = mkccall($2,installid("n"),Lnil); }
1499 | CCALL_GC ccallid cexp { $$ = mkccall($2,installid("p"),$3); }
1500 | CCALL_GC ccallid { $$ = mkccall($2,installid("p"),Lnil); }
1501 | CASM CLITLIT cexp { $$ = mkccall($2,installid("N"),$3); }
1502 | CASM CLITLIT { $$ = mkccall($2,installid("N"),Lnil); }
1503 | CASM_GC CLITLIT cexp { $$ = mkccall($2,installid("P"),$3); }
1504 | CASM_GC CLITLIT { $$ = mkccall($2,installid("P"),Lnil); }
1506 /* SCC Expression */
1508 { extern BOOLEAN ignoreSCC;
1509 extern BOOLEAN warnSCC;
1514 "\"%s\", line %d: _scc_ (`set [profiling] cost centre') ignored\n",
1515 input_filename, hsplineno);
1525 /* Function application */
1526 fexp : fexp aexp { $$ = mkap($1,$2); }
1530 cexp : cexp aexp { $$ = lapp($1,$2); }
1531 | aexp { $$ = lsing($1); }
1535 The mkpars are so that infix parsing doesn't get confused.
1540 /* Simple Expressions */
1541 aexp : var { $$ = mkident($1); }
1542 | con { $$ = mkident($1); }
1543 | lit_constant { $$ = mklit($1); }
1544 | OPAREN exp CPAREN { $$ = mkpar($2); }
1545 | OPAREN oexp op CPAREN { checkprec($2,$3,FALSE); $$ = mklsection($2,$3); }
1546 | OPAREN op1 oexp CPAREN { checkprec($3,$2,TRUE); $$ = mkrsection($2,$3); }
1550 | list { $$ = mkpar($1); }
1551 | sequence { $$ = mkpar($1); }
1552 | comprehension { $$ = mkpar($1); }
1554 /* These only occur in patterns */
1555 | var AT aexp { checkinpat(); $$ = mkas($1,$3); }
1556 | WILDCARD { checkinpat(); $$ = mkwildp(); }
1557 | LAZY aexp { checkinpat(); $$ = mklazyp($2); }
1562 LHS patterns are parsed in a similar way to
1563 expressions. This avoids the horrible non-LRness
1564 which occurs with the 1.1 syntax.
1566 The xpatk business is to do with accurately recording
1567 the starting line for definitions.
1573 { $$ = mkap($1,$2); }
1574 | opatk varop opat %prec PLUS
1576 $$ = mkinfixop($2,$1,$3);
1581 | opatk conop opat %prec PLUS
1583 $$ = mkinfixop($2,$1,$3);
1591 | opatk op opat %prec PLUS
1593 $$ = mkinfixop($2,$1,$3);
1595 if(isconstr(id_to_string($2)))
1599 checkprec($1,$2,FALSE); /* Check the precedence of the left pattern */
1600 checkprec($3,$2,TRUE); /* then check the right pattern */
1606 | opat op opat %prec PLUS
1608 $$ = mkinfixop($2,$1,$3);
1610 if(isconstr(id_to_string($2)))
1614 checkprec($1,$2,FALSE); /* Check the precedence of the left pattern */
1615 checkprec($3,$2,TRUE); /* then check the right pattern */
1621 This comes here because of the funny precedence rules concerning
1626 dpat : MINUS fpat { $$ = mknegate($2); }
1630 /* Function application */
1631 fpat : fpat aapat { $$ = mkap($1,$2); }
1635 dpatk : minuskey fpat { $$ = mknegate($2); }
1639 /* Function application */
1640 fpatk : fpatk aapat { $$ = mkap($1,$2); }
1644 aapat : con { $$ = mkident($1); }
1645 | var { $$ = mkident($1); }
1646 | var AT apat { $$ = mkas($1,$3); }
1647 | lit_constant { $$ = mklit($1); }
1648 | WILDCARD { $$ = mkwildp(); }
1649 | OPAREN CPAREN { $$ = mktuple(Lnil); }
1650 | OPAREN var PLUS INTEGER CPAREN { $$ = mkplusp(mkident($2),mkinteger($4)); }
1651 /* GHC cannot do these anyway. WDP 93/11/15
1652 | OPAREN WILDCARD PLUS INTEGER CPAREN { $$ = mkplusp(mkwildp(),mkinteger($4)); }
1654 | OPAREN opat CPAREN { $$ = mkpar($2); }
1655 | OPAREN opat COMMA pats CPAREN { $$ = mktuple(mklcons($2,$4)); }
1656 | OBRACK pats CBRACK { $$ = mkllist($2); }
1657 | OBRACK CBRACK { $$ = mkllist(Lnil); }
1658 | LAZY apat { $$ = mklazyp($2); }
1661 aapatk : conk { $$ = mkident($1); }
1662 | vark { $$ = mkident($1); }
1663 | vark AT apat { $$ = mkas($1,$3); }
1664 | lit_constant { $$ = mklit($1); setstartlineno(); }
1665 | WILDCARD { $$ = mkwildp(); setstartlineno(); }
1666 | oparenkey CPAREN { $$ = mktuple(Lnil); }
1667 | oparenkey var PLUS INTEGER CPAREN { $$ = mkplusp(mkident($2),mkinteger($4)); }
1668 /* GHC no cannae do (WDP 95/05)
1669 | oparenkey WILDCARD PLUS INTEGER CPAREN { $$ = mkplusp(mkwildp(),mkinteger($4)); }
1671 | oparenkey opat CPAREN { $$ = mkpar($2); }
1672 | oparenkey opat COMMA pats CPAREN { $$ = mktuple(mklcons($2,$4)); }
1673 | obrackkey pats CBRACK { $$ = mkllist($2); }
1674 | obrackkey CBRACK { $$ = mkllist(Lnil); }
1675 | lazykey apat { $$ = mklazyp($2); }
1680 The mkpars are so that infix parsing doesn't get confused.
1685 tuple : OPAREN exp COMMA texps CPAREN
1686 { if (ttree($4) == tuple)
1687 $$ = mktuple(mklcons($2, gtuplelist((struct Stuple *) $4)));
1689 $$ = mktuple(ldub($2, $4));
1692 { $$ = mktuple(Lnil); }
1695 texps : exp { $$ = mkpar($1); }
1697 { if (ttree($3) == tuple)
1698 $$ = mktuple(mklcons($1, gtuplelist((struct Stuple *) $3)));
1700 $$ = mktuple(ldub($1, $3));
1702 /* right recursion? WDP */
1706 list : OBRACK CBRACK { $$ = mkllist(Lnil); }
1707 | OBRACK list_exps CBRACK { $$ = mkllist($2); }
1711 exp { $$ = lsing($1); }
1712 | exp COMMA list_exps { $$ = mklcons($1, $3); }
1713 /* right recursion? (WDP)
1715 It has to be this way, though, otherwise you
1716 may do the wrong thing to distinguish between...
1718 [ e1 , e2 .. ] -- an enumeration ...
1719 [ e1 , e2 , e3 ] -- a list
1721 (In fact, if you change the grammar and throw yacc/bison
1722 at it, it *will* do the wrong thing [WDP 94/06])
1727 sequence: OBRACK exp COMMA exp DOTDOT upto CBRACK {$$ = mkeenum($2,lsing($4),$6);}
1728 | OBRACK exp DOTDOT upto CBRACK { $$ = mkeenum($2,Lnil,$4); }
1731 comprehension: OBRACK exp VBAR quals CBRACK { $$ = mkcomprh($2,$4); }
1734 quals : qual { $$ = lsing($1); }
1735 | quals COMMA qual { $$ = lapp($1,$3); }
1738 qual : { inpat = TRUE; } exp { inpat = FALSE; } qualrest
1746 tree prevpatt_save = PREVPATT;
1748 $$ = mkdef((tree) mkpbind(lsing(createpat(lsing(mktruecase(ggdef((struct Sdef *) $4))),mknullbind())),hsplineno));
1749 PREVPATT = prevpatt_save;
1757 qualrest: LARROW exp { $$ = $2; }
1758 | /* empty */ { $$ = NULL; }
1761 alts : alt { $$ = $1; }
1762 | alts SEMI alt { $$ = lconc($1,$3); }
1771 | /* empty */ { $$ = Lnil; }
1774 altrest : gdpat maybe_where { $$ = lsing(createpat($1, $2)); }
1775 | RARROW exp maybe_where { $$ = lsing(createpat(lsing(mktruecase($2)), $3)); }
1778 gdpat : gd RARROW exp gdpat { $$ = mklcons(ldub($1,$3),$4); }
1779 | gd RARROW exp { $$ = lsing(ldub($1,$3)); }
1782 upto : /* empty */ { $$ = Lnil; }
1783 | exp { $$ = lsing($1); }
1786 pats : pat COMMA pats { $$ = mklcons($1, $3); }
1787 | pat { $$ = lsing($1); }
1788 /* right recursion? (WDP) */
1792 | pat conop bpat { $$ = mkinfixop($2,$1,$3); precparse($$); }
1797 | MINUS INTEGER { $$ = mklit(mkinteger(ineg($2))); }
1798 | MINUS FLOAT { $$ = mklit(mkfloatr(ineg($2))); }
1801 conpat : con { $$ = mkident($1); }
1802 | conpat apat { $$ = mkap($1,$2); }
1805 apat : con { $$ = mkident($1); }
1809 apatc : var { $$ = mkident($1); }
1810 | var AT apat { $$ = mkas($1,$3); }
1811 | lit_constant { $$ = mklit($1); }
1812 | WILDCARD { $$ = mkwildp(); }
1813 | OPAREN CPAREN { $$ = mktuple(Lnil); }
1814 | OPAREN var PLUS INTEGER CPAREN { $$ = mkplusp(mkident($2),mkinteger($4)); }
1815 /* GHC no cannae do (WDP 95/05)
1816 | OPAREN WILDCARD PLUS INTEGER CPAREN { $$ = mkplusp(mkwildp(),mkinteger($4)); }
1818 | OPAREN pat CPAREN { $$ = mkpar($2); }
1819 | OPAREN pat COMMA pats CPAREN { $$ = mktuple(mklcons($2,$4)); }
1820 | OBRACK pats CBRACK { $$ = mkllist($2); }
1821 | OBRACK CBRACK { $$ = mkllist(Lnil); }
1822 | LAZY apat { $$ = mklazyp($2); }
1826 INTEGER { $$ = mkinteger($1); }
1827 | FLOAT { $$ = mkfloatr($1); }
1828 | CHAR { $$ = mkcharr($1); }
1829 | STRING { $$ = mkstring($1); }
1830 | CHARPRIM { $$ = mkcharprim($1); }
1831 | STRINGPRIM { $$ = mkstringprim($1); }
1832 | INTPRIM { $$ = mkintprim($1); }
1833 | FLOATPRIM { $$ = mkfloatprim($1); }
1834 | DOUBLEPRIM { $$ = mkdoubleprim($1); }
1835 | CLITLIT /* yurble yurble */ { $$ = mkclitlit($1, ""); }
1836 | CLITLIT KIND_PRAGMA CONID { $$ = mkclitlit($1, $3); }
1837 | NOREP_INTEGER INTEGER { $$ = mknorepi($2); }
1838 | NOREP_RATIONAL INTEGER INTEGER { $$ = mknorepr($2, $3); }
1839 | NOREP_STRING STRING { $$ = mknoreps($2); }
1843 /* Keywords which record the line start */
1845 importkey: IMPORT { setstartlineno(); }
1848 datakey : DATA { setstartlineno();
1851 printf("%u\n",startlineno);
1853 fprintf(stderr,"%u\tdata\n",startlineno);
1858 typekey : TYPE { setstartlineno();
1861 printf("%u\n",startlineno);
1863 fprintf(stderr,"%u\ttype\n",startlineno);
1868 instkey : INSTANCE { setstartlineno();
1871 printf("%u\n",startlineno);
1874 fprintf(stderr,"%u\tinstance\n",startlineno);
1879 defaultkey: DEFAULT { setstartlineno(); }
1882 classkey: CLASS { setstartlineno();
1885 printf("%u\n",startlineno);
1887 fprintf(stderr,"%u\tclass\n",startlineno);
1892 minuskey: MINUS { setstartlineno(); }
1895 modulekey: MODULE { setstartlineno();
1898 printf("%u\n",startlineno);
1900 fprintf(stderr,"%u\tmodule\n",startlineno);
1905 oparenkey: OPAREN { setstartlineno(); }
1908 obrackkey: OBRACK { setstartlineno(); }
1911 lazykey : LAZY { setstartlineno(); }
1916 /* Non "-" op, used in right sections -- KH */
1926 | BQUOTE VARID BQUOTE { $$ = $2; }
1929 /* Non-minus varop, used in right sections */
1932 | BQUOTE VARID BQUOTE { $$ = $2; }
1936 | BQUOTE CONID BQUOTE { $$ = $2; }
1944 minus : MINUS { $$ = install_literal("-"); }
1947 plus : PLUS { $$ = install_literal("+"); }
1951 | OPAREN varsym CPAREN { $$ = $2; }
1954 vark : VARID { setstartlineno(); $$ = $1; }
1955 | oparenkey varsym CPAREN { $$ = $2; }
1958 /* tycon used here to eliminate 11 spurious R/R errors -- KH */
1960 | OPAREN CONSYM CPAREN { $$ = $2; }
1963 conk : tycon { setstartlineno(); $$ = $1; }
1964 | oparenkey CONSYM CPAREN { $$ = $2; }
1971 /* partain: "atype_list" must be at least 2 elements long (defn of "inst") */
1972 atype_list: atype COMMA atype { $$ = mklcons($1,lsing($3)); }
1973 | atype COMMA atype_list { $$ = mklcons($1,$3); }
1974 /* right recursion? WDP */
1977 tyvars : tyvar { $$ = lsing($1); }
1978 | tyvars tyvar { $$ = lapp($1, $2); }
1981 tyvar : VARID { $$ = mknamedtvar($1); }
1985 /* partain: "aconid"->"tycon" got rid of a r/r conflict
1986 (and introduced >= 2 s/r's ...)
1997 ocurly : layout OCURLY { hsincindent(); }
1999 vocurly : layout { hssetindent(); }
2002 layout : { hsindentoff(); }
2008 FN = NULL; SAMEFN = 0; PREVPATT = NULL;
2013 vccurly : { expect_ccurly = 1; } vccurly1 { expect_ccurly = 0; }
2019 FN = NULL; SAMEFN = 0; PREVPATT = NULL;
2025 FN = NULL; SAMEFN = 0; PREVPATT = NULL;
2032 /**********************************************************************
2034 * Error Processing and Reporting *
2036 * (This stuff is here in case we want to use Yacc macros and such.) *
2038 **********************************************************************/
2040 /* The parser calls "hsperror" when it sees a
2041 `report this and die' error. It sets the stage
2042 and calls "yyerror".
2044 There should be no direct calls in the parser to
2045 "yyerror", except for the one from "hsperror". Thus,
2046 the only other calls will be from the error productions
2047 introduced by yacc/bison/whatever.
2049 We need to be able to recognise the from-error-production
2050 case, because we sometimes want to say, "Oh, never mind",
2051 because the layout rule kicks into action and may save
2055 static BOOLEAN error_and_I_mean_it = FALSE;
2061 error_and_I_mean_it = TRUE;
2069 extern char *yytext;
2072 /* We want to be able to distinguish 'error'-raised yyerrors
2073 from yyerrors explicitly coded by the parser hacker.
2075 if (expect_ccurly && ! error_and_I_mean_it ) {
2079 fprintf(stderr, "\"%s\", line %d, column %d: %s on input: ",
2080 input_filename, hsplineno, hspcolno + 1, s);
2082 if (yyleng == 1 && *yytext == '\0')
2083 fprintf(stderr, "<EOF>");
2087 format_string(stderr, (unsigned char *) yytext, yyleng);
2090 fputc('\n', stderr);
2092 /* a common problem */
2093 if (strcmp(yytext, "#") == 0)
2094 fprintf(stderr, "\t(Perhaps you forgot a `-cpp' or `-fglasgow-exts' flag?)\n");
2101 format_string(fp, s, len)
2108 case '\0': fputs("\\NUL", fp); break;
2109 case '\007': fputs("\\a", fp); break;
2110 case '\010': fputs("\\b", fp); break;
2111 case '\011': fputs("\\t", fp); break;
2112 case '\012': fputs("\\n", fp); break;
2113 case '\013': fputs("\\v", fp); break;
2114 case '\014': fputs("\\f", fp); break;
2115 case '\015': fputs("\\r", fp); break;
2116 case '\033': fputs("\\ESC", fp); break;
2117 case '\034': fputs("\\FS", fp); break;
2118 case '\035': fputs("\\GS", fp); break;
2119 case '\036': fputs("\\RS", fp); break;
2120 case '\037': fputs("\\US", fp); break;
2121 case '\177': fputs("\\DEL", fp); break;
2126 fprintf(fp, "\\^%c", *s + '@');