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 static BOOLEAN expect_ccurly = FALSE; /* Used to signal that a CCURLY could be inserted here */
45 extern char *input_filename;
46 static char *the_module_name;
47 static maybe module_exports;
50 extern list reverse_list();
53 /* For FN, PREVPATT and SAMEFN macros */
55 extern BOOLEAN samefn[];
56 extern tree prevpatt[];
57 extern short icontexts;
60 extern int hsplineno, hspcolno;
61 extern int modulelineno;
62 extern int startlineno;
65 /**********************************************************************
68 * Fixity and Precedence Declarations *
71 **********************************************************************/
73 static int Fixity = 0, Precedence = 0;
75 char *ineg PROTO((char *));
77 long source_version = 0;
78 BOOLEAN pat_check=TRUE;
102 /**********************************************************************
105 * These are lexemes. *
108 **********************************************************************/
111 %token VARID CONID QVARID QCONID
112 VARSYM CONSYM QVARSYM QCONSYM
114 %token INTEGER FLOAT CHAR STRING
115 CHARPRIM STRINGPRIM INTPRIM FLOATPRIM
120 /**********************************************************************
126 **********************************************************************/
128 %token OCURLY CCURLY VCCURLY
129 %token COMMA SEMI OBRACK CBRACK
130 %token WILDCARD BQUOTE OPAREN CPAREN
131 %token OUNBOXPAREN CUNBOXPAREN
134 /**********************************************************************
137 * Reserved Operators *
140 **********************************************************************/
142 %token DOTDOT DCOLON EQUAL LAMBDA
143 %token VBAR RARROW LARROW
144 %token AT LAZY DARROW
147 /**********************************************************************
150 * Reserved Identifiers *
153 **********************************************************************/
155 %token CASE CLASS DATA
156 %token DEFAULT DERIVING DO
157 %token ELSE IF IMPORT
158 %token IN INFIX INFIXL
159 %token INFIXR INSTANCE LET
160 %token MODULE NEWTYPE OF
161 %token THEN TYPE WHERE
164 %token CCALL CCALL_GC CASM CASM_GC
167 %token EXPORT UNSAFE STDCALL C_CALL LABEL
168 %token PASCAL FASTCALL FOREIGN DYNAMIC
170 /**********************************************************************
173 * Special symbols/identifiers which need to be recognised *
176 **********************************************************************/
178 %token MINUS BANG PLUS
179 %token AS HIDING QUALIFIED
182 /**********************************************************************
185 * Special Symbols for the Lexer *
188 **********************************************************************/
190 %token INTERFACE_UPRAGMA SPECIALISE_UPRAGMA
191 %token INLINE_UPRAGMA NOINLINE_UPRAGMA MAGIC_UNFOLDING_UPRAGMA
193 %token SOURCE_UPRAGMA
195 /**********************************************************************
198 * Precedences of the various tokens *
201 **********************************************************************/
206 SCC CASM CCALL CASM_GC CCALL_GC
208 %left VARSYM CONSYM QVARSYM QCONSYM
209 MINUS BQUOTE BANG DARROW PLUS
215 %left OCURLY OBRACK OPAREN
221 /**********************************************************************
224 * Type Declarations *
227 **********************************************************************/
230 %type <ulist> caserest alts alt quals
232 rbinds rbinds1 rpats rpats1 list_exps list_rest
234 constrs constr1 fields conargatypes
237 pats simple_context simple_context_list
240 impdecls maybeimpdecls impdecl
241 maybefixes fixes fix ops
244 lampats cexps gd texps
245 tyvars1 constr_context forall
247 %type <umaybe> maybeexports impspec deriving
250 %type <uliteral> lit_constant
252 %type <utree> exp oexp dexp kexp fexp aexp rbind
253 expL oexpL kexpL expLno oexpLno dexpLno kexpLno
254 vallhs funlhs qual leftexp
255 pat cpat bpat apat apatc conpat rpat
256 patk bpatk apatck conpatk
259 %type <uid> MINUS PLUS DARROW AS LAZY
260 VARID CONID VARSYM CONSYM
261 var con varop conop op
262 vark varid varsym varsym_nominus
263 tycon modid ccallid tyvar
266 %type <uqid> QVARID QCONID QVARSYM QCONSYM
267 qvarid qconid qvarsym qconsym
268 qvar qcon qvarop qconop qop
269 qvark qconk qtycon qtycls
270 gcon gconk gtycon itycon qop1 qvarop1
273 %type <ubinding> topdecl topdecls letdecls
274 typed datad newtd classd instd defaultd foreignd
275 decl decls valdef instdef instdefs
276 maybe_where cbody rinst type_and_maybe_id
278 %type <upbinding> valrhs1 altrest
280 %type <uttype> polytype
281 conargatype conapptype
285 simple_con_app simple_con_app1 inst_type
287 %type <uconstr> constr constr_after_context field
289 %type <ustring> FLOAT INTEGER INTPRIM
290 FLOATPRIM DOUBLEPRIM CLITLIT
292 %type <uhstring> STRING STRINGPRIM CHAR CHARPRIM
294 %type <uentid> export import
296 %type <ulong> commas importkey get_line_no
299 /**********************************************************************
302 * Start Symbol for the Parser *
305 **********************************************************************/
310 module : modulekey modid maybeexports
312 modulelineno = startlineno;
313 the_module_name = $2;
319 the_module_name = install_literal("Main");
320 module_exports = mknothing();
325 body : ocurly { setstartlineno(); } interface_pragma orestm
326 | vocurly interface_pragma vrestm
329 interface_pragma : /* empty */
330 | INTERFACE_UPRAGMA INTEGER END_UPRAGMA SEMI
332 source_version = atoi($2);
336 orestm : maybeimpdecls maybefixes topdecls ccurly
338 root = mkhmodule(the_module_name,$1,module_exports,
339 $2,$3,source_version,modulelineno);
343 root = mkhmodule(the_module_name,$1,module_exports,
344 Lnil,mknullbind(),source_version,modulelineno);
347 vrestm : maybeimpdecls maybefixes topdecls vccurly
349 root = mkhmodule(the_module_name,$1,module_exports,
350 $2,$3,source_version,modulelineno);
354 root = mkhmodule(the_module_name,$1,module_exports,
355 Lnil,mknullbind(),source_version,modulelineno);
358 maybeexports : /* empty */ { $$ = mknothing(); }
359 | OPAREN export_list CPAREN { $$ = mkjust($2); }
360 | OPAREN export_list COMMA CPAREN { $$ = mkjust($2); }
364 export { $$ = lsing($1); }
365 | export_list COMMA export { $$ = lapp($1, $3); }
368 export : qvar { $$ = mkentid($1); }
369 | gtycon { $$ = mkenttype($1); }
370 | gtycon OPAREN DOTDOT CPAREN { $$ = mkenttypeall($1); }
371 | gtycon OPAREN CPAREN { $$ = mkenttypenamed($1,Lnil); }
372 | gtycon OPAREN enames CPAREN { $$ = mkenttypenamed($1,$3); }
373 | MODULE modid { $$ = mkentmod($2); }
376 enames : ename { $$ = lsing($1); }
377 | enames COMMA ename { $$ = lapp($1,$3); }
384 maybeimpdecls : /* empty */ { $$ = Lnil; }
385 | impdecls SEMI { $$ = $1; }
388 impdecls: impdecl { $$ = $1; }
389 | impdecls SEMI impdecl { $$ = lconc($1,$3); }
393 impdecl : importkey modid impspec
394 { $$ = lsing(mkimport($2,0,mknothing(),$3,$1,startlineno)); }
395 | importkey QUALIFIED modid impspec
396 { $$ = lsing(mkimport($3,1,mknothing(),$4,$1,startlineno)); }
397 | importkey QUALIFIED modid AS modid impspec
398 { $$ = lsing(mkimport($3,1,mkjust($5),$6,$1,startlineno)); }
399 | importkey modid AS modid impspec
400 { $$ = lsing(mkimport($3,1,mkjust($4),$5,$1,startlineno)); }
403 impspec : /* empty */ { $$ = mknothing(); }
404 | OPAREN CPAREN { $$ = mkjust(mkleft(Lnil)); }
405 | OPAREN import_list CPAREN { $$ = mkjust(mkleft($2)); }
406 | OPAREN import_list COMMA CPAREN { $$ = mkjust(mkleft($2)); }
407 | HIDING OPAREN import_list CPAREN { $$ = mkjust(mkright($3)); }
408 | HIDING OPAREN import_list COMMA CPAREN { $$ = mkjust(mkright($3)); }
412 import { $$ = lsing($1); }
413 | import_list COMMA import { $$ = lapp($1, $3); }
416 import : var { $$ = mkentid(mknoqual($1)); }
417 | itycon { $$ = mkenttype($1); }
418 | itycon OPAREN DOTDOT CPAREN { $$ = mkenttypeall($1); }
419 | itycon OPAREN CPAREN { $$ = mkenttypenamed($1,Lnil);}
420 | itycon OPAREN inames CPAREN { $$ = mkenttypenamed($1,$3); }
423 itycon : tycon { $$ = mknoqual($1); }
424 | OBRACK CBRACK { $$ = creategid(NILGID); }
425 | OPAREN CPAREN { $$ = creategid(UNITGID); }
426 | OPAREN commas CPAREN { $$ = creategid($2); }
429 inames : iname { $$ = lsing($1); }
430 | inames COMMA iname { $$ = lapp($1,$3); }
432 iname : var { $$ = mknoqual($1); }
433 | con { $$ = mknoqual($1); }
436 /**********************************************************************
439 * Fixes and Decls etc *
442 **********************************************************************/
444 maybefixes: /* empty */ { $$ = Lnil; }
445 | fixes SEMI { $$ = $1; }
448 fixes : fix { $$ = $1; }
449 | fixes SEMI fix { $$ = lconc($1,$3); }
452 fix : INFIXL INTEGER { Precedence = checkfixity($2); Fixity = INFIXL; }
454 | INFIXR INTEGER { Precedence = checkfixity($2); Fixity = INFIXR; }
456 | INFIX INTEGER { Precedence = checkfixity($2); Fixity = INFIX; }
458 | INFIXL { Fixity = INFIXL; Precedence = 9; }
460 | INFIXR { Fixity = INFIXR; Precedence = 9; }
462 | INFIX { Fixity = INFIX; Precedence = 9; }
466 ops : op { $$ = lsing(mkfixop(mknoqual($1),infixint(Fixity),Precedence,startlineno)); }
467 | ops COMMA op { $$ = lapp($1,mkfixop(mknoqual($3),infixint(Fixity),Precedence,startlineno)); }
471 | topdecls SEMI topdecl
490 topdecl : typed { $$ = $1; FN = NULL; SAMEFN = 0; }
491 | datad { $$ = $1; FN = NULL; SAMEFN = 0; }
492 | newtd { $$ = $1; FN = NULL; SAMEFN = 0; }
493 | classd { $$ = $1; FN = NULL; SAMEFN = 0; }
494 | instd { $$ = $1; FN = NULL; SAMEFN = 0; }
495 | defaultd { $$ = $1; FN = NULL; SAMEFN = 0; }
496 | foreignd { $$ = $1; FN = NULL; SAMEFN = 0; }
500 typed : typekey simple_con_app EQUAL tautype { $$ = mknbind($2,$4,startlineno); }
504 datad : datakey simple_con_app EQUAL constrs deriving
505 { $$ = mktbind(Lnil,$2,$4,$5,startlineno); }
506 | datakey simple_context DARROW simple_con_app EQUAL constrs deriving
507 { $$ = mktbind($2,$4,$6,$7,startlineno); }
510 newtd : newtypekey simple_con_app EQUAL constr1 deriving
511 { $$ = mkntbind(Lnil,$2,$4,$5,startlineno); }
512 | newtypekey simple_context DARROW simple_con_app EQUAL constr1 deriving
513 { $$ = mkntbind($2,$4,$6,$7,startlineno); }
516 deriving: /* empty */ { $$ = mknothing(); }
517 | DERIVING dtyclses { $$ = mkjust($2); }
520 classd : classkey apptype DARROW simple_con_app1 cbody
521 /* Context can now be more than simple_context */
522 { $$ = mkcbind(type2context($2),$4,$5,startlineno); }
523 | classkey apptype cbody
524 /* We have to say apptype rather than simple_con_app1, else
525 we get reduce/reduce errs */
526 { check_class_decl_head($2);
527 $$ = mkcbind(Lnil,$2,$3,startlineno); }
530 cbody : /* empty */ { $$ = mknullbind(); }
531 | WHERE ocurly decls ccurly { checkorder($3); $$ = $3; }
532 | WHERE vocurly decls vccurly { checkorder($3); $$ = $3; }
535 instd : instkey inst_type rinst { $$ = mkibind($2,$3,startlineno); }
538 /* Compare polytype */
539 /* [July 98: first production was tautype DARROW tautype, but I can't see why.] */
540 inst_type : apptype DARROW apptype { is_context_format( $3, 0 ); /* Check the instance head */
541 $$ = mkforall(Lnil,type2context($1),$3); }
542 | apptype { is_context_format( $1, 0 ); /* Check the instance head */
547 rinst : /* empty */ { $$ = mknullbind(); }
548 | WHERE ocurly instdefs ccurly { $$ = $3; }
549 | WHERE vocurly instdefs vccurly { $$ = $3; }
552 defaultd: defaultkey OPAREN tautypes CPAREN { $$ = mkdbind($3,startlineno); }
553 | defaultkey OPAREN CPAREN { $$ = mkdbind(Lnil,startlineno); }
556 /* FFI primitive declarations - GHC/Hugs specific */
557 foreignd: foreignkey IMPORT callconv ext_name unsafe_flag qvarid DCOLON tautype { $$ = mkfobind($6,$8,$4,$5,$3,FOREIGN_IMPORT,startlineno); }
558 | foreignkey EXPORT callconv ext_name qvarid DCOLON tautype { $$ = mkfobind($5,$7,$4,0,$3,FOREIGN_EXPORT,startlineno); }
560 | foreignkey LABEL ext_name qvarid DCOLON tautype { $$ = mkfobind($4,$6,$3,0,-1,FOREIGN_LABEL,startlineno); }
563 callconv: STDCALL { $$ = CALLCONV_STDCALL; }
564 | C_CALL { $$ = CALLCONV_CCALL; }
565 | PASCAL { $$ = CALLCONV_PASCAL; }
566 | FASTCALL { $$ = CALLCONV_FASTCALL; }
567 /* If you leave out the specification of a calling convention, you'll (probably) get C's. */
568 | /*empty*/ { $$ = CALLCONV_NONE; }
571 ext_name: STRING { $$ = mkjust(lsing($1)); }
572 | STRING STRING { $$ = mkjust(mklcons ($1,lsing($2))); }
573 | DYNAMIC { $$ = mknothing(); }
575 unsafe_flag: UNSAFE { $$ = 1; }
576 | /*empty*/ { $$ = 0; }
595 Note: if there is an iclasop_pragma here, then we must be
596 doing a class-op in an interface -- unless the user is up
597 to real mischief (ugly, but likely to work).
600 decl : qvarsk DCOLON polytype
601 { $$ = mksbind($1,$3,startlineno);
602 PREVPATT = NULL; FN = NULL; SAMEFN = 0;
605 /* User-specified pragmas come in as "signatures"...
606 They are similar in that they can appear anywhere in the module,
607 and have to be "joined up" with their related entity.
609 Have left out the case specialising to an overloaded type.
610 Let's get real, OK? (WDP)
612 | SPECIALISE_UPRAGMA qvark DCOLON types_and_maybe_ids END_UPRAGMA
614 $$ = mkvspec_uprag($2, $4, startlineno);
615 PREVPATT = NULL; FN = NULL; SAMEFN = 0;
618 | SPECIALISE_UPRAGMA INSTANCE gtycon atype END_UPRAGMA
620 $$ = mkispec_uprag($3, $4, startlineno);
621 PREVPATT = NULL; FN = NULL; SAMEFN = 0;
624 | SPECIALISE_UPRAGMA DATA gtycon atypes END_UPRAGMA
626 $$ = mkdspec_uprag($3, $4, startlineno);
627 PREVPATT = NULL; FN = NULL; SAMEFN = 0;
630 | INLINE_UPRAGMA qvark END_UPRAGMA
632 $$ = mkinline_uprag($2, startlineno);
633 PREVPATT = NULL; FN = NULL; SAMEFN = 0;
636 | NOINLINE_UPRAGMA qvark END_UPRAGMA
638 $$ = mknoinline_uprag($2, startlineno);
639 PREVPATT = NULL; FN = NULL; SAMEFN = 0;
642 | MAGIC_UNFOLDING_UPRAGMA qvark vark END_UPRAGMA
644 $$ = mkmagicuf_uprag($2, $3, startlineno);
645 PREVPATT = NULL; FN = NULL; SAMEFN = 0;
648 /* end of user-specified pragmas */
651 | /* empty */ { $$ = mknullbind(); PREVPATT = NULL; FN = NULL; SAMEFN = 0; }
654 qvarsk : qvark COMMA qvars_list { $$ = mklcons($1,$3); }
655 | qvark { $$ = lsing($1); }
658 qvars_list: qvar { $$ = lsing($1); }
659 | qvars_list COMMA qvar { $$ = lapp($1,$3); }
662 types_and_maybe_ids :
663 type_and_maybe_id { $$ = lsing($1); }
664 | types_and_maybe_ids COMMA type_and_maybe_id { $$ = lapp($1,$3); }
668 tautype { $$ = mkvspec_ty_and_id($1,mknothing()); }
669 | tautype EQUAL qvark { $$ = mkvspec_ty_and_id($1,mkjust($3)); }
672 /**********************************************************************
678 **********************************************************************/
680 /* "DCOLON context => tautype" vs "DCOLON tautype" is a problem,
681 because you can't distinguish between
683 foo :: (Baz a, Baz a)
684 bar :: (Baz a, Baz a) => [a] -> [a] -> [a]
686 with one token of lookahead. The HACK is to have "DCOLON apptype"
687 in the first case, then check that it has the right
688 form C a, or (C1 a, C2 b, ... Cn z) and convert it into a
692 /* --------------------------- */
697 polytype : FORALL tyvars1 DOT
698 apptype DARROW tautype { $$ = mkforall($2, type2context($4), $6); }
699 | FORALL tyvars1 DOT tautype { $$ = mkforall($2, Lnil, $4); }
700 | apptype DARROW tautype { $$ = mkforall(Lnil, type2context($1), $3); }
704 /* --------------------------- */
705 /* tautype is just a monomorphic type.
706 But it may have nested for-alls if we're in a rank-2 type */
708 tautype : apptype RARROW tautype { $$ = mktfun($1,$3); }
709 | apptype { $$ = $1; }
712 tautypes : tautype { $$ = lsing($1); }
713 | tautypes COMMA tautype { $$ = lapp($1,$3); }
716 /* --------------------------- */
717 /* apptype: type application */
719 apptype : apptype atype { $$ = mktapp($1,$2); }
723 /* --------------------------- */
724 /* atype: an atomic or bracketed type: T, x, [ty], tuple ty */
726 atypes : atype { $$ = lsing($1); }
727 | atype atypes { $$ = mklcons($1,$2); }
730 atype : gtycon { $$ = mktname($1); }
731 | tyvar { $$ = mknamedtvar($1); }
733 | OPAREN tautype COMMA
734 tautypes CPAREN { $$ = mkttuple(mklcons($2,$4)); }
736 | OUNBOXPAREN tautype COMMA
737 tautypes CUNBOXPAREN { $$ = mktutuple(mklcons($2,$4)); }
739 | OBRACK tautype CBRACK { $$ = mktllist($2); }
740 | OPAREN polytype CPAREN { $$ = $2; }
743 /* --------------------------- */
745 | OPAREN RARROW CPAREN { $$ = creategid(ARROWGID); }
746 | OBRACK CBRACK { $$ = creategid(NILGID); }
747 | OPAREN CPAREN { $$ = creategid(UNITGID); }
748 | OPAREN commas CPAREN { $$ = creategid($2); }
751 commas : COMMA { $$ = 1; }
752 | commas COMMA { $$ = $1 + 1; }
755 /**********************************************************************
758 * Declaration stuff *
761 **********************************************************************/
763 /* C a b c, where a,b,c are type variables */
764 /* C can be a class or tycon */
765 simple_con_app: gtycon { $$ = mktname($1); }
766 | simple_con_app1 { $$ = $1; }
769 simple_con_app1: gtycon tyvar { $$ = mktapp(mktname($1),mknamedtvar($2)); }
770 | simple_con_app tyvar { $$ = mktapp($1, mknamedtvar($2)); }
773 simple_context : OPAREN simple_context_list CPAREN { $$ = $2; }
774 | simple_con_app1 { $$ = lsing($1); }
777 simple_context_list: simple_con_app1 { $$ = lsing($1); }
778 | simple_context_list COMMA simple_con_app1 { $$ = lapp($1,$3); }
781 constrs : constr { $$ = lsing($1); }
782 | constrs VBAR constr { $$ = lapp($1,$3); }
785 constr : forall constr_context DARROW constr_after_context { $$ = mkconstrex ( $1, $2, $4 ); }
786 | forall constr_after_context { $$ = mkconstrex ( $1, Lnil, $2 ); }
789 forall : { $$ = Lnil }
790 | FORALL tyvars1 DOT { $$ = $2; }
794 : conapptype conargatype { $$ = type2context( mktapp($1,$2) ); }
795 | conargatype { $$ = type2context( $1 ); }
798 constr_after_context :
800 /* We have to parse the constructor application as a *type*, else we get
801 into terrible ambiguity problems. Consider the difference between
803 data T = S Int Int Int `R` Int
805 data T = S Int Int Int
807 It isn't till we get to the operator that we discover that the "S" is
808 part of a type in the first, but part of a constructor application in the
812 /* Con !Int (Tree a) */
813 conapptype { qid tyc; list tys;
814 splittyconapp($1, &tyc, &tys);
815 $$ = mkconstrpre(tyc,tys,hsplineno); }
817 /* (::) (Tree a) Int */
818 | OPAREN qconsym CPAREN conargatypes { $$ = mkconstrpre($2,$4,hsplineno); }
820 /* !Int `Con` Tree a */
821 | conargatype qconop conargatype { $$ = mkconstrinf($1,$2,$3,hsplineno); }
823 /* Con { op1 :: Int } */
824 | qtycon OCURLY fields CCURLY { $$ = mkconstrrec($1,$3,hsplineno); }
825 | OPAREN qconsym CPAREN OCURLY fields CCURLY { $$ = mkconstrrec($2,$5,hsplineno); }
827 /* 1 S/R conflict on OCURLY -> shift */
830 conapptype : gtycon { $$ = mktname($1); }
831 | conapptype conargatype { $$ = mktapp($1, $2); }
834 conargatype : polyatype { $$ = $1; }
835 | BANG polyatype { $$ = mktbang( $2 ); }
838 conargatypes : { $$ = Lnil; }
839 | conargatype conargatypes { $$ = mklcons($1,$2); }
842 fields : field { $$ = lsing($1); }
843 | fields COMMA field { $$ = lapp($1,$3); }
846 field : qvars_list DCOLON polytype { $$ = mkfield($1,$3); }
847 | qvars_list DCOLON BANG polyatype { $$ = mkfield($1,mktbang($4)); }
850 constr1 : gtycon conargatype { $$ = lsing(mkconstrnew($1,$2,hsplineno)); }
854 dtyclses: OPAREN dtycls_list CPAREN { $$ = $2; }
855 | OPAREN CPAREN { $$ = Lnil; }
856 | qtycls { $$ = lsing($1); }
859 dtycls_list: qtycls { $$ = lsing($1); }
860 | dtycls_list COMMA qtycls { $$ = lapp($1,$3); }
863 instdefs : /* empty */ { $$ = mknullbind(); }
864 | instdef { $$ = $1; }
865 | instdefs SEMI instdef
877 /* instdef: same as valdef, except certain user-pragmas may appear */
879 SPECIALISE_UPRAGMA qvark DCOLON types_and_maybe_ids END_UPRAGMA
881 $$ = mkvspec_uprag($2, $4, startlineno);
882 PREVPATT = NULL; FN = NULL; SAMEFN = 0;
885 | INLINE_UPRAGMA qvark END_UPRAGMA
887 $$ = mkinline_uprag($2, startlineno);
888 PREVPATT = NULL; FN = NULL; SAMEFN = 0;
891 | NOINLINE_UPRAGMA qvark END_UPRAGMA
893 $$ = mknoinline_uprag($2, startlineno);
894 PREVPATT = NULL; FN = NULL; SAMEFN = 0;
897 | MAGIC_UNFOLDING_UPRAGMA qvark vark END_UPRAGMA
899 $$ = mkmagicuf_uprag($2, $3, startlineno);
900 PREVPATT = NULL; FN = NULL; SAMEFN = 0;
910 tree fn = function($1);
913 if(ttree(fn) == ident)
915 qid fun_id = gident((struct Sident *) fn);
920 else if (ttree(fn) == infixap)
922 qid fun_id = ginffun((struct Sinfixap *) fn);
929 printf("%u\n",startlineno);
931 fprintf(stderr,"%u\tvaldef\n",startlineno);
938 if ( lhs_is_patt($1) )
940 $$ = mkpbind($4, $3);
945 $$ = mkfbind($4, $3);
951 get_line_no : { $$ = startlineno; }
954 vallhs : patk { $$ = $1; }
955 | patk qvarop pat { $$ = mkinfixap($2,$1,$3); }
956 | funlhs { $$ = $1; }
959 funlhs : qvark apat { $$ = mkap(mkident($1),$2); }
960 | funlhs apat { $$ = mkap($1,$2); }
964 valrhs : valrhs1 maybe_where { $$ = lsing(createpat($1, $2)); }
967 valrhs1 : gdrhs { $$ = mkpguards($1); }
968 | EQUAL exp { $$ = mkpnoguards($2); }
971 gdrhs : gd EQUAL exp { $$ = lsing(mkpgdexp($1,$3)); }
972 | gd EQUAL exp gdrhs { $$ = mklcons(mkpgdexp($1,$3),$4); }
976 WHERE ocurly decls ccurly { $$ = $3; }
977 | WHERE vocurly decls vccurly { $$ = $3; }
978 /* A where containing no decls is OK */
979 | WHERE SEMI { $$ = mknullbind(); }
980 | /* empty */ { $$ = mknullbind(); }
983 gd : VBAR quals { $$ = $2; }
987 /**********************************************************************
993 **********************************************************************/
995 exp : oexp DCOLON polytype { $$ = mkrestr($1,$3); }
1000 Operators must be left-associative at the same precedence for
1001 precedence parsing to work.
1003 /* 8 S/R conflicts on qop -> shift */
1004 oexp : oexp qop oexp %prec MINUS { $$ = mkinfixap($2,$1,$3); }
1009 This comes here because of the funny precedence rules concerning
1012 dexp : MINUS kexp { $$ = mknegate($2); }
1017 We need to factor out a leading let expression so we can set
1018 pat_check=FALSE when parsing (non let) expressions inside stmts and quals
1020 expLno : oexpLno DCOLON polytype { $$ = mkrestr($1,$3); }
1023 oexpLno : oexpLno qop oexp %prec MINUS { $$ = mkinfixap($2,$1,$3); }
1026 dexpLno : MINUS kexp { $$ = mknegate($2); }
1030 expL : oexpL DCOLON polytype { $$ = mkrestr($1,$3); }
1033 oexpL : oexpL qop oexp %prec MINUS { $$ = mkinfixap($2,$1,$3); }
1038 let/if/lambda/case have higher precedence than infix operators.
1045 /* kexpL = a let expression */
1046 kexpL : letdecls IN exp { $$ = mklet($1,$3); }
1049 /* kexpLno = any other expression more tightly binding than operator application */
1051 { hsincindent(); /* push new context for FN = NULL; */
1052 FN = NULL; /* not actually concerned about indenting */
1053 $<ulong>$ = hsplineno; /* remember current line number */
1058 RARROW exp /* lambda abstraction */
1060 $$ = mklambda($3, $6, $<ulong>2);
1064 | IF {$<ulong>$ = hsplineno;}
1065 exp THEN exp ELSE exp { $$ = mkife($3,$5,$7,$<ulong>2); }
1067 /* Case Expression */
1068 | CASE {$<ulong>$ = hsplineno;}
1069 exp OF caserest { $$ = mkcasee($3,$5,$<ulong>2); }
1072 | DO {$<ulong>$ = hsplineno;}
1073 dorest { $$ = mkdoe($3,$<ulong>2); }
1075 /* CCALL/CASM Expression */
1076 | CCALL ccallid cexps { $$ = mkccall($2,install_literal("n"),$3); }
1077 | CCALL ccallid { $$ = mkccall($2,install_literal("n"),Lnil); }
1078 | CCALL_GC ccallid cexps { $$ = mkccall($2,install_literal("p"),$3); }
1079 | CCALL_GC ccallid { $$ = mkccall($2,install_literal("p"),Lnil); }
1080 | CASM CLITLIT cexps { $$ = mkccall($2,install_literal("N"),$3); }
1081 | CASM CLITLIT { $$ = mkccall($2,install_literal("N"),Lnil); }
1082 | CASM_GC CLITLIT cexps { $$ = mkccall($2,install_literal("P"),$3); }
1083 | CASM_GC CLITLIT { $$ = mkccall($2,install_literal("P"),Lnil); }
1085 /* SCC Expression */
1090 "\"%s\":%d: _scc_ (`set [profiling] cost centre') ignored\n",
1091 input_filename, hsplineno);
1093 $$ = mkpar($3); /* Note the mkpar(). If we don't have it, then
1094 (x >> _scc_ y >> z) parses as (x >> (y >> z)),
1095 right associated. But the precedence reorganiser expects
1096 the parser to *left* associate all operators unless there
1097 are explicit parens. The _scc_ acts like an explicit paren,
1098 so if we omit it we'd better add explicit parens instead. */
1106 fexp : fexp aexp { $$ = mkap($1,$2); }
1110 /* simple expressions */
1111 aexp : qvar { $$ = mkident($1); }
1112 | gcon { $$ = mkident($1); }
1113 | lit_constant { $$ = mklit($1); }
1114 | OPAREN exp CPAREN { $$ = mkpar($2); } /* mkpar: stop infix parsing at ()'s */
1115 | qcon OCURLY rbinds CCURLY { $$ = mkrecord($1,$3); } /* 1 S/R conflict on OCURLY -> shift */
1116 | OBRACK list_exps CBRACK { $$ = mkllist($2); }
1117 | OPAREN exp COMMA texps CPAREN { $$ = mktuple(mklcons($2,$4)); }
1118 /* unboxed tuples */
1119 | OUNBOXPAREN exp COMMA texps CUNBOXPAREN
1120 { $$ = mkutuple(mklcons($2,$4)); }
1122 /* only in expressions ... */
1123 | aexp OCURLY rbinds1 CCURLY { $$ = mkrupdate($1,$3); }
1124 | OBRACK exp VBAR quals CBRACK { $$ = mkcomprh($2,$4); }
1125 | OBRACK exp COMMA exp DOTDOT exp CBRACK {$$= mkeenum($2,mkjust($4),mkjust($6)); }
1126 | OBRACK exp COMMA exp DOTDOT CBRACK { $$ = mkeenum($2,mkjust($4),mknothing()); }
1127 | OBRACK exp DOTDOT exp CBRACK { $$ = mkeenum($2,mknothing(),mkjust($4)); }
1128 | OBRACK exp DOTDOT CBRACK { $$ = mkeenum($2,mknothing(),mknothing()); }
1129 | OPAREN oexp qop CPAREN { $$ = mklsection($2,$3); }
1130 | OPAREN qop1 oexp CPAREN { $$ = mkrsection($2,$3); }
1132 /* only in patterns ... */
1133 /* these add 2 S/R conflict with with aexp . OCURLY rbinds CCURLY */
1134 | qvar AT aexp { checkinpat(); $$ = mkas($1,$3); }
1135 | LAZY aexp { checkinpat(); $$ = mklazyp($2); }
1136 | WILDCARD { checkinpat(); $$ = mkwildp(); }
1139 /* ccall arguments */
1140 cexps : cexps aexp { $$ = lapp($1,$2); }
1141 | aexp { $$ = lsing($1); }
1144 caserest: ocurly alts ccurly { $$ = $2; }
1145 | vocurly alts vccurly { $$ = $2; }
1147 dorest : ocurly stmts ccurly { checkdostmts($2); $$ = $2; }
1148 | vocurly stmts vccurly { checkdostmts($2); $$ = $2; }
1151 rbinds : /* empty */ { $$ = Lnil; }
1155 rbinds1 : rbind { $$ = lsing($1); }
1156 | rbinds1 COMMA rbind { $$ = lapp($1,$3); }
1159 rbind : qvar { $$ = mkrbind($1,mknothing()); }
1160 | qvar EQUAL exp { $$ = mkrbind($1,mkjust($3)); }
1163 texps : exp { $$ = lsing($1); }
1164 | exp COMMA texps { $$ = mklcons($1, $3) }
1165 /* right recursion? WDP */
1169 exp { $$ = lsing($1); }
1170 | exp COMMA exp { $$ = mklcons( $1, lsing($3) ); }
1171 | exp COMMA exp COMMA list_rest { $$ = mklcons( $1, mklcons( $3, reverse_list( $5 ))); }
1174 /* Use left recusion for list_rest, because we sometimes get programs with
1175 very long explicit lists. */
1176 list_rest : exp { $$ = lsing($1); }
1177 | list_rest COMMA exp { $$ = mklcons( $3, $1 ); }
1181 exp { $$ = lsing($1); }
1182 | exp COMMA list_exps { $$ = mklcons($1, $3); }
1184 /* right recursion? (WDP)
1186 It has to be this way, though, otherwise you
1187 may do the wrong thing to distinguish between...
1189 [ e1 , e2 .. ] -- an enumeration ...
1190 [ e1 , e2 , e3 ] -- a list
1192 (In fact, if you change the grammar and throw yacc/bison
1193 at it, it *will* do the wrong thing [WDP 94/06])
1196 letdecls: LET { pat_check = TRUE; } ocurly decls ccurly { $$ = $4; }
1197 | LET { pat_check = TRUE; } vocurly decls vccurly { $$ = $4; }
1201 When parsing patterns inside do stmt blocks or quals, we have
1202 to tentatively parse them as expressions, since we don't know at
1203 the time of parsing `p' whether it will be part of "p <- e" (pat)
1204 or "p" (expr). When we eventually can tell the difference, the parse
1205 of `p' is examined to see if it consitutes a syntactically legal pattern
1208 The expr rule used to parse the pattern/expression do contain
1209 pattern-special productions (e.g., _ , a@pat, etc.), which are
1210 illegal in expressions. Since we don't know whether what
1211 we're parsing is an expression rather than a pattern, we turn off
1212 the check and instead do it later.
1214 The rather clumsy way that this check is turned on/off is there
1215 to work around a Bison feature/shortcoming. Turning the flag
1216 on/off just around the relevant nonterminal by decorating it
1217 with simple semantic actions, e.g.,
1219 {pat_check = FALSE; } expLNo { pat_check = TRUE; }
1221 causes Bison to generate a parser where in one state it either
1222 has to reduce/perform a semantic action ( { pat_check = FALSE; })
1223 or reduce an error (the error production used to implement
1224 vccurly.) Bison picks the semantic action, which it ideally shouldn't.
1225 The work around is to lift out the setting of { pat_check = FALSE; }
1226 and then later reset pat_check. Not pretty.
1231 quals : { pat_check = FALSE;} qual { pat_check = TRUE; $$ = lsing($2); }
1232 | quals COMMA { pat_check = FALSE; } qual { pat_check = TRUE; $$ = lapp($1,$4); }
1235 qual : letdecls { $$ = mkseqlet($1); }
1236 | expL { expORpat(LEGIT_EXPR,$1); $$ = $1; }
1237 | expLno { pat_check = TRUE; } leftexp
1239 expORpat(LEGIT_EXPR,$1);
1242 expORpat(LEGIT_PATT,$1);
1248 alts : alt { $$ = $1; }
1249 | alts SEMI alt { $$ = lconc($1,$3); }
1252 alt : pat { PREVPATT = $1; } altrest { $$ = lsing($3); PREVPATT = NULL; }
1253 | /* empty */ { $$ = Lnil; }
1256 altrest : gdpat maybe_where { $$ = createpat(mkpguards($1), $2); }
1257 | RARROW exp maybe_where { $$ = createpat(mkpnoguards($2),$3); }
1260 gdpat : gd RARROW exp { $$ = lsing(mkpgdexp($1,$3)); }
1261 | gd RARROW exp gdpat { $$ = mklcons(mkpgdexp($1,$3),$4); }
1264 stmts : {pat_check = FALSE;} stmt {pat_check=TRUE; $$ = $2; }
1265 | stmts SEMI {pat_check=FALSE;} stmt {pat_check=TRUE; $$ = lconc($1,$4); }
1268 stmt : /* empty */ { $$ = Lnil; }
1269 | letdecls { $$ = lsing(mkseqlet($1)); }
1270 | expL { expORpat(LEGIT_EXPR,$1); $$ = lsing(mkdoexp($1,hsplineno)); }
1271 | expLno {pat_check=TRUE;} leftexp
1273 expORpat(LEGIT_EXPR,$1);
1274 $$ = lsing(mkdoexp($1,endlineno));
1276 expORpat(LEGIT_PATT,$1);
1277 $$ = lsing(mkdobind($1,$3,endlineno));
1283 leftexp : LARROW exp { $$ = $2; }
1284 | /* empty */ { $$ = NULL; }
1287 /**********************************************************************
1293 **********************************************************************/
1295 pat : qvar PLUS INTEGER { $$ = mkplusp($1, mkinteger($3)); }
1299 cpat : cpat qconop bpat { $$ = mkinfixap($2,$1,$3); }
1305 | qcon OCURLY rpats CCURLY { $$ = mkrecord($1,$3); }
1306 | MINUS INTEGER { $$ = mknegate(mklit(mkinteger($2))); }
1307 | MINUS FLOAT { $$ = mknegate(mklit(mkfloatr($2))); }
1310 conpat : gcon { $$ = mkident($1); }
1311 | conpat apat { $$ = mkap($1,$2); }
1314 apat : gcon { $$ = mkident($1); }
1315 | qcon OCURLY rpats CCURLY { $$ = mkrecord($1,$3); }
1319 apatc : qvar { $$ = mkident($1); }
1320 | qvar AT apat { $$ = mkas($1,$3); }
1321 | lit_constant { $$ = mklit($1); }
1322 | WILDCARD { $$ = mkwildp(); }
1323 | OPAREN pat CPAREN { $$ = mkpar($2); }
1324 | OPAREN pat COMMA pats CPAREN { $$ = mktuple(mklcons($2,$4)); }
1325 | OUNBOXPAREN pat COMMA pats CUNBOXPAREN { $$ = mkutuple(mklcons($2,$4)); }
1326 | OBRACK pats CBRACK { $$ = mkllist($2); }
1327 | LAZY apat { $$ = mklazyp($2); }
1331 INTEGER { $$ = mkinteger($1); }
1332 | FLOAT { $$ = mkfloatr($1); }
1333 | CHAR { $$ = mkcharr($1); }
1334 | STRING { $$ = mkstring($1); }
1335 | CHARPRIM { $$ = mkcharprim($1); }
1336 | STRINGPRIM { $$ = mkstringprim($1); }
1337 | INTPRIM { $$ = mkintprim($1); }
1338 | FLOATPRIM { $$ = mkfloatprim($1); }
1339 | DOUBLEPRIM { $$ = mkdoubleprim($1); }
1340 | CLITLIT /* yurble yurble */ { $$ = mkclitlit($1); }
1343 lampats : apat lampats { $$ = mklcons($1,$2); }
1344 | apat { $$ = lsing($1); }
1345 /* right recursion? (WDP) */
1348 pats : pat COMMA pats { $$ = mklcons($1, $3); }
1349 | pat { $$ = lsing($1); }
1350 /* right recursion? (WDP) */
1353 rpats : /* empty */ { $$ = Lnil; }
1357 rpats1 : rpat { $$ = lsing($1); }
1358 | rpats1 COMMA rpat { $$ = lapp($1,$3); }
1361 rpat : qvar { $$ = mkrbind($1,mknothing()); }
1362 | qvar EQUAL pat { $$ = mkrbind($1,mkjust($3)); }
1366 patk : patk qconop bpat { $$ = mkinfixap($2,$1,$3); }
1372 | qconk OCURLY rpats CCURLY { $$ = mkrecord($1,$3); }
1373 | minuskey INTEGER { $$ = mknegate(mklit(mkinteger($2))); }
1374 | minuskey FLOAT { $$ = mknegate(mklit(mkfloatr($2))); }
1377 conpatk : gconk { $$ = mkident($1); }
1378 | conpatk apat { $$ = mkap($1,$2); }
1381 apatck : qvark { $$ = mkident($1); }
1382 | qvark AT apat { $$ = mkas($1,$3); }
1383 | lit_constant { $$ = mklit($1); setstartlineno(); }
1384 | WILDCARD { $$ = mkwildp(); setstartlineno(); }
1385 | oparenkey pat CPAREN { $$ = mkpar($2); }
1386 | oparenkey pat COMMA pats CPAREN { $$ = mktuple(mklcons($2,$4)); }
1387 | ounboxparenkey pat COMMA pats CUNBOXPAREN
1388 { $$ = mkutuple(mklcons($2,$4)); }
1389 | obrackkey pats CBRACK { $$ = mkllist($2); }
1390 | lazykey apat { $$ = mklazyp($2); }
1395 | OBRACK CBRACK { $$ = creategid(NILGID); }
1396 | OPAREN CPAREN { $$ = creategid(UNITGID); }
1397 | OPAREN commas CPAREN { $$ = creategid($2); }
1401 | obrackkey CBRACK { $$ = creategid(NILGID); }
1402 | oparenkey CPAREN { $$ = creategid(UNITGID); }
1403 | oparenkey commas CPAREN { $$ = creategid($2); }
1406 /**********************************************************************
1409 * Keywords which record the line start *
1412 **********************************************************************/
1414 importkey: IMPORT { setstartlineno(); $$ = 0; }
1415 | IMPORT SOURCE_UPRAGMA { setstartlineno(); $$ = 1; }
1418 datakey : DATA { setstartlineno();
1421 printf("%u\n",startlineno);
1423 fprintf(stderr,"%u\tdata\n",startlineno);
1428 typekey : TYPE { setstartlineno();
1431 printf("%u\n",startlineno);
1433 fprintf(stderr,"%u\ttype\n",startlineno);
1438 newtypekey : NEWTYPE { setstartlineno();
1441 printf("%u\n",startlineno);
1443 fprintf(stderr,"%u\tnewtype\n",startlineno);
1448 instkey : INSTANCE { setstartlineno();
1451 printf("%u\n",startlineno);
1454 fprintf(stderr,"%u\tinstance\n",startlineno);
1459 defaultkey: DEFAULT { setstartlineno(); }
1462 foreignkey: FOREIGN { setstartlineno(); }
1465 classkey: CLASS { setstartlineno();
1468 printf("%u\n",startlineno);
1470 fprintf(stderr,"%u\tclass\n",startlineno);
1475 modulekey: MODULE { setstartlineno();
1478 printf("%u\n",startlineno);
1480 fprintf(stderr,"%u\tmodule\n",startlineno);
1485 oparenkey: OPAREN { setstartlineno(); }
1488 ounboxparenkey: OUNBOXPAREN { setstartlineno(); }
1491 obrackkey: OBRACK { setstartlineno(); }
1494 lazykey : LAZY { setstartlineno(); }
1497 minuskey: MINUS { setstartlineno(); }
1501 /**********************************************************************
1504 * Basic qualified/unqualified ids/ops *
1507 **********************************************************************/
1510 | OPAREN qvarsym CPAREN { $$ = $2; }
1513 | OPAREN qconsym CPAREN { $$ = $2; }
1516 | BQUOTE qvarid BQUOTE { $$ = $2; }
1519 | BQUOTE qconid BQUOTE { $$ = $2; }
1525 /* Non "-" op, used in right sections */
1530 /* Non "-" varop, used in right sections */
1532 | varsym_nominus { $$ = mknoqual($1); }
1533 | BQUOTE qvarid BQUOTE { $$ = $2; }
1538 | OPAREN varsym CPAREN { $$ = $2; }
1540 con : tycon /* using tycon removes conflicts */
1541 | OPAREN CONSYM CPAREN { $$ = $2; }
1544 | BQUOTE varid BQUOTE { $$ = $2; }
1547 | BQUOTE CONID BQUOTE { $$ = $2; }
1553 qvark : qvarid { setstartlineno(); $$ = $1; }
1554 | oparenkey qvarsym CPAREN { $$ = $2; }
1556 qconk : qconid { setstartlineno(); $$ = $1; }
1557 | oparenkey qconsym CPAREN { $$ = $2; }
1559 vark : varid { setstartlineno(); $$ = $1; }
1560 | oparenkey varsym CPAREN { $$ = $2; }
1564 | varid { $$ = mknoqual($1); }
1567 | varsym { $$ = mknoqual($1); }
1570 | tycon { $$ = mknoqual($1); } /* using tycon removes conflicts */
1573 | CONSYM { $$ = mknoqual($1); }
1576 | tycon { $$ = mknoqual($1); } /* using tycon removes conflicts */
1579 | tycon { $$ = mknoqual($1); } /* using tycon removes conflicts */
1582 varsym : varsym_nominus
1583 | MINUS { $$ = install_literal("-"); }
1586 /* PLUS, BANG are valid varsyms */
1587 varsym_nominus : VARSYM
1588 | PLUS { $$ = install_literal("+"); }
1589 | BANG { $$ = install_literal("!"); }
1590 | DOT { $$ = install_literal("."); }
1593 /* AS HIDING QUALIFIED are valid varids */
1594 varid : varid_noforall
1595 | FORALL { $$ = install_literal("forall"); }
1600 | AS { $$ = install_literal("as"); }
1601 | HIDING { $$ = install_literal("hiding"); }
1602 | QUALIFIED { $$ = install_literal("qualified"); }
1603 /* The rest of these guys are used by the FFI decls, a ghc (and hugs) extension. */
1604 | EXPORT { $$ = install_literal("export"); }
1605 | UNSAFE { $$ = install_literal("unsafe"); }
1606 | DYNAMIC { $$ = install_literal("dynamic"); }
1607 | LABEL { $$ = install_literal("label"); }
1608 | C_CALL { $$ = install_literal("ccall"); }
1609 | STDCALL { $$ = install_literal("stdcall"); }
1610 | PASCAL { $$ = install_literal("pascal"); }
1622 /* ---------------------------------------------- */
1623 tyvar : varid_noforall { $$ = $1; }
1626 /* tyvars1: At least one tyvar */
1627 tyvars1 : tyvar { $$ = lsing($1); }
1628 | tyvar tyvars1 { $$ = mklcons($1,$2); }
1631 /**********************************************************************
1634 * Stuff to do with layout *
1637 **********************************************************************/
1639 ocurly : layout OCURLY { hsincindent(); }
1641 vocurly : layout { hssetindent(); }
1644 layout : { hsindentoff(); }
1650 FN = NULL; SAMEFN = 0; PREVPATT = NULL;
1655 vccurly : { expect_ccurly = 1; } vccurly1 { expect_ccurly = 0; }
1661 FN = NULL; SAMEFN = 0; PREVPATT = NULL;
1667 FN = NULL; SAMEFN = 0; PREVPATT = NULL;
1674 /**********************************************************************
1676 * Error Processing and Reporting *
1678 * (This stuff is here in case we want to use Yacc macros and such.) *
1680 **********************************************************************/
1687 hsperror("pattern syntax used in expression");
1690 /* The parser calls "hsperror" when it sees a
1691 `report this and die' error. It sets the stage
1692 and calls "yyerror".
1694 There should be no direct calls in the parser to
1695 "yyerror", except for the one from "hsperror". Thus,
1696 the only other calls will be from the error productions
1697 introduced by yacc/bison/whatever.
1699 We need to be able to recognise the from-error-production
1700 case, because we sometimes want to say, "Oh, never mind",
1701 because the layout rule kicks into action and may save
1705 static BOOLEAN error_and_I_mean_it = FALSE;
1711 error_and_I_mean_it = TRUE;
1715 extern char *yytext;
1722 /* We want to be able to distinguish 'error'-raised yyerrors
1723 from yyerrors explicitly coded by the parser hacker.
1725 if ( expect_ccurly && ! error_and_I_mean_it ) {
1729 fprintf(stderr, "%s:%d:%d: %s on input: ",
1730 input_filename, hsplineno, hspcolno + 1, s);
1732 if (yyleng == 1 && *yytext == '\0')
1733 fprintf(stderr, "<EOF>");
1737 format_string(stderr, (unsigned char *) yytext, yyleng);
1740 fputc('\n', stderr);
1742 /* a common problem */
1743 if (strcmp(yytext, "#") == 0)
1744 fprintf(stderr, "\t(Perhaps you forgot a `-cpp' or `-fglasgow-exts' flag?)\n");
1751 format_string(fp, s, len)
1758 case '\0': fputs("\\NUL", fp); break;
1759 case '\007': fputs("\\a", fp); break;
1760 case '\010': fputs("\\b", fp); break;
1761 case '\011': fputs("\\t", fp); break;
1762 case '\012': fputs("\\n", fp); break;
1763 case '\013': fputs("\\v", fp); break;
1764 case '\014': fputs("\\f", fp); break;
1765 case '\015': fputs("\\r", fp); break;
1766 case '\033': fputs("\\ESC", fp); break;
1767 case '\034': fputs("\\FS", fp); break;
1768 case '\035': fputs("\\GS", fp); break;
1769 case '\036': fputs("\\RS", fp); break;
1770 case '\037': fputs("\\US", fp); break;
1771 case '\177': fputs("\\DEL", fp); break;
1776 fprintf(fp, "\\^%c", *s + '@');