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 exp COMMA texps CUNBOXPAREN
1073 { $$ = mkutuple(mklcons($2,$4)); }
1075 /* only in expressions ... */
1076 | aexp OCURLY rbinds1 CCURLY { $$ = mkrupdate($1,$3); }
1077 | OBRACK exp VBAR quals CBRACK { $$ = mkcomprh($2,$4); }
1078 | OBRACK exp COMMA exp DOTDOT exp CBRACK {$$= mkeenum($2,mkjust($4),mkjust($6)); }
1079 | OBRACK exp COMMA exp DOTDOT CBRACK { $$ = mkeenum($2,mkjust($4),mknothing()); }
1080 | OBRACK exp DOTDOT exp CBRACK { $$ = mkeenum($2,mknothing(),mkjust($4)); }
1081 | OBRACK exp DOTDOT CBRACK { $$ = mkeenum($2,mknothing(),mknothing()); }
1082 | OPAREN oexp qop CPAREN { $$ = mklsection($2,$3); }
1083 | OPAREN qop1 oexp CPAREN { $$ = mkrsection($2,$3); }
1085 /* only in patterns ... */
1086 /* these add 2 S/R conflict with with aexp . OCURLY rbinds CCURLY */
1087 | qvar AT aexp { checkinpat(); $$ = mkas($1,$3); }
1088 | LAZY aexp { checkinpat(); $$ = mklazyp($2); }
1091 /* ccall arguments */
1092 cexps : cexps aexp { $$ = lapp($1,$2); }
1093 | aexp { $$ = lsing($1); }
1096 caserest: ocurly alts ccurly { $$ = $2; }
1097 | vocurly alts vccurly { $$ = $2; }
1099 dorest : ocurly stmts ccurly { checkdostmts($2); $$ = $2; }
1100 | vocurly stmts vccurly { checkdostmts($2); $$ = $2; }
1103 rbinds : /* empty */ { $$ = Lnil; }
1107 rbinds1 : rbind { $$ = lsing($1); }
1108 | rbinds1 COMMA rbind { $$ = lapp($1,$3); }
1111 rbind : qvar { punningNowIllegal(); }
1112 | qvar EQUAL exp { $$ = mkrbind($1,mkjust($3)); }
1115 texps : exp { $$ = lsing($1); }
1116 | exp COMMA texps { $$ = mklcons($1, $3) }
1117 /* right recursion? WDP */
1121 exp { $$ = lsing($1); }
1122 | exp COMMA exp { $$ = mklcons( $1, lsing($3) ); }
1123 | exp COMMA exp COMMA list_rest { $$ = mklcons( $1, mklcons( $3, reverse_list( $5 ))); }
1126 /* Use left recusion for list_rest, because we sometimes get programs with
1127 very long explicit lists. */
1128 list_rest : exp { $$ = lsing($1); }
1129 | list_rest COMMA exp { $$ = mklcons( $3, $1 ); }
1133 exp { $$ = lsing($1); }
1134 | exp COMMA list_exps { $$ = mklcons($1, $3); }
1136 /* right recursion? (WDP)
1138 It has to be this way, though, otherwise you
1139 may do the wrong thing to distinguish between...
1141 [ e1 , e2 .. ] -- an enumeration ...
1142 [ e1 , e2 , e3 ] -- a list
1144 (In fact, if you change the grammar and throw yacc/bison
1145 at it, it *will* do the wrong thing [WDP 94/06])
1148 letdecls: LET { pat_check = TRUE; } ocurly decls ccurly { $$ = $4; }
1149 | LET { pat_check = TRUE; } vocurly decls vccurly { $$ = $4; }
1153 When parsing patterns inside do stmt blocks or quals, we have
1154 to tentatively parse them as expressions, since we don't know at
1155 the time of parsing `p' whether it will be part of "p <- e" (pat)
1156 or "p" (expr). When we eventually can tell the difference, the parse
1157 of `p' is examined to see if it consitutes a syntactically legal pattern
1160 The expr rule used to parse the pattern/expression do contain
1161 pattern-special productions (e.g., _ , a@pat, etc.), which are
1162 illegal in expressions. Since we don't know whether what
1163 we're parsing is an expression rather than a pattern, we turn off
1164 the check and instead do it later.
1166 The rather clumsy way that this check is turned on/off is there
1167 to work around a Bison feature/shortcoming. Turning the flag
1168 on/off just around the relevant nonterminal by decorating it
1169 with simple semantic actions, e.g.,
1171 {pat_check = FALSE; } expLNo { pat_check = TRUE; }
1173 causes Bison to generate a parser where in one state it either
1174 has to reduce/perform a semantic action ( { pat_check = FALSE; })
1175 or reduce an error (the error production used to implement
1176 vccurly.) Bison picks the semantic action, which it ideally shouldn't.
1177 The work around is to lift out the setting of { pat_check = FALSE; }
1178 and then later reset pat_check. Not pretty.
1183 quals : { pat_check = FALSE;} qual { pat_check = TRUE; $$ = lsing($2); }
1184 | quals COMMA { pat_check = FALSE; } qual { pat_check = TRUE; $$ = lapp($1,$4); }
1187 qual : letdecls { $$ = mkseqlet($1); }
1188 | expL { expORpat(LEGIT_EXPR,$1); $$ = $1; }
1189 | expLno { pat_check = TRUE; } leftexp
1191 expORpat(LEGIT_EXPR,$1);
1194 expORpat(LEGIT_PATT,$1);
1200 alts : /* empty */ { $$ = Lnil; }
1201 | alt { $$ = lsing($1); }
1202 | alt SEMI alts { $$ = mklcons($1,$3); }
1203 | SEMI alts { $$ = $2; }
1206 alt : dpat opt_sig altrhs { $$ = mkpmatch( lsing($1), $2, $3 ); }
1209 altrhs : RARROW get_line_no exp maybe_where { $$ = mkpnoguards($2, $3, $4); }
1210 | gdpat maybe_where { $$ = mkpguards($1, $2); }
1213 gdpat : gd RARROW get_line_no exp { $$ = lsing(mkpgdexp($1,$3,$4)); }
1214 | gd RARROW get_line_no exp gdpat { $$ = mklcons(mkpgdexp($1,$3,$4),$5); }
1217 stmts : {pat_check = FALSE;} stmt {pat_check=TRUE; $$ = $2; }
1218 | stmts SEMI {pat_check=FALSE;} stmt {pat_check=TRUE; $$ = lconc($1,$4); }
1221 stmt : /* empty */ { $$ = Lnil; }
1222 | letdecls { $$ = lsing(mkseqlet($1)); }
1223 | expL { expORpat(LEGIT_EXPR,$1); $$ = lsing(mkdoexp($1,hsplineno)); }
1224 | expLno {pat_check=TRUE;} leftexp
1226 expORpat(LEGIT_EXPR,$1);
1227 $$ = lsing(mkdoexp($1,endlineno));
1229 expORpat(LEGIT_PATT,$1);
1230 $$ = lsing(mkdobind($1,$3,endlineno));
1236 leftexp : LARROW exp { $$ = $2; }
1237 | /* empty */ { $$ = NULL; }
1240 /**********************************************************************
1246 **********************************************************************/
1248 pat : dpat DCOLON tautype { $$ = mkrestr($1,$3); }
1252 dpat : qvar PLUS INTEGER { $$ = mkplusp($1, mkinteger($3)); }
1256 cpat : cpat qconop bpat { $$ = mkinfixap($2,$1,$3); }
1262 | qcon OCURLY rpats CCURLY { $$ = mkrecord($1,$3); }
1263 | MINUS INTEGER { $$ = mknegate(mklit(mkinteger($2))); }
1264 | MINUS FLOAT { $$ = mknegate(mklit(mkfloatr($2))); }
1267 conpat : gcon { $$ = mkident($1); }
1268 | conpat apat { $$ = mkap($1,$2); }
1271 apat : gcon { $$ = mkident($1); }
1272 | qcon OCURLY rpats CCURLY { $$ = mkrecord($1,$3); }
1276 apatc : qvar { $$ = mkident($1); }
1277 | qvar AT apat { $$ = mkas($1,$3); }
1278 | lit_constant { $$ = mklit($1); }
1279 | OPAREN pat CPAREN { $$ = mkpar($2); }
1280 | OPAREN pat COMMA pats CPAREN { $$ = mktuple(mklcons($2,$4)); }
1281 | OUNBOXPAREN pat COMMA pats CUNBOXPAREN { $$ = mkutuple(mklcons($2,$4)); }
1282 | OBRACK pats CBRACK { $$ = mkllist($2); }
1283 | LAZY apat { $$ = mklazyp($2); }
1287 INTEGER { $$ = mkinteger($1); }
1288 | FLOAT { $$ = mkfloatr($1); }
1289 | CHAR { $$ = mkcharr($1); }
1290 | STRING { $$ = mkstring($1); }
1291 | CHARPRIM { $$ = mkcharprim($1); }
1292 | STRINGPRIM { $$ = mkstringprim($1); }
1293 | INTPRIM { $$ = mkintprim($1); }
1294 | FLOATPRIM { $$ = mkfloatprim($1); }
1295 | DOUBLEPRIM { $$ = mkdoubleprim($1); }
1296 | CLITLIT /* yurble yurble */ { $$ = mkclitlit($1); }
1299 /* Sequence of apats for a lambda abstraction */
1300 lampats : apat lampats { $$ = mklcons($1,$2); }
1301 | apat { $$ = lsing($1); }
1302 /* right recursion? (WDP) */
1305 /* Comma-separated sequence of pats */
1306 pats : pat COMMA pats { $$ = mklcons($1, $3); }
1307 | pat { $$ = lsing($1); }
1308 /* right recursion? (WDP) */
1311 /* Comma separated sequence of record patterns, each of form 'field=pat' */
1312 rpats : /* empty */ { $$ = Lnil; }
1316 rpats1 : rpat { $$ = lsing($1); }
1317 | rpats1 COMMA rpat { $$ = lapp($1,$3); }
1320 rpat : qvar { punningNowIllegal(); }
1321 | qvar EQUAL pat { $$ = mkrbind($1,mkjust($3)); }
1325 /* I can't figure out just what these ...k patterns are for.
1326 It seems to have something to do with recording the line number */
1328 /* Corresponds to a cpat */
1329 patk : patk qconop bpat { $$ = mkinfixap($2,$1,$3); }
1335 | qconk OCURLY rpats CCURLY { $$ = mkrecord($1,$3); }
1336 | minuskey INTEGER { $$ = mknegate(mklit(mkinteger($2))); }
1337 | minuskey FLOAT { $$ = mknegate(mklit(mkfloatr($2))); }
1340 conpatk : gconk { $$ = mkident($1); }
1341 | conpatk apat { $$ = mkap($1,$2); }
1344 apatck : qvark { $$ = mkident($1); }
1345 | qvark AT apat { $$ = mkas($1,$3); }
1346 | lit_constant { $$ = mklit($1); setstartlineno(); }
1347 | oparenkey pat CPAREN { $$ = mkpar($2); }
1348 | oparenkey pat COMMA pats CPAREN { $$ = mktuple(mklcons($2,$4)); }
1349 | ounboxparenkey pat COMMA pats CUNBOXPAREN
1350 { $$ = mkutuple(mklcons($2,$4)); }
1351 | obrackkey pats CBRACK { $$ = mkllist($2); }
1352 | lazykey apat { $$ = mklazyp($2); }
1357 | OBRACK CBRACK { $$ = creategid(NILGID); }
1358 | OPAREN CPAREN { $$ = creategid(UNITGID); }
1359 | OPAREN commas CPAREN { $$ = creategid($2); }
1363 | obrackkey CBRACK { $$ = creategid(NILGID); }
1364 | oparenkey CPAREN { $$ = creategid(UNITGID); }
1365 | oparenkey commas CPAREN { $$ = creategid($2); }
1368 /**********************************************************************
1371 * Keywords which record the line start *
1374 **********************************************************************/
1376 importkey: IMPORT { setstartlineno(); $$ = 0; }
1377 | IMPORT SOURCE_UPRAGMA { setstartlineno(); $$ = 1; }
1380 datakey : DATA { setstartlineno();
1383 printf("%u\n",startlineno);
1385 fprintf(stderr,"%u\tdata\n",startlineno);
1390 typekey : TYPE { setstartlineno();
1393 printf("%u\n",startlineno);
1395 fprintf(stderr,"%u\ttype\n",startlineno);
1400 newtypekey : NEWTYPE { setstartlineno();
1403 printf("%u\n",startlineno);
1405 fprintf(stderr,"%u\tnewtype\n",startlineno);
1410 instkey : INSTANCE { setstartlineno();
1413 printf("%u\n",startlineno);
1416 fprintf(stderr,"%u\tinstance\n",startlineno);
1421 defaultkey: DEFAULT { setstartlineno(); }
1424 foreignkey: FOREIGN { setstartlineno(); }
1427 classkey: CLASS { setstartlineno();
1430 printf("%u\n",startlineno);
1432 fprintf(stderr,"%u\tclass\n",startlineno);
1437 modulekey: MODULE { setstartlineno();
1440 printf("%u\n",startlineno);
1442 fprintf(stderr,"%u\tmodule\n",startlineno);
1447 oparenkey: OPAREN { setstartlineno(); }
1450 ounboxparenkey: OUNBOXPAREN { setstartlineno(); }
1453 obrackkey: OBRACK { setstartlineno(); }
1456 lazykey : LAZY { setstartlineno(); }
1459 minuskey: MINUS { setstartlineno(); }
1463 /**********************************************************************
1466 * Basic qualified/unqualified ids/ops *
1469 **********************************************************************/
1472 | OPAREN qvarsym CPAREN { $$ = $2; }
1475 | OPAREN qconsym CPAREN { $$ = $2; }
1478 | BQUOTE qvarid BQUOTE { $$ = $2; }
1481 | BQUOTE qconid BQUOTE { $$ = $2; }
1487 /* Non "-" op, used in right sections */
1492 /* Non "-" varop, used in right sections */
1494 | varsym_nominus { $$ = mknoqual($1); }
1495 | BQUOTE qvarid BQUOTE { $$ = $2; }
1500 | OPAREN varsym CPAREN { $$ = $2; }
1502 con : tycon /* using tycon removes conflicts */
1503 | OPAREN CONSYM CPAREN { $$ = $2; }
1506 | BQUOTE varid BQUOTE { $$ = $2; }
1509 | BQUOTE CONID BQUOTE { $$ = $2; }
1515 qvark : qvarid { setstartlineno(); $$ = $1; }
1516 | oparenkey qvarsym CPAREN { $$ = $2; }
1518 qconk : qconid { setstartlineno(); $$ = $1; }
1519 | oparenkey qconsym CPAREN { $$ = $2; }
1521 vark : varid { setstartlineno(); $$ = $1; }
1522 | oparenkey varsym CPAREN { $$ = $2; }
1526 | varid { $$ = mknoqual($1); }
1529 | varsym { $$ = mknoqual($1); }
1532 | tycon { $$ = mknoqual($1); } /* using tycon removes conflicts */
1535 | CONSYM { $$ = mknoqual($1); }
1538 | tycon { $$ = mknoqual($1); } /* using tycon removes conflicts */
1541 | tycon { $$ = mknoqual($1); } /* using tycon removes conflicts */
1544 varsym : varsym_nominus
1545 | MINUS { $$ = install_literal("-"); }
1548 /* PLUS, BANG are valid varsyms */
1549 varsym_nominus : VARSYM
1550 | PLUS { $$ = install_literal("+"); }
1551 | BANG { $$ = install_literal("!"); }
1552 | DOT { $$ = install_literal("."); }
1555 /* AS HIDING QUALIFIED are valid varids */
1556 varid : varid_noforall
1557 | FORALL { $$ = install_literal("forall"); }
1562 | AS { $$ = install_literal("as"); }
1563 | HIDING { $$ = install_literal("hiding"); }
1564 | QUALIFIED { $$ = install_literal("qualified"); }
1565 /* The rest of these guys are used by the FFI decls, a ghc (and hugs) extension. */
1566 | EXPORT { $$ = install_literal("export"); }
1567 | UNSAFE { $$ = install_literal("unsafe"); }
1568 | DYNAMIC { $$ = install_literal("dynamic"); }
1569 | LABEL { $$ = install_literal("label"); }
1570 | C_CALL { $$ = install_literal("ccall"); }
1571 | STDCALL { $$ = install_literal("stdcall"); }
1572 | PASCAL { $$ = install_literal("pascal"); }
1584 /* ---------------------------------------------- */
1585 tyvar : varid_noforall { $$ = $1; }
1588 /* tyvars1: At least one tyvar */
1589 tyvars1 : tyvar { $$ = lsing($1); }
1590 | tyvar tyvars1 { $$ = mklcons($1,$2); }
1593 /**********************************************************************
1596 * Stuff to do with layout *
1599 **********************************************************************/
1601 ocurly : layout OCURLY { hsincindent(); }
1603 vocurly : layout { hssetindent(); }
1606 layout : { hsindentoff(); }
1612 FN = NULL; SAMEFN = 0;
1617 vccurly : { expect_ccurly = 1; } vccurly1 { expect_ccurly = 0; }
1623 FN = NULL; SAMEFN = 0;
1629 FN = NULL; SAMEFN = 0;
1636 /**********************************************************************
1638 * Error Processing and Reporting *
1640 * (This stuff is here in case we want to use Yacc macros and such.) *
1642 **********************************************************************/
1645 static void checkinpat()
1648 hsperror("pattern syntax used in expression");
1651 static void punningNowIllegal()
1653 hsperror("Haskell 98 does not support 'punning' on records");
1657 /* The parser calls "hsperror" when it sees a
1658 `report this and die' error. It sets the stage
1659 and calls "yyerror".
1661 There should be no direct calls in the parser to
1662 "yyerror", except for the one from "hsperror". Thus,
1663 the only other calls will be from the error productions
1664 introduced by yacc/bison/whatever.
1666 We need to be able to recognise the from-error-production
1667 case, because we sometimes want to say, "Oh, never mind",
1668 because the layout rule kicks into action and may save
1672 static BOOLEAN error_and_I_mean_it = FALSE;
1678 error_and_I_mean_it = TRUE;
1682 extern char *yytext;
1689 /* We want to be able to distinguish 'error'-raised yyerrors
1690 from yyerrors explicitly coded by the parser hacker.
1692 if ( expect_ccurly && ! error_and_I_mean_it ) {
1696 fprintf(stderr, "%s:%d:%d: %s on input: ",
1697 input_filename, hsplineno, hspcolno + 1, s);
1699 if (yyleng == 1 && *yytext == '\0')
1700 fprintf(stderr, "<EOF>");
1704 format_string(stderr, (unsigned char *) yytext, yyleng);
1707 fputc('\n', stderr);
1709 /* a common problem */
1710 if (strcmp(yytext, "#") == 0)
1711 fprintf(stderr, "\t(Perhaps you forgot a `-cpp' or `-fglasgow-exts' flag?)\n");
1718 format_string(fp, s, len)
1725 case '\0': fputs("\\NUL", fp); break;
1726 case '\007': fputs("\\a", fp); break;
1727 case '\010': fputs("\\b", fp); break;
1728 case '\011': fputs("\\t", fp); break;
1729 case '\012': fputs("\\n", fp); break;
1730 case '\013': fputs("\\v", fp); break;
1731 case '\014': fputs("\\f", fp); break;
1732 case '\015': fputs("\\r", fp); break;
1733 case '\033': fputs("\\ESC", fp); break;
1734 case '\034': fputs("\\FS", fp); break;
1735 case '\035': fputs("\\GS", fp); break;
1736 case '\036': fputs("\\RS", fp); break;
1737 case '\037': fputs("\\US", fp); break;
1738 case '\177': fputs("\\DEL", fp); break;
1743 fprintf(fp, "\\^%c", *s + '@');