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, SAMEFN macros */
55 extern BOOLEAN samefn[];
56 extern short icontexts;
59 extern int hsplineno, hspcolno;
60 extern int modulelineno;
61 extern int startlineno;
64 /* Local helper functions */
65 static void checkinpat PROTO((void));
66 static void punningNowIllegal PROTO((void));
69 /**********************************************************************
72 * Fixity and Precedence Declarations *
75 **********************************************************************/
77 static int Fixity = 0, Precedence = 0;
79 char *ineg PROTO((char *));
81 long source_version = 0;
82 BOOLEAN pat_check=TRUE;
108 /**********************************************************************
111 * These are lexemes. *
114 **********************************************************************/
117 %token VARID CONID QVARID QCONID
118 VARSYM CONSYM QVARSYM QCONSYM
120 %token INTEGER FLOAT CHAR STRING
121 CHARPRIM STRINGPRIM INTPRIM FLOATPRIM
126 /**********************************************************************
132 **********************************************************************/
134 %token OCURLY CCURLY VCCURLY
135 %token COMMA SEMI OBRACK CBRACK
136 %token BQUOTE OPAREN CPAREN
137 %token OUNBOXPAREN CUNBOXPAREN
140 /**********************************************************************
143 * Reserved Operators *
146 **********************************************************************/
148 %token DOTDOT DCOLON EQUAL LAMBDA
149 %token VBAR RARROW LARROW
150 %token AT LAZY DARROW
153 /**********************************************************************
156 * Reserved Identifiers *
159 **********************************************************************/
161 %token CASE CLASS DATA
162 %token DEFAULT DERIVING DO
163 %token ELSE IF IMPORT
164 %token IN INFIX INFIXL
165 %token INFIXR INSTANCE LET
166 %token MODULE NEWTYPE OF
167 %token THEN TYPE WHERE
170 %token CCALL CCALL_GC CASM CASM_GC
173 %token EXPORT UNSAFE STDCALL C_CALL LABEL
174 %token PASCAL FASTCALL FOREIGN DYNAMIC
176 /**********************************************************************
179 * Special symbols/identifiers which need to be recognised *
182 **********************************************************************/
184 %token MINUS BANG PLUS
185 %token AS HIDING QUALIFIED
188 /**********************************************************************
191 * Special Symbols for the Lexer *
194 **********************************************************************/
196 %token INTERFACE_UPRAGMA SPECIALISE_UPRAGMA
197 %token INLINE_UPRAGMA NOINLINE_UPRAGMA MAGIC_UNFOLDING_UPRAGMA
199 %token SOURCE_UPRAGMA
201 /**********************************************************************
204 * Precedences of the various tokens *
207 **********************************************************************/
212 SCC CASM CCALL CASM_GC CCALL_GC
214 %left VARSYM CONSYM QVARSYM QCONSYM
215 MINUS BQUOTE BANG DARROW PLUS
221 %left OCURLY OBRACK OPAREN
227 /**********************************************************************
230 * Type Declarations *
233 **********************************************************************/
236 %type <ulist> caserest alts quals
238 rbinds rbinds1 rpats rpats1 list_exps list_rest
240 constrs fields conargatypes
243 pats simple_context simple_context_list
246 impdecls maybeimpdecls impdecl
249 lampats cexps gd texps
250 tyvars1 constr_context forall
254 %type <ugrhsb> valrhs altrhs
256 %type <umaybe> maybeexports impspec deriving
257 ext_name opt_sig opt_asig
259 %type <uliteral> lit_constant
261 %type <utree> exp oexp dexp kexp fexp aexp rbind
262 expL oexpL kexpL expLno oexpLno dexpLno kexpLno
263 funlhs funlhs1 funlhs2 funlhs3 qual leftexp
264 pat dpat cpat bpat apat apatc conpat rpat
265 patk bpatk apatck conpatk
268 %type <uid> MINUS PLUS DARROW AS LAZY
269 VARID CONID VARSYM CONSYM
270 var con varop conop op
271 vark varid varsym varsym_nominus
272 tycon modid ccallid tyvar
275 %type <uqid> QVARID QCONID QVARSYM QCONSYM
276 qvarid qconid qvarsym qconsym
277 qvar qcon qvarop qconop qop
278 qvark qconk qtycon qtycls
279 gcon gconk gtycon itycon qop1 qvarop1
282 %type <ubinding> topdecl topdecls letdecls
283 typed datad newtd classd instd defaultd foreignd
284 decl decls non_empty_decls fixdecl fix_op fix_ops valdef
285 maybe_where where_body type_and_maybe_id
287 %type <uttype> polytype
288 conargatype conapptype
292 simple_con_app simple_con_app1 inst_type
294 %type <uconstr> constr constr_after_context field constr1
296 %type <ustring> FLOAT INTEGER INTPRIM
297 FLOATPRIM DOUBLEPRIM CLITLIT
299 %type <uhstring> STRING STRINGPRIM CHAR CHARPRIM
301 %type <uentid> export import
303 %type <ulong> commas importkey get_line_no
306 /**********************************************************************
309 * Start Symbol for the Parser *
312 **********************************************************************/
317 module : modulekey modid maybeexports
319 modulelineno = startlineno;
320 the_module_name = $2;
326 the_module_name = install_literal("Main");
327 module_exports = mknothing();
332 body : ocurly { setstartlineno(); } main_body ccurly
333 | vocurly main_body vccurly
336 main_body : interface_pragma maybeimpdecls topdecls
338 root = mkhmodule(the_module_name, $2, module_exports,
339 $3, source_version,modulelineno);
341 | interface_pragma impdecls
343 root = mkhmodule(the_module_name, $2, module_exports,
344 mknullbind(), source_version, modulelineno);
347 interface_pragma : /* empty */
348 | INTERFACE_UPRAGMA INTEGER END_UPRAGMA SEMI
350 source_version = atoi($2);
354 maybeexports : /* empty */ { $$ = mknothing(); }
355 | OPAREN CPAREN { $$ = mkjust(Lnil); }
356 | OPAREN export_list CPAREN { $$ = mkjust($2); }
357 | OPAREN export_list COMMA CPAREN { $$ = mkjust($2); }
361 export { $$ = lsing($1); }
362 | export_list COMMA export { $$ = lapp($1, $3); }
365 export : qvar { $$ = mkentid($1); }
366 | gtycon { $$ = mkenttype($1); }
367 | gtycon OPAREN DOTDOT CPAREN { $$ = mkenttypeall($1); }
368 | gtycon OPAREN CPAREN { $$ = mkenttypenamed($1,Lnil); }
369 | gtycon OPAREN enames CPAREN { $$ = mkenttypenamed($1,$3); }
370 | MODULE modid { $$ = mkentmod($2); }
373 enames : ename { $$ = lsing($1); }
374 | enames COMMA ename { $$ = lapp($1,$3); }
381 maybeimpdecls : /* empty */ { $$ = Lnil; }
382 | impdecls SEMI { $$ = $1; }
385 impdecls: impdecl { $$ = $1; }
386 | impdecls SEMI impdecl { $$ = lconc($1,$3); }
390 impdecl : importkey modid impspec
391 { $$ = lsing(mkimport($2,0,mknothing(),$3,$1,startlineno)); }
392 | importkey QUALIFIED modid impspec
393 { $$ = lsing(mkimport($3,1,mknothing(),$4,$1,startlineno)); }
394 | importkey QUALIFIED modid AS modid impspec
395 { $$ = lsing(mkimport($3,1,mkjust($5),$6,$1,startlineno)); }
396 | importkey modid AS modid impspec
397 { $$ = lsing(mkimport($3,1,mkjust($4),$5,$1,startlineno)); }
400 impspec : /* empty */ { $$ = mknothing(); }
401 | OPAREN CPAREN { $$ = mkjust(mkleft(Lnil)); }
402 | OPAREN import_list CPAREN { $$ = mkjust(mkleft($2)); }
403 | OPAREN import_list COMMA CPAREN { $$ = mkjust(mkleft($2)); }
404 | HIDING OPAREN CPAREN { $$ = mkjust(mkright(Lnil)); }
405 | HIDING OPAREN import_list CPAREN { $$ = mkjust(mkright($3)); }
406 | HIDING OPAREN import_list COMMA CPAREN { $$ = mkjust(mkright($3)); }
410 import { $$ = lsing($1); }
411 | import_list COMMA import { $$ = lapp($1, $3); }
414 import : var { $$ = mkentid(mknoqual($1)); }
415 | itycon { $$ = mkenttype($1); }
416 | itycon OPAREN DOTDOT CPAREN { $$ = mkenttypeall($1); }
417 | itycon OPAREN CPAREN { $$ = mkenttypenamed($1,Lnil);}
418 | itycon OPAREN inames CPAREN { $$ = mkenttypenamed($1,$3); }
421 itycon : tycon { $$ = mknoqual($1); }
422 | OBRACK CBRACK { $$ = creategid(NILGID); }
423 | OPAREN CPAREN { $$ = creategid(UNITGID); }
424 | OPAREN commas CPAREN { $$ = creategid($2); }
427 inames : iname { $$ = lsing($1); }
428 | inames COMMA iname { $$ = lapp($1,$3); }
430 iname : var { $$ = mknoqual($1); }
431 | con { $$ = mknoqual($1); }
434 /**********************************************************************
437 * Fixes and Decls etc *
440 **********************************************************************/
442 topdecls : /* empty */ { $$ = mknullbind(); }
444 | topdecls SEMI { $$ = $1; }
445 | topdecls SEMI topdecl
464 topdecl : typed { $$ = $1; FN = NULL; SAMEFN = 0; }
465 | datad { $$ = $1; FN = NULL; SAMEFN = 0; }
466 | newtd { $$ = $1; FN = NULL; SAMEFN = 0; }
467 | classd { $$ = $1; FN = NULL; SAMEFN = 0; }
468 | instd { $$ = $1; FN = NULL; SAMEFN = 0; }
469 | defaultd { $$ = $1; FN = NULL; SAMEFN = 0; }
470 | foreignd { $$ = $1; FN = NULL; SAMEFN = 0; }
474 typed : typekey simple_con_app EQUAL tautype { $$ = mknbind($2,$4,startlineno); }
478 datad : datakey simple_con_app EQUAL constrs deriving
479 { $$ = mktbind(Lnil,$2,$4,$5,startlineno); }
480 | datakey simple_context DARROW simple_con_app EQUAL constrs deriving
481 { $$ = mktbind($2,$4,$6,$7,startlineno); }
484 newtd : newtypekey simple_con_app EQUAL constr1 deriving
485 { $$ = mkntbind(Lnil,$2,lsing($4),$5,startlineno); }
486 | newtypekey simple_context DARROW simple_con_app EQUAL constr1 deriving
487 { $$ = mkntbind($2,$4,lsing($6),$7,startlineno); }
490 deriving: /* empty */ { $$ = mknothing(); }
491 | DERIVING dtyclses { $$ = mkjust($2); }
494 classd : classkey apptype DARROW simple_con_app1 maybe_where
495 /* Context can now be more than simple_context */
496 { $$ = mkcbind(type2context($2),$4,$5,startlineno); }
497 | classkey apptype maybe_where
498 /* We have to say apptype rather than simple_con_app1, else
499 we get reduce/reduce errs */
500 { check_class_decl_head($2);
501 $$ = mkcbind(Lnil,$2,$3,startlineno); }
504 instd : instkey inst_type maybe_where { $$ = mkibind($2,$3,startlineno); }
507 /* Compare polytype */
508 /* [July 98: first production was tautype DARROW tautype, but I can't see why.] */
509 inst_type : apptype DARROW apptype { is_context_format( $3, 0 ); /* Check the instance head */
510 $$ = mkimp_forall(type2context($1),$3); }
511 | apptype { is_context_format( $1, 0 ); /* Check the instance head */
516 defaultd: defaultkey OPAREN tautypes CPAREN { $$ = mkdbind($3,startlineno); }
517 | defaultkey OPAREN CPAREN { $$ = mkdbind(Lnil,startlineno); }
520 /* FFI primitive declarations - GHC/Hugs specific */
521 foreignd: foreignkey IMPORT callconv ext_name unsafe_flag qvarid DCOLON tautype
522 { $$ = mkfobind($6,$8,$4,$5,$3,FOREIGN_IMPORT,startlineno); }
523 | foreignkey EXPORT callconv ext_name qvarid DCOLON tautype
524 { $$ = mkfobind($5,$7,$4,0,$3,FOREIGN_EXPORT,startlineno); }
525 | foreignkey LABEL ext_name qvarid DCOLON tautype
526 { $$ = mkfobind($4,$6,$3,0,-1,FOREIGN_LABEL,startlineno); }
529 callconv: STDCALL { $$ = CALLCONV_STDCALL; }
530 | C_CALL { $$ = CALLCONV_CCALL; }
531 | PASCAL { $$ = CALLCONV_PASCAL; }
532 | FASTCALL { $$ = CALLCONV_FASTCALL; }
533 /* If you leave out the specification of a calling convention, you'll (probably) get C's. */
534 | /*empty*/ { $$ = CALLCONV_NONE; }
537 ext_name: STRING { $$ = mkjust(lsing($1)); }
538 | STRING STRING { $$ = mkjust(mklcons ($1,lsing($2))); }
539 | DYNAMIC { $$ = mknothing(); }
541 unsafe_flag: UNSAFE { $$ = 1; }
542 | /*empty*/ { $$ = 0; }
545 decls : /* empty */ { $$ = mknullbind(); }
547 | decls SEMI { $$ = $1; }
560 non_empty_decls : decl
561 | non_empty_decls SEMI { $$ = $1; }
562 | non_empty_decls SEMI decl
575 Note: if there is an iclasop_pragma here, then we must be
576 doing a class-op in an interface -- unless the user is up
577 to real mischief (ugly, but likely to work).
582 | qvarsk DCOLON polytype
583 { $$ = mksbind($1,$3,startlineno);
584 FN = NULL; SAMEFN = 0;
587 | qvark DCOLON polytype
588 { $$ = mksbind(lsing($1),$3,startlineno);
589 FN = NULL; SAMEFN = 0;
592 /* User-specified pragmas come in as "signatures"...
593 They are similar in that they can appear anywhere in the module,
594 and have to be "joined up" with their related entity.
596 Have left out the case specialising to an overloaded type.
597 Let's get real, OK? (WDP)
599 | SPECIALISE_UPRAGMA qvark DCOLON types_and_maybe_ids END_UPRAGMA
601 $$ = mkvspec_uprag($2, $4, startlineno);
602 FN = NULL; SAMEFN = 0;
605 | SPECIALISE_UPRAGMA INSTANCE gtycon atype END_UPRAGMA
607 $$ = mkispec_uprag($3, $4, startlineno);
608 FN = NULL; SAMEFN = 0;
611 | SPECIALISE_UPRAGMA DATA gtycon atypes END_UPRAGMA
613 $$ = mkdspec_uprag($3, $4, startlineno);
614 FN = NULL; SAMEFN = 0;
617 | INLINE_UPRAGMA qvark END_UPRAGMA
619 $$ = mkinline_uprag($2, startlineno);
620 FN = NULL; SAMEFN = 0;
623 | NOINLINE_UPRAGMA qvark END_UPRAGMA
625 $$ = mknoinline_uprag($2, startlineno);
626 FN = NULL; SAMEFN = 0;
629 | MAGIC_UNFOLDING_UPRAGMA qvark vark END_UPRAGMA
631 $$ = mkmagicuf_uprag($2, $3, startlineno);
632 FN = NULL; SAMEFN = 0;
635 /* end of user-specified pragmas */
640 fixdecl : INFIXL INTEGER { Precedence = checkfixity($2); Fixity = INFIXL; }
642 | INFIXR INTEGER { Precedence = checkfixity($2); Fixity = INFIXR; }
644 | INFIX INTEGER { Precedence = checkfixity($2); Fixity = INFIX; }
646 | INFIXL { Fixity = INFIXL; Precedence = 9; }
648 | INFIXR { Fixity = INFIXR; Precedence = 9; }
650 | INFIX { Fixity = INFIX; Precedence = 9; }
654 /* Grotesque global-variable hack to
655 make a separate fixity decl for each op */
657 | fix_ops COMMA fix_op { $$ = mkabind($1,$3); }
660 fix_op : op { $$ = mkfixd(mknoqual($1),infixint(Fixity),Precedence,startlineno); }
663 qvarsk : qvark COMMA qvars_list { $$ = mklcons($1,$3); }
666 qvars_list: qvar { $$ = lsing($1); }
667 | qvars_list COMMA qvar { $$ = lapp($1,$3); }
670 types_and_maybe_ids :
671 type_and_maybe_id { $$ = lsing($1); }
672 | types_and_maybe_ids COMMA type_and_maybe_id { $$ = lapp($1,$3); }
676 tautype { $$ = mkvspec_ty_and_id($1,mknothing()); }
677 | tautype EQUAL qvark { $$ = mkvspec_ty_and_id($1,mkjust($3)); }
680 /**********************************************************************
686 **********************************************************************/
688 /* "DCOLON context => tautype" vs "DCOLON tautype" is a problem,
689 because you can't distinguish between
691 foo :: (Baz a, Baz a)
692 bar :: (Baz a, Baz a) => [a] -> [a] -> [a]
694 with one token of lookahead. The HACK is to have "DCOLON apptype"
695 in the first case, then check that it has the right
696 form C a, or (C1 a, C2 b, ... Cn z) and convert it into a
700 /* --------------------------- */
705 polytype : FORALL tyvars1 DOT
706 apptype DARROW tautype { $$ = mkforall($2, type2context($4), $6); }
707 | FORALL tyvars1 DOT tautype { $$ = mkforall($2, Lnil, $4); }
708 | apptype DARROW tautype { $$ = mkimp_forall( type2context($1), $3); }
712 /* --------------------------- */
713 /* tautype is just a monomorphic type.
714 But it may have nested for-alls if we're in a rank-2 type */
716 tautype : apptype RARROW tautype { $$ = mktfun($1,$3); }
717 | apptype { $$ = $1; }
720 tautypes : tautype { $$ = lsing($1); }
721 | tautypes COMMA tautype { $$ = lapp($1,$3); }
724 /* --------------------------- */
725 /* apptype: type application */
727 apptype : apptype atype { $$ = mktapp($1,$2); }
731 /* --------------------------- */
732 /* atype: an atomic or bracketed type: T, x, [ty], tuple ty */
734 atypes : atype { $$ = lsing($1); }
735 | atype atypes { $$ = mklcons($1,$2); }
738 atype : gtycon { $$ = mktname($1); }
739 | tyvar { $$ = mknamedtvar($1); }
741 | OPAREN tautype COMMA
742 tautypes CPAREN { $$ = mkttuple(mklcons($2,$4)); }
744 | OUNBOXPAREN tautype COMMA
745 tautypes CUNBOXPAREN { $$ = mktutuple(mklcons($2,$4)); }
747 | OBRACK tautype CBRACK { $$ = mktllist($2); }
748 | OPAREN polytype CPAREN { $$ = $2; }
751 /* --------------------------- */
753 | OPAREN RARROW CPAREN { $$ = creategid(ARROWGID); }
754 | OBRACK CBRACK { $$ = creategid(NILGID); }
755 | OPAREN CPAREN { $$ = creategid(UNITGID); }
756 | OPAREN commas CPAREN { $$ = creategid($2); }
759 commas : COMMA { $$ = 1; }
760 | commas COMMA { $$ = $1 + 1; }
763 /**********************************************************************
766 * Declaration stuff *
769 **********************************************************************/
771 /* C a b c, where a,b,c are type variables */
772 /* C can be a class or tycon */
774 /* simple_con_app can have no args; simple_con_app1 must have at least one */
775 simple_con_app: gtycon { $$ = mktname($1); }
776 | simple_con_app1 { $$ = $1; }
779 simple_con_app1: gtycon tyvar { $$ = mktapp(mktname($1),mknamedtvar($2)); }
780 | simple_con_app1 tyvar { $$ = mktapp($1, mknamedtvar($2)); }
783 simple_context : OPAREN simple_context_list CPAREN { $$ = $2; }
784 | OPAREN CPAREN { $$ = Lnil; }
785 | simple_con_app1 { $$ = lsing($1); }
788 simple_context_list : simple_con_app1 { $$ = lsing($1); }
789 | simple_context_list COMMA simple_con_app1 { $$ = lapp($1,$3); }
792 constrs : constr { $$ = lsing($1); }
793 | constrs VBAR constr { $$ = lapp($1,$3); }
796 constr : forall constr_context DARROW constr_after_context { $$ = mkconstrex ( $1, $2, $4 ); }
797 | forall constr_after_context { $$ = mkconstrex ( $1, Lnil, $2 ); }
800 forall : { $$ = Lnil }
801 | FORALL tyvars1 DOT { $$ = $2; }
805 : conapptype conargatype { $$ = type2context( mktapp($1,$2) ); }
806 | conargatype { $$ = type2context( $1 ); }
809 constr_after_context :
811 /* We have to parse the constructor application as a *type*, else we get
812 into terrible ambiguity problems. Consider the difference between
814 data T = S Int Int Int `R` Int
816 data T = S Int Int Int
818 It isn't till we get to the operator that we discover that the "S" is
819 part of a type in the first, but part of a constructor application in the
823 /* Con !Int (Tree a) */
824 conapptype { qid tyc; list tys;
825 splittyconapp($1, &tyc, &tys);
826 $$ = mkconstrpre(tyc,tys,hsplineno); }
828 /* (::) (Tree a) Int */
829 | OPAREN qconsym CPAREN conargatypes { $$ = mkconstrpre($2,$4,hsplineno); }
831 /* !Int `Con` Tree a */
832 | conargatype qconop conargatype { $$ = mkconstrinf($1,$2,$3,hsplineno); }
834 /* Con { op1 :: Int } */
835 | qtycon OCURLY CCURLY { $$ = mkconstrrec($1,Lnil,hsplineno); }
836 | qtycon OCURLY fields CCURLY { $$ = mkconstrrec($1,$3,hsplineno); }
837 | OPAREN qconsym CPAREN OCURLY fields CCURLY { $$ = mkconstrrec($2,$5,hsplineno); }
839 /* 1 S/R conflict on OCURLY -> shift */
842 conapptype : gtycon { $$ = mktname($1); }
843 | conapptype conargatype { $$ = mktapp($1, $2); }
846 conargatype : polyatype { $$ = $1; }
847 | BANG polyatype { $$ = mktbang( $2 ); }
850 conargatypes : { $$ = Lnil; }
851 | conargatype conargatypes { $$ = mklcons($1,$2); }
854 fields : field { $$ = lsing($1); }
855 | fields COMMA field { $$ = lapp($1,$3); }
858 field : qvars_list DCOLON polytype { $$ = mkfield($1,$3); }
859 | qvars_list DCOLON BANG polyatype { $$ = mkfield($1,mktbang($4)); }
862 constr1 : gtycon conargatype { $$ = mkconstrnew($1,$2,mknothing(),hsplineno); }
863 | gtycon OCURLY qvar DCOLON polytype CCURLY { $$ = mkconstrnew($1,$5,mkjust($3),hsplineno); }
867 dtyclses: OPAREN dtycls_list CPAREN { $$ = $2; }
868 | OPAREN CPAREN { $$ = Lnil; }
869 | qtycls { $$ = lsing($1); }
872 dtycls_list: qtycls { $$ = lsing($1); }
873 | dtycls_list COMMA qtycls { $$ = lapp($1,$3); }
876 valdef : funlhs opt_sig { checksamefn($1); }
877 get_line_no valrhs { $$ = mkfbind( lsing(mkpmatch( lsing($1), $2, $5 )), $4); }
879 /* Special case for f :: type = e
880 We treat it as a special kind of pattern binding */
881 | qvark DCOLON tautype
882 get_line_no valrhs { $$ = mkpbind( mkrestr( mkident($1), $3 ), $5, $4 );
883 FN = NULL; SAMEFN = 0; }
886 get_line_no valrhs { $$ = mkpbind($1, $3, $2);
887 FN = NULL; SAMEFN = 0; }
889 get_line_no : { $$ = hsplineno; /* startlineno; */ }
891 /* This grammar still isn't quite right
894 you should get a function binding, but actually the (x+3) will
895 parse as a pattern, and you'll get a parse error. */
897 funlhs : patk qvarop cpat { $$ = mkinfixap($2,$1,$3); }
898 | funlhs1 apat { $$ = mkap( $1, $2 ); }
900 funlhs1 : oparenkey funlhs2 CPAREN { $$ = mkpar($2); }
901 | funlhs1 apat { $$ = mkap( $1, $2 ); }
902 | qvark { $$ = mkident($1); }
905 funlhs2 : cpat qvarop cpat { $$ = mkinfixap($2,$1,$3); }
906 | funlhs3 apat { $$ = mkap( $1, $2 ); }
908 funlhs3 : OPAREN funlhs2 CPAREN { $$ = mkpar($2); }
909 | funlhs3 apat { $$ = mkap( $1, $2 ); }
910 | qvar { $$ = mkident($1); }
913 opt_sig : { $$ = mknothing(); }
914 | DCOLON tautype { $$ = mkjust($2); }
917 /* opt_asig is the same, but with a parenthesised type */
918 opt_asig : { $$ = mknothing(); }
919 | DCOLON atype { $$ = mkjust($2); }
922 valrhs : EQUAL get_line_no exp maybe_where { $$ = mkpnoguards($2, $3, $4); }
923 | gdrhs maybe_where { $$ = mkpguards($1, $2); }
926 gdrhs : gd EQUAL get_line_no exp { $$ = lsing(mkpgdexp($1,$3,$4)); }
927 | gd EQUAL get_line_no exp gdrhs { $$ = mklcons(mkpgdexp($1,$3,$4),$5); }
930 maybe_where: /* empty */ { $$ = mknullbind(); }
931 | WHERE where_body { $$ = $2; }
932 | WHERE { $$ = mknullbind(); }
935 where_body : ocurly decls ccurly { $$ = $2; }
936 | vocurly non_empty_decls vccurly { $$ = $2; }
939 gd : VBAR quals { $$ = $2; }
943 /**********************************************************************
949 **********************************************************************/
951 exp : oexp DCOLON polytype { $$ = mkrestr($1,$3); }
956 Operators must be left-associative at the same precedence for
957 precedence parsing to work.
959 /* 10 S/R conflicts on qop -> shift */
960 oexp : oexp qop dexp %prec MINUS { $$ = mkinfixap($2,$1,$3); }
965 This comes here because of the funny precedence rules concerning
968 dexp : MINUS kexp { $$ = mknegate($2); }
973 We need to factor out a leading let expression so we can set
974 pat_check=FALSE when parsing (non let) expressions inside stmts and quals
976 expLno : oexpLno DCOLON polytype { $$ = mkrestr($1,$3); }
979 oexpLno : oexpLno qop oexp %prec MINUS { $$ = mkinfixap($2,$1,$3); }
982 dexpLno : MINUS kexp { $$ = mknegate($2); }
986 expL : oexpL DCOLON polytype { $$ = mkrestr($1,$3); }
989 oexpL : oexpL qop oexp %prec MINUS { $$ = mkinfixap($2,$1,$3); }
994 let/if/lambda/case have higher precedence than infix operators.
1001 /* kexpL = a let expression */
1002 kexpL : letdecls IN exp { $$ = mklet($1,$3); }
1005 /* kexpLno = any other expression more tightly binding than operator application */
1007 { hsincindent(); /* push new context for FN = NULL; */
1008 FN = NULL; /* not actually concerned about indenting */
1013 RARROW get_line_no exp /* lambda abstraction */
1014 { $$ = mklambda( mkpmatch( $3, $4, mkpnoguards( $7, $8, mknullbind() ) ) ); }
1017 | IF {$<ulong>$ = hsplineno;}
1018 exp THEN exp ELSE exp { $$ = mkife($3,$5,$7,$<ulong>2); }
1020 /* Case Expression */
1021 | CASE {$<ulong>$ = hsplineno;}
1022 exp OF caserest { $$ = mkcasee($3,$5,$<ulong>2); }
1025 | DO {$<ulong>$ = hsplineno;}
1026 dorest { $$ = mkdoe($3,$<ulong>2); }
1028 /* CCALL/CASM Expression */
1029 | CCALL ccallid cexps { $$ = mkccall($2,install_literal("n"),$3); }
1030 | CCALL ccallid { $$ = mkccall($2,install_literal("n"),Lnil); }
1031 | CCALL_GC ccallid cexps { $$ = mkccall($2,install_literal("p"),$3); }
1032 | CCALL_GC ccallid { $$ = mkccall($2,install_literal("p"),Lnil); }
1033 | CASM CLITLIT cexps { $$ = mkccall($2,install_literal("N"),$3); }
1034 | CASM CLITLIT { $$ = mkccall($2,install_literal("N"),Lnil); }
1035 | CASM_GC CLITLIT cexps { $$ = mkccall($2,install_literal("P"),$3); }
1036 | CASM_GC CLITLIT { $$ = mkccall($2,install_literal("P"),Lnil); }
1038 /* SCC Expression */
1043 "\"%s\":%d: _scc_ (`set [profiling] cost centre') ignored\n",
1044 input_filename, hsplineno);
1046 $$ = mkpar($3); /* Note the mkpar(). If we don't have it, then
1047 (x >> _scc_ y >> z) parses as (x >> (y >> z)),
1048 right associated. But the precedence reorganiser expects
1049 the parser to *left* associate all operators unless there
1050 are explicit parens. The _scc_ acts like an explicit paren,
1051 so if we omit it we'd better add explicit parens instead. */
1059 fexp : fexp aexp { $$ = mkap($1,$2); }
1063 /* simple expressions */
1064 aexp : qvar { $$ = mkident($1); }
1065 | gcon { $$ = mkident($1); }
1066 | lit_constant { $$ = mklit($1); }
1067 | OPAREN exp CPAREN { $$ = mkpar($2); } /* mkpar: stop infix parsing at ()'s */
1068 | qcon OCURLY rbinds CCURLY { $$ = mkrecord($1,$3); } /* 1 S/R conflict on OCURLY -> shift */
1069 | OBRACK list_exps CBRACK { $$ = mkllist($2); }
1070 | OPAREN exp COMMA texps CPAREN { $$ = mktuple(mklcons($2,$4)); }
1071 /* unboxed tuples */
1072 | OUNBOXPAREN texps CUNBOXPAREN { $$ = mkutuple($2); }
1074 /* only in expressions ... */
1075 | aexp OCURLY rbinds1 CCURLY { $$ = mkrupdate($1,$3); }
1076 | OBRACK exp VBAR quals CBRACK { $$ = mkcomprh($2,$4); }
1077 | OBRACK exp COMMA exp DOTDOT exp CBRACK {$$= mkeenum($2,mkjust($4),mkjust($6)); }
1078 | OBRACK exp COMMA exp DOTDOT CBRACK { $$ = mkeenum($2,mkjust($4),mknothing()); }
1079 | OBRACK exp DOTDOT exp CBRACK { $$ = mkeenum($2,mknothing(),mkjust($4)); }
1080 | OBRACK exp DOTDOT CBRACK { $$ = mkeenum($2,mknothing(),mknothing()); }
1081 | OPAREN oexp qop CPAREN { $$ = mklsection($2,$3); }
1082 | OPAREN qop1 oexp CPAREN { $$ = mkrsection($2,$3); }
1084 /* only in patterns ... */
1085 /* these add 2 S/R conflict with with aexp . OCURLY rbinds CCURLY */
1086 | qvar AT aexp { checkinpat(); $$ = mkas($1,$3); }
1087 | LAZY aexp { checkinpat(); $$ = mklazyp($2); }
1090 /* ccall arguments */
1091 cexps : cexps aexp { $$ = lapp($1,$2); }
1092 | aexp { $$ = lsing($1); }
1095 caserest: ocurly alts ccurly { $$ = $2; }
1096 | vocurly alts vccurly { $$ = $2; }
1098 dorest : ocurly stmts ccurly { checkdostmts($2); $$ = $2; }
1099 | vocurly stmts vccurly { checkdostmts($2); $$ = $2; }
1102 rbinds : /* empty */ { $$ = Lnil; }
1106 rbinds1 : rbind { $$ = lsing($1); }
1107 | rbinds1 COMMA rbind { $$ = lapp($1,$3); }
1110 rbind : qvar { punningNowIllegal(); }
1111 | qvar EQUAL exp { $$ = mkrbind($1,mkjust($3)); }
1114 texps : exp { $$ = lsing($1); }
1115 | exp COMMA texps { $$ = mklcons($1, $3) }
1116 /* right recursion? WDP */
1120 exp { $$ = lsing($1); }
1121 | exp COMMA exp { $$ = mklcons( $1, lsing($3) ); }
1122 | exp COMMA exp COMMA list_rest { $$ = mklcons( $1, mklcons( $3, reverse_list( $5 ))); }
1125 /* Use left recusion for list_rest, because we sometimes get programs with
1126 very long explicit lists. */
1127 list_rest : exp { $$ = lsing($1); }
1128 | list_rest COMMA exp { $$ = mklcons( $3, $1 ); }
1132 exp { $$ = lsing($1); }
1133 | exp COMMA list_exps { $$ = mklcons($1, $3); }
1135 /* right recursion? (WDP)
1137 It has to be this way, though, otherwise you
1138 may do the wrong thing to distinguish between...
1140 [ e1 , e2 .. ] -- an enumeration ...
1141 [ e1 , e2 , e3 ] -- a list
1143 (In fact, if you change the grammar and throw yacc/bison
1144 at it, it *will* do the wrong thing [WDP 94/06])
1147 letdecls: LET { pat_check = TRUE; } ocurly decls ccurly { $$ = $4; }
1148 | LET { pat_check = TRUE; } vocurly decls vccurly { $$ = $4; }
1152 When parsing patterns inside do stmt blocks or quals, we have
1153 to tentatively parse them as expressions, since we don't know at
1154 the time of parsing `p' whether it will be part of "p <- e" (pat)
1155 or "p" (expr). When we eventually can tell the difference, the parse
1156 of `p' is examined to see if it consitutes a syntactically legal pattern
1159 The expr rule used to parse the pattern/expression do contain
1160 pattern-special productions (e.g., _ , a@pat, etc.), which are
1161 illegal in expressions. Since we don't know whether what
1162 we're parsing is an expression rather than a pattern, we turn off
1163 the check and instead do it later.
1165 The rather clumsy way that this check is turned on/off is there
1166 to work around a Bison feature/shortcoming. Turning the flag
1167 on/off just around the relevant nonterminal by decorating it
1168 with simple semantic actions, e.g.,
1170 {pat_check = FALSE; } expLNo { pat_check = TRUE; }
1172 causes Bison to generate a parser where in one state it either
1173 has to reduce/perform a semantic action ( { pat_check = FALSE; })
1174 or reduce an error (the error production used to implement
1175 vccurly.) Bison picks the semantic action, which it ideally shouldn't.
1176 The work around is to lift out the setting of { pat_check = FALSE; }
1177 and then later reset pat_check. Not pretty.
1182 quals : { pat_check = FALSE;} qual { pat_check = TRUE; $$ = lsing($2); }
1183 | quals COMMA { pat_check = FALSE; } qual { pat_check = TRUE; $$ = lapp($1,$4); }
1186 qual : letdecls { $$ = mkseqlet($1); }
1187 | expL { expORpat(LEGIT_EXPR,$1); $$ = $1; }
1188 | expLno { pat_check = TRUE; } leftexp
1190 expORpat(LEGIT_EXPR,$1);
1193 expORpat(LEGIT_PATT,$1);
1199 alts : /* empty */ { $$ = Lnil; }
1200 | alt { $$ = lsing($1); }
1201 | alt SEMI alts { $$ = mklcons($1,$3); }
1202 | SEMI alts { $$ = $2; }
1205 alt : dpat opt_sig altrhs { $$ = mkpmatch( lsing($1), $2, $3 ); }
1208 altrhs : RARROW get_line_no exp maybe_where { $$ = mkpnoguards($2, $3, $4); }
1209 | gdpat maybe_where { $$ = mkpguards($1, $2); }
1212 gdpat : gd RARROW get_line_no exp { $$ = lsing(mkpgdexp($1,$3,$4)); }
1213 | gd RARROW get_line_no exp gdpat { $$ = mklcons(mkpgdexp($1,$3,$4),$5); }
1216 stmts : {pat_check = FALSE;} stmt {pat_check=TRUE; $$ = $2; }
1217 | stmts SEMI {pat_check=FALSE;} stmt {pat_check=TRUE; $$ = lconc($1,$4); }
1220 stmt : /* empty */ { $$ = Lnil; }
1221 | letdecls { $$ = lsing(mkseqlet($1)); }
1222 | expL { expORpat(LEGIT_EXPR,$1); $$ = lsing(mkdoexp($1,hsplineno)); }
1223 | expLno {pat_check=TRUE;} leftexp
1225 expORpat(LEGIT_EXPR,$1);
1226 $$ = lsing(mkdoexp($1,endlineno));
1228 expORpat(LEGIT_PATT,$1);
1229 $$ = lsing(mkdobind($1,$3,endlineno));
1235 leftexp : LARROW exp { $$ = $2; }
1236 | /* empty */ { $$ = NULL; }
1239 /**********************************************************************
1245 **********************************************************************/
1247 pat : dpat DCOLON tautype { $$ = mkrestr($1,$3); }
1251 dpat : qvar PLUS INTEGER { $$ = mkplusp($1, mkinteger($3)); }
1255 cpat : cpat qconop bpat { $$ = mkinfixap($2,$1,$3); }
1261 | qcon OCURLY rpats CCURLY { $$ = mkrecord($1,$3); }
1262 | MINUS INTEGER { $$ = mknegate(mklit(mkinteger($2))); }
1263 | MINUS FLOAT { $$ = mknegate(mklit(mkfloatr($2))); }
1266 conpat : gcon { $$ = mkident($1); }
1267 | conpat apat { $$ = mkap($1,$2); }
1270 apat : gcon { $$ = mkident($1); }
1271 | qcon OCURLY rpats CCURLY { $$ = mkrecord($1,$3); }
1275 apatc : qvar { $$ = mkident($1); }
1276 | qvar AT apat { $$ = mkas($1,$3); }
1277 | lit_constant { $$ = mklit($1); }
1278 | OPAREN pat CPAREN { $$ = mkpar($2); }
1279 | OPAREN pat COMMA pats CPAREN { $$ = mktuple(mklcons($2,$4)); }
1280 | OUNBOXPAREN pats CUNBOXPAREN { $$ = mkutuple($2); }
1281 | OBRACK pats CBRACK { $$ = mkllist($2); }
1282 | LAZY apat { $$ = mklazyp($2); }
1286 INTEGER { $$ = mkinteger($1); }
1287 | FLOAT { $$ = mkfloatr($1); }
1288 | CHAR { $$ = mkcharr($1); }
1289 | STRING { $$ = mkstring($1); }
1290 | CHARPRIM { $$ = mkcharprim($1); }
1291 | STRINGPRIM { $$ = mkstringprim($1); }
1292 | INTPRIM { $$ = mkintprim($1); }
1293 | FLOATPRIM { $$ = mkfloatprim($1); }
1294 | DOUBLEPRIM { $$ = mkdoubleprim($1); }
1295 | CLITLIT /* yurble yurble */ { $$ = mkclitlit($1); }
1298 /* Sequence of apats for a lambda abstraction */
1299 lampats : apat lampats { $$ = mklcons($1,$2); }
1300 | apat { $$ = lsing($1); }
1301 /* right recursion? (WDP) */
1304 /* Comma-separated sequence of pats */
1305 pats : pat COMMA pats { $$ = mklcons($1, $3); }
1306 | pat { $$ = lsing($1); }
1307 /* right recursion? (WDP) */
1310 /* Comma separated sequence of record patterns, each of form 'field=pat' */
1311 rpats : /* empty */ { $$ = Lnil; }
1315 rpats1 : rpat { $$ = lsing($1); }
1316 | rpats1 COMMA rpat { $$ = lapp($1,$3); }
1319 rpat : qvar { punningNowIllegal(); }
1320 | qvar EQUAL pat { $$ = mkrbind($1,mkjust($3)); }
1324 /* I can't figure out just what these ...k patterns are for.
1325 It seems to have something to do with recording the line number */
1327 /* Corresponds to a cpat */
1328 patk : patk qconop bpat { $$ = mkinfixap($2,$1,$3); }
1334 | qconk OCURLY rpats CCURLY { $$ = mkrecord($1,$3); }
1335 | minuskey INTEGER { $$ = mknegate(mklit(mkinteger($2))); }
1336 | minuskey FLOAT { $$ = mknegate(mklit(mkfloatr($2))); }
1339 conpatk : gconk { $$ = mkident($1); }
1340 | conpatk apat { $$ = mkap($1,$2); }
1343 apatck : qvark { $$ = mkident($1); }
1344 | qvark AT apat { $$ = mkas($1,$3); }
1345 | lit_constant { $$ = mklit($1); setstartlineno(); }
1346 | oparenkey pat CPAREN { $$ = mkpar($2); }
1347 | oparenkey pat COMMA pats CPAREN { $$ = mktuple(mklcons($2,$4)); }
1348 | ounboxparenkey pat COMMA pats CUNBOXPAREN
1349 { $$ = mkutuple(mklcons($2,$4)); }
1350 | obrackkey pats CBRACK { $$ = mkllist($2); }
1351 | lazykey apat { $$ = mklazyp($2); }
1356 | OBRACK CBRACK { $$ = creategid(NILGID); }
1357 | OPAREN CPAREN { $$ = creategid(UNITGID); }
1358 | OPAREN commas CPAREN { $$ = creategid($2); }
1362 | obrackkey CBRACK { $$ = creategid(NILGID); }
1363 | oparenkey CPAREN { $$ = creategid(UNITGID); }
1364 | oparenkey commas CPAREN { $$ = creategid($2); }
1367 /**********************************************************************
1370 * Keywords which record the line start *
1373 **********************************************************************/
1375 importkey: IMPORT { setstartlineno(); $$ = 0; }
1376 | IMPORT SOURCE_UPRAGMA { setstartlineno(); $$ = 1; }
1379 datakey : DATA { setstartlineno();
1382 printf("%u\n",startlineno);
1384 fprintf(stderr,"%u\tdata\n",startlineno);
1389 typekey : TYPE { setstartlineno();
1392 printf("%u\n",startlineno);
1394 fprintf(stderr,"%u\ttype\n",startlineno);
1399 newtypekey : NEWTYPE { setstartlineno();
1402 printf("%u\n",startlineno);
1404 fprintf(stderr,"%u\tnewtype\n",startlineno);
1409 instkey : INSTANCE { setstartlineno();
1412 printf("%u\n",startlineno);
1415 fprintf(stderr,"%u\tinstance\n",startlineno);
1420 defaultkey: DEFAULT { setstartlineno(); }
1423 foreignkey: FOREIGN { setstartlineno(); }
1426 classkey: CLASS { setstartlineno();
1429 printf("%u\n",startlineno);
1431 fprintf(stderr,"%u\tclass\n",startlineno);
1436 modulekey: MODULE { setstartlineno();
1439 printf("%u\n",startlineno);
1441 fprintf(stderr,"%u\tmodule\n",startlineno);
1446 oparenkey: OPAREN { setstartlineno(); }
1449 ounboxparenkey: OUNBOXPAREN { setstartlineno(); }
1452 obrackkey: OBRACK { setstartlineno(); }
1455 lazykey : LAZY { setstartlineno(); }
1458 minuskey: MINUS { setstartlineno(); }
1462 /**********************************************************************
1465 * Basic qualified/unqualified ids/ops *
1468 **********************************************************************/
1471 | OPAREN qvarsym CPAREN { $$ = $2; }
1474 | OPAREN qconsym CPAREN { $$ = $2; }
1477 | BQUOTE qvarid BQUOTE { $$ = $2; }
1480 | BQUOTE qconid BQUOTE { $$ = $2; }
1486 /* Non "-" op, used in right sections */
1491 /* Non "-" varop, used in right sections */
1493 | varsym_nominus { $$ = mknoqual($1); }
1494 | BQUOTE qvarid BQUOTE { $$ = $2; }
1499 | OPAREN varsym CPAREN { $$ = $2; }
1501 con : tycon /* using tycon removes conflicts */
1502 | OPAREN CONSYM CPAREN { $$ = $2; }
1505 | BQUOTE varid BQUOTE { $$ = $2; }
1508 | BQUOTE CONID BQUOTE { $$ = $2; }
1514 qvark : qvarid { setstartlineno(); $$ = $1; }
1515 | oparenkey qvarsym CPAREN { $$ = $2; }
1517 qconk : qconid { setstartlineno(); $$ = $1; }
1518 | oparenkey qconsym CPAREN { $$ = $2; }
1520 vark : varid { setstartlineno(); $$ = $1; }
1521 | oparenkey varsym CPAREN { $$ = $2; }
1525 | varid { $$ = mknoqual($1); }
1528 | varsym { $$ = mknoqual($1); }
1531 | tycon { $$ = mknoqual($1); } /* using tycon removes conflicts */
1534 | CONSYM { $$ = mknoqual($1); }
1537 | tycon { $$ = mknoqual($1); } /* using tycon removes conflicts */
1540 | tycon { $$ = mknoqual($1); } /* using tycon removes conflicts */
1543 varsym : varsym_nominus
1544 | MINUS { $$ = install_literal("-"); }
1547 /* PLUS, BANG are valid varsyms */
1548 varsym_nominus : VARSYM
1549 | PLUS { $$ = install_literal("+"); }
1550 | BANG { $$ = install_literal("!"); }
1551 | DOT { $$ = install_literal("."); }
1554 /* AS HIDING QUALIFIED are valid varids */
1555 varid : varid_noforall
1556 | FORALL { $$ = install_literal("forall"); }
1561 | AS { $$ = install_literal("as"); }
1562 | HIDING { $$ = install_literal("hiding"); }
1563 | QUALIFIED { $$ = install_literal("qualified"); }
1564 /* The rest of these guys are used by the FFI decls, a ghc (and hugs) extension. */
1565 | EXPORT { $$ = install_literal("export"); }
1566 | UNSAFE { $$ = install_literal("unsafe"); }
1567 | DYNAMIC { $$ = install_literal("dynamic"); }
1568 | LABEL { $$ = install_literal("label"); }
1569 | C_CALL { $$ = install_literal("ccall"); }
1570 | STDCALL { $$ = install_literal("stdcall"); }
1571 | PASCAL { $$ = install_literal("pascal"); }
1583 /* ---------------------------------------------- */
1584 tyvar : varid_noforall { $$ = $1; }
1587 /* tyvars1: At least one tyvar */
1588 tyvars1 : tyvar { $$ = lsing($1); }
1589 | tyvar tyvars1 { $$ = mklcons($1,$2); }
1592 /**********************************************************************
1595 * Stuff to do with layout *
1598 **********************************************************************/
1600 ocurly : layout OCURLY { hsincindent(); }
1602 vocurly : layout { hssetindent(); }
1605 layout : { hsindentoff(); }
1611 FN = NULL; SAMEFN = 0;
1616 vccurly : { expect_ccurly = 1; } vccurly1 { expect_ccurly = 0; }
1622 FN = NULL; SAMEFN = 0;
1628 FN = NULL; SAMEFN = 0;
1635 /**********************************************************************
1637 * Error Processing and Reporting *
1639 * (This stuff is here in case we want to use Yacc macros and such.) *
1641 **********************************************************************/
1644 static void checkinpat()
1647 hsperror("pattern syntax used in expression");
1650 static void punningNowIllegal()
1652 hsperror("Haskell 98 does not support 'punning' on records");
1656 /* The parser calls "hsperror" when it sees a
1657 `report this and die' error. It sets the stage
1658 and calls "yyerror".
1660 There should be no direct calls in the parser to
1661 "yyerror", except for the one from "hsperror". Thus,
1662 the only other calls will be from the error productions
1663 introduced by yacc/bison/whatever.
1665 We need to be able to recognise the from-error-production
1666 case, because we sometimes want to say, "Oh, never mind",
1667 because the layout rule kicks into action and may save
1671 static BOOLEAN error_and_I_mean_it = FALSE;
1677 error_and_I_mean_it = TRUE;
1681 extern char *yytext;
1688 /* We want to be able to distinguish 'error'-raised yyerrors
1689 from yyerrors explicitly coded by the parser hacker.
1691 if ( expect_ccurly && ! error_and_I_mean_it ) {
1695 fprintf(stderr, "%s:%d:%d: %s on input: ",
1696 input_filename, hsplineno, hspcolno + 1, s);
1698 if (yyleng == 1 && *yytext == '\0')
1699 fprintf(stderr, "<EOF>");
1703 format_string(stderr, (unsigned char *) yytext, yyleng);
1706 fputc('\n', stderr);
1708 /* a common problem */
1709 if (strcmp(yytext, "#") == 0)
1710 fprintf(stderr, "\t(Perhaps you forgot a `-cpp' or `-fglasgow-exts' flag?)\n");
1717 format_string(fp, s, len)
1724 case '\0': fputs("\\NUL", fp); break;
1725 case '\007': fputs("\\a", fp); break;
1726 case '\010': fputs("\\b", fp); break;
1727 case '\011': fputs("\\t", fp); break;
1728 case '\012': fputs("\\n", fp); break;
1729 case '\013': fputs("\\v", fp); break;
1730 case '\014': fputs("\\f", fp); break;
1731 case '\015': fputs("\\r", fp); break;
1732 case '\033': fputs("\\ESC", fp); break;
1733 case '\034': fputs("\\FS", fp); break;
1734 case '\035': fputs("\\GS", fp); break;
1735 case '\036': fputs("\\RS", fp); break;
1736 case '\037': fputs("\\US", fp); break;
1737 case '\177': fputs("\\DEL", fp); break;
1742 fprintf(fp, "\\^%c", *s + '@');