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;
109 /**********************************************************************
112 * These are lexemes. *
115 **********************************************************************/
118 %token VARID CONID QVARID QCONID
119 VARSYM CONSYM QVARSYM QCONSYM
121 %token INTEGER FLOAT CHAR STRING
122 CHARPRIM STRINGPRIM INTPRIM FLOATPRIM
127 /**********************************************************************
133 **********************************************************************/
135 %token OCURLY CCURLY VCCURLY
136 %token COMMA SEMI OBRACK CBRACK
137 %token BQUOTE OPAREN CPAREN
138 %token OUNBOXPAREN CUNBOXPAREN
141 /**********************************************************************
144 * Reserved Operators *
147 **********************************************************************/
149 %token DOTDOT DCOLON EQUAL LAMBDA
150 %token VBAR RARROW LARROW
151 %token AT LAZY DARROW
154 /**********************************************************************
157 * Reserved Identifiers *
160 **********************************************************************/
162 %token CASE CLASS DATA
163 %token DEFAULT DERIVING DO
164 %token ELSE IF IMPORT
165 %token IN INFIX INFIXL
166 %token INFIXR INSTANCE LET
167 %token MODULE NEWTYPE OF
168 %token THEN TYPE WHERE
171 %token CCALL CCALL_GC CASM CASM_GC
174 %token EXPORT UNSAFE STDCALL C_CALL LABEL
175 %token PASCAL FASTCALL FOREIGN DYNAMIC
177 /**********************************************************************
180 * Special symbols/identifiers which need to be recognised *
183 **********************************************************************/
185 %token MINUS BANG PLUS
186 %token AS HIDING QUALIFIED
189 /**********************************************************************
192 * Special Symbols for the Lexer *
195 **********************************************************************/
197 %token INTERFACE_UPRAGMA SPECIALISE_UPRAGMA
198 %token INLINE_UPRAGMA NOINLINE_UPRAGMA MAGIC_UNFOLDING_UPRAGMA RULES_UPRAGMA
200 %token SOURCE_UPRAGMA
202 /**********************************************************************
205 * Precedences of the various tokens *
208 **********************************************************************/
213 SCC CASM CCALL CASM_GC CCALL_GC
215 %left VARSYM CONSYM QVARSYM QCONSYM
216 MINUS BQUOTE BANG DARROW PLUS
222 %left OCURLY OBRACK OPAREN
228 /**********************************************************************
231 * Type Declarations *
234 **********************************************************************/
237 %type <ulist> caserest alts quals
239 rbinds rbinds1 rpats rpats1 list_exps list_rest
241 constrs fields conargatypes
242 tautypes polytypes atypes
243 pats simple_context simple_context_list
246 impdecls maybeimpdecls impdecl
249 lampats aexps gd texps
250 var_list constr_context forall
251 rule_forall rule_var_list
255 %type <ugrhsb> valrhs altrhs
257 %type <umaybe> maybeexports impspec deriving
258 ext_name opt_sig opt_asig
260 %type <uliteral> lit_constant
262 %type <utree> exp oexp dexp kexp fexp aexp rbind
263 expL oexpL kexpL expLno oexpLno dexpLno kexpLno
264 funlhs funlhs1 funlhs2 funlhs3 qual leftexp
265 pat dpat cpat bpat apat apatc conpat rpat
266 patk bpatk apatck conpatk
269 %type <urulevar> rule_var
271 %type <uid> MINUS PLUS DARROW AS LAZY
272 VARID CONID VARSYM CONSYM
273 var con varop conop op
274 vark varid varsym varsym_nominus
275 tycon modid ccallid tyvar
278 %type <uqid> QVARID QCONID QVARSYM QCONSYM
279 qvarid qconid qvarsym qconsym
280 qvar qcon qvarop qconop qop
281 qvark qconk qtycon qtycls
282 gcon gconk gtycon itycon qop1 qvarop1
285 %type <ubinding> topdecl topdecls letdecls
286 typed datad newtd classd instd defaultd foreignd
287 decl decls non_empty_decls fixdecl fix_op fix_ops valdef
288 maybe_where where_body
291 %type <uttype> polytype
292 conargatype conapptype
296 simple_con_app simple_con_app1 inst_type
298 %type <uconstr> constr constr_after_context field constr1
300 %type <ustring> FLOAT INTEGER INTPRIM
301 FLOATPRIM DOUBLEPRIM CLITLIT
303 %type <uhstring> STRING STRINGPRIM CHAR CHARPRIM
305 %type <uentid> export import
307 %type <ulong> commas importkey get_line_no
311 /**********************************************************************
314 * Start Symbol for the Parser *
317 **********************************************************************/
322 module : modulekey modid maybeexports
324 modulelineno = startlineno;
325 the_module_name = $2;
331 the_module_name = install_literal("Main");
332 module_exports = mknothing();
337 body : ocurly { setstartlineno(); } main_body ccurly
338 | vocurly main_body vccurly
341 main_body : interface_pragma maybeimpdecls topdecls
343 root = mkhmodule(the_module_name, $2, module_exports,
344 $3, source_version,modulelineno);
346 | interface_pragma impdecls
348 root = mkhmodule(the_module_name, $2, module_exports,
349 mknullbind(), source_version, modulelineno);
352 interface_pragma : /* empty */
353 | INTERFACE_UPRAGMA INTEGER END_UPRAGMA SEMI
355 source_version = atoi($2);
359 maybeexports : /* empty */ { $$ = mknothing(); }
360 | OPAREN CPAREN { $$ = mkjust(Lnil); }
361 | OPAREN export_list CPAREN { $$ = mkjust($2); }
362 | OPAREN export_list COMMA CPAREN { $$ = mkjust($2); }
366 export { $$ = lsing($1); }
367 | export_list COMMA export { $$ = lapp($1, $3); }
370 export : qvar { $$ = mkentid($1); }
371 | gtycon { $$ = mkenttype($1); }
372 | gtycon OPAREN DOTDOT CPAREN { $$ = mkenttypeall($1); }
373 | gtycon OPAREN CPAREN { $$ = mkenttypenamed($1,Lnil); }
374 | gtycon OPAREN enames CPAREN { $$ = mkenttypenamed($1,$3); }
375 | MODULE modid { $$ = mkentmod($2); }
378 enames : ename { $$ = lsing($1); }
379 | enames COMMA ename { $$ = lapp($1,$3); }
386 maybeimpdecls : /* empty */ { $$ = Lnil; }
387 | impdecls SEMI { $$ = $1; }
390 impdecls: impdecl { $$ = $1; }
391 | impdecls SEMI impdecl { $$ = lconc($1,$3); }
395 impdecl : importkey modid impspec
396 { $$ = lsing(mkimport($2,0,mknothing(),$3,$1,startlineno)); }
397 | importkey QUALIFIED modid impspec
398 { $$ = lsing(mkimport($3,1,mknothing(),$4,$1,startlineno)); }
399 | importkey QUALIFIED modid AS modid impspec
400 { $$ = lsing(mkimport($3,1,mkjust($5),$6,$1,startlineno)); }
401 | importkey modid AS modid impspec
402 { $$ = lsing(mkimport($3,1,mkjust($4),$5,$1,startlineno)); }
405 impspec : /* empty */ { $$ = mknothing(); }
406 | OPAREN CPAREN { $$ = mkjust(mkleft(Lnil)); }
407 | OPAREN import_list CPAREN { $$ = mkjust(mkleft($2)); }
408 | OPAREN import_list COMMA CPAREN { $$ = mkjust(mkleft($2)); }
409 | HIDING OPAREN CPAREN { $$ = mkjust(mkright(Lnil)); }
410 | HIDING OPAREN import_list CPAREN { $$ = mkjust(mkright($3)); }
411 | HIDING OPAREN import_list COMMA CPAREN { $$ = mkjust(mkright($3)); }
415 import { $$ = lsing($1); }
416 | import_list COMMA import { $$ = lapp($1, $3); }
419 import : var { $$ = mkentid(mknoqual($1)); }
420 | itycon { $$ = mkenttype($1); }
421 | itycon OPAREN DOTDOT CPAREN { $$ = mkenttypeall($1); }
422 | itycon OPAREN CPAREN { $$ = mkenttypenamed($1,Lnil);}
423 | itycon OPAREN inames CPAREN { $$ = mkenttypenamed($1,$3); }
426 itycon : tycon { $$ = mknoqual($1); }
427 | OBRACK CBRACK { $$ = creategid(NILGID); }
428 | OPAREN CPAREN { $$ = creategid(UNITGID); }
429 | OPAREN commas CPAREN { $$ = creategid($2); }
432 inames : iname { $$ = lsing($1); }
433 | inames COMMA iname { $$ = lapp($1,$3); }
435 iname : var { $$ = mknoqual($1); }
436 | con { $$ = mknoqual($1); }
439 /**********************************************************************
442 * Fixes and Decls etc *
445 **********************************************************************/
447 topdecls : /* empty */ { $$ = mknullbind(); }
449 | topdecls SEMI { $$ = $1; }
450 | topdecls SEMI topdecl
469 topdecl : typed { $$ = $1; FN = NULL; SAMEFN = 0; }
470 | datad { $$ = $1; FN = NULL; SAMEFN = 0; }
471 | newtd { $$ = $1; FN = NULL; SAMEFN = 0; }
472 | classd { $$ = $1; FN = NULL; SAMEFN = 0; }
473 | instd { $$ = $1; FN = NULL; SAMEFN = 0; }
474 | defaultd { $$ = $1; FN = NULL; SAMEFN = 0; }
475 | foreignd { $$ = $1; FN = NULL; SAMEFN = 0; }
476 | ruled { $$ = $1; FN = NULL; SAMEFN = 0; }
480 /* *********************************************************** */
481 /* Transformation rules */
483 ruled : RULES_UPRAGMA rules END_UPRAGMA { $$ = $2; }
486 rules : /* empty */ { $$ = mknullbind(); }
488 | rule SEMI rules { $$ = mkabind($1,$3); }
489 | SEMI rules { $$ = $2; }
492 rule : STRING rule_forall fexp
493 EQUAL get_line_no exp { $$ = mkrule_prag($1,$2,$3,$6,$5); }
495 rule_forall : FORALL rule_var_list DOT { $$ = $2; }
496 | /* Empty */ { $$ = Lnil; }
499 rule_var_list : /* Empty */ { $$ = Lnil; }
500 | rule_var { $$ = lsing($1); }
501 | rule_var COMMA rule_var_list { $$ = mklcons($1,$3); }
504 rule_var : varid { $$ = mkprulevar( $1 ); }
505 | varid DCOLON polytype { $$ = mkprulevarsig( $1, $3 ); }
508 /* *********************************************************** */
510 typed : typekey simple_con_app EQUAL tautype { $$ = mknbind($2,$4,startlineno); }
514 datad : datakey simple_con_app EQUAL constrs deriving
515 { $$ = mktbind(Lnil,$2,$4,$5,startlineno); }
516 | datakey simple_context DARROW simple_con_app EQUAL constrs deriving
517 { $$ = mktbind($2,$4,$6,$7,startlineno); }
520 newtd : newtypekey simple_con_app EQUAL constr1 deriving
521 { $$ = mkntbind(Lnil,$2,lsing($4),$5,startlineno); }
522 | newtypekey simple_context DARROW simple_con_app EQUAL constr1 deriving
523 { $$ = mkntbind($2,$4,lsing($6),$7,startlineno); }
526 deriving: /* empty */ { $$ = mknothing(); }
527 | DERIVING dtyclses { $$ = mkjust($2); }
530 classd : classkey apptype DARROW simple_con_app1 maybe_where
531 /* Context can now be more than simple_context */
532 { $$ = mkcbind(type2context($2),$4,$5,startlineno); }
533 | classkey apptype maybe_where
534 /* We have to say apptype rather than simple_con_app1, else
535 we get reduce/reduce errs */
536 { check_class_decl_head($2);
537 $$ = mkcbind(Lnil,$2,$3,startlineno); }
540 instd : instkey inst_type maybe_where { $$ = mkibind($2,$3,startlineno); }
543 /* Compare polytype */
544 /* [July 98: first production was tautype DARROW tautype, but I can't see why.] */
545 inst_type : apptype DARROW apptype { is_context_format( $3, 0 ); /* Check the instance head */
546 $$ = mkimp_forall(type2context($1),$3); }
547 | apptype { is_context_format( $1, 0 ); /* Check the instance head */
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
558 { $$ = mkfobind($6,$8,$4,$5,$3,FOREIGN_IMPORT,startlineno); }
559 | foreignkey EXPORT callconv ext_name qvarid DCOLON tautype
560 { $$ = mkfobind($5,$7,$4,0,$3,FOREIGN_EXPORT,startlineno); }
561 | foreignkey LABEL ext_name qvarid DCOLON tautype
562 { $$ = mkfobind($4,$6,$3,0,-1,FOREIGN_LABEL,startlineno); }
565 callconv: STDCALL { $$ = CALLCONV_STDCALL; }
566 | C_CALL { $$ = CALLCONV_CCALL; }
567 | PASCAL { $$ = CALLCONV_PASCAL; }
568 | FASTCALL { $$ = CALLCONV_FASTCALL; }
569 /* If you leave out the specification of a calling convention, you'll (probably) get C's. */
570 | /*empty*/ { $$ = CALLCONV_NONE; }
573 ext_name: STRING { $$ = mkjust(lsing($1)); }
574 | STRING STRING { $$ = mkjust(mklcons ($1,lsing($2))); }
575 | DYNAMIC { $$ = mknothing(); }
577 unsafe_flag: UNSAFE { $$ = 1; }
578 | /*empty*/ { $$ = 0; }
581 decls : /* empty */ { $$ = mknullbind(); }
583 | decls SEMI { $$ = $1; }
596 non_empty_decls : decl
597 | non_empty_decls SEMI { $$ = $1; }
598 | non_empty_decls SEMI decl
611 Note: if there is an iclasop_pragma here, then we must be
612 doing a class-op in an interface -- unless the user is up
613 to real mischief (ugly, but likely to work).
618 | qvarsk DCOLON polytype
619 { $$ = mksbind($1,$3,startlineno);
620 FN = NULL; SAMEFN = 0;
623 | qvark DCOLON polytype
624 { $$ = mksbind(lsing($1),$3,startlineno);
625 FN = NULL; SAMEFN = 0;
628 /* User-specified pragmas come in as "signatures"...
629 They are similar in that they can appear anywhere in the module,
630 and have to be "joined up" with their related entity.
632 Have left out the case specialising to an overloaded type.
633 Let's get real, OK? (WDP)
635 | SPECIALISE_UPRAGMA qvark DCOLON polytypes END_UPRAGMA
637 $$ = mkvspec_uprag($2, $4, startlineno);
638 FN = NULL; SAMEFN = 0;
641 | SPECIALISE_UPRAGMA INSTANCE inst_type END_UPRAGMA
643 $$ = mkispec_uprag($3, startlineno);
644 FN = NULL; SAMEFN = 0;
647 | SPECIALISE_UPRAGMA DATA gtycon atypes END_UPRAGMA
649 $$ = mkdspec_uprag($3, $4, startlineno);
650 FN = NULL; SAMEFN = 0;
653 | INLINE_UPRAGMA qvark END_UPRAGMA
655 $$ = mkinline_uprag($2, startlineno);
656 FN = NULL; SAMEFN = 0;
659 | NOINLINE_UPRAGMA qvark END_UPRAGMA
661 $$ = mknoinline_uprag($2, startlineno);
662 FN = NULL; SAMEFN = 0;
665 | MAGIC_UNFOLDING_UPRAGMA qvark vark END_UPRAGMA
667 $$ = mkmagicuf_uprag($2, $3, startlineno);
668 FN = NULL; SAMEFN = 0;
671 /* end of user-specified pragmas */
676 fixdecl : INFIXL INTEGER { Precedence = checkfixity($2); Fixity = INFIXL; }
678 | INFIXR INTEGER { Precedence = checkfixity($2); Fixity = INFIXR; }
680 | INFIX INTEGER { Precedence = checkfixity($2); Fixity = INFIX; }
682 | INFIXL { Fixity = INFIXL; Precedence = 9; }
684 | INFIXR { Fixity = INFIXR; Precedence = 9; }
686 | INFIX { Fixity = INFIX; Precedence = 9; }
690 /* Grotesque global-variable hack to
691 make a separate fixity decl for each op */
693 | fix_ops COMMA fix_op { $$ = mkabind($1,$3); }
696 fix_op : op { $$ = mkfixd(mknoqual($1),infixint(Fixity),Precedence,startlineno); }
699 qvarsk : qvark COMMA qvars_list { $$ = mklcons($1,$3); }
702 qvars_list: qvar { $$ = lsing($1); }
703 | qvars_list COMMA qvar { $$ = lapp($1,$3); }
707 /**********************************************************************
713 **********************************************************************/
715 /* "DCOLON context => tautype" vs "DCOLON tautype" is a problem,
716 because you can't distinguish between
718 foo :: (Baz a, Baz a)
719 bar :: (Baz a, Baz a) => [a] -> [a] -> [a]
721 with one token of lookahead. The HACK is to have "DCOLON apptype"
722 in the first case, then check that it has the right
723 form C a, or (C1 a, C2 b, ... Cn z) and convert it into a
727 /* --------------------------- */
732 polytype : FORALL var_list DOT
733 apptype DARROW tautype { $$ = mkforall($2, type2context($4), $6); }
734 | FORALL var_list DOT tautype { $$ = mkforall($2, Lnil, $4); }
735 | apptype DARROW tautype { $$ = mkimp_forall( type2context($1), $3); }
739 polytypes : polytype { $$ = lsing($1); }
740 | polytypes COMMA polytype { $$ = lapp($1,$3); }
743 /* --------------------------- */
744 /* tautype is just a monomorphic type.
745 But it may have nested for-alls if we're in a rank-2 type */
747 tautype : apptype RARROW tautype { $$ = mktfun($1,$3); }
748 | apptype { $$ = $1; }
751 tautypes : tautype { $$ = lsing($1); }
752 | tautypes COMMA tautype { $$ = lapp($1,$3); }
755 /* --------------------------- */
756 /* apptype: type application */
758 apptype : apptype atype { $$ = mktapp($1,$2); }
762 /* --------------------------- */
763 /* atype: an atomic or bracketed type: T, x, [ty], tuple ty */
765 atypes : atype { $$ = lsing($1); }
766 | atype atypes { $$ = mklcons($1,$2); }
769 atype : gtycon { $$ = mktname($1); }
770 | tyvar { $$ = mknamedtvar($1); }
772 | OPAREN tautype COMMA
773 tautypes CPAREN { $$ = mkttuple(mklcons($2,$4)); }
775 | OUNBOXPAREN tautype COMMA
776 tautypes CUNBOXPAREN { $$ = mktutuple(mklcons($2,$4)); }
778 | OBRACK tautype CBRACK { $$ = mktllist($2); }
779 | OPAREN polytype CPAREN { $$ = $2; }
782 /* --------------------------- */
784 | OPAREN RARROW CPAREN { $$ = creategid(ARROWGID); }
785 | OBRACK CBRACK { $$ = creategid(NILGID); }
786 | OPAREN CPAREN { $$ = creategid(UNITGID); }
787 | OPAREN commas CPAREN { $$ = creategid($2); }
790 commas : COMMA { $$ = 1; }
791 | commas COMMA { $$ = $1 + 1; }
794 /**********************************************************************
797 * Declaration stuff *
800 **********************************************************************/
802 /* C a b c, where a,b,c are type variables */
803 /* C can be a class or tycon */
805 /* simple_con_app can have no args; simple_con_app1 must have at least one */
806 simple_con_app: gtycon { $$ = mktname($1); }
807 | simple_con_app1 { $$ = $1; }
810 simple_con_app1: gtycon tyvar { $$ = mktapp(mktname($1),mknamedtvar($2)); }
811 | simple_con_app1 tyvar { $$ = mktapp($1, mknamedtvar($2)); }
814 simple_context : OPAREN simple_context_list CPAREN { $$ = $2; }
815 | OPAREN CPAREN { $$ = Lnil; }
816 | simple_con_app1 { $$ = lsing($1); }
819 simple_context_list : simple_con_app1 { $$ = lsing($1); }
820 | simple_context_list COMMA simple_con_app1 { $$ = lapp($1,$3); }
823 constrs : constr { $$ = lsing($1); }
824 | constrs VBAR constr { $$ = lapp($1,$3); }
827 constr : forall constr_context DARROW constr_after_context { $$ = mkconstrex ( $1, $2, $4 ); }
828 | forall constr_after_context { $$ = mkconstrex ( $1, Lnil, $2 ); }
832 : conapptype conargatype { $$ = type2context( mktapp($1,$2) ); }
833 | conargatype { $$ = type2context( $1 ); }
836 constr_after_context :
838 /* We have to parse the constructor application as a *type*, else we get
839 into terrible ambiguity problems. Consider the difference between
841 data T = S Int Int Int `R` Int
843 data T = S Int Int Int
845 It isn't till we get to the operator that we discover that the "S" is
846 part of a type in the first, but part of a constructor application in the
850 /* Con !Int (Tree a) */
851 conapptype { qid tyc; list tys;
852 splittyconapp($1, &tyc, &tys);
853 $$ = mkconstrpre(tyc,tys,hsplineno); }
855 /* (::) (Tree a) Int */
856 | OPAREN qconsym CPAREN conargatypes { $$ = mkconstrpre($2,$4,hsplineno); }
858 /* !Int `Con` Tree a */
859 | conargatype qconop conargatype { $$ = mkconstrinf($1,$2,$3,hsplineno); }
861 /* Con { op1 :: Int } */
862 | qtycon OCURLY CCURLY { $$ = mkconstrrec($1,Lnil,hsplineno); }
863 | qtycon OCURLY fields CCURLY { $$ = mkconstrrec($1,$3,hsplineno); }
864 | OPAREN qconsym CPAREN OCURLY fields CCURLY { $$ = mkconstrrec($2,$5,hsplineno); }
866 /* 1 S/R conflict on OCURLY -> shift */
869 conapptype : gtycon { $$ = mktname($1); }
870 | conapptype conargatype { $$ = mktapp($1, $2); }
873 conargatype : polyatype { $$ = $1; }
874 | BANG polyatype { $$ = mktbang( $2 ); }
877 conargatypes : { $$ = Lnil; }
878 | conargatype conargatypes { $$ = mklcons($1,$2); }
881 fields : field { $$ = lsing($1); }
882 | fields COMMA field { $$ = lapp($1,$3); }
885 field : qvars_list DCOLON polytype { $$ = mkfield($1,$3); }
886 | qvars_list DCOLON BANG polyatype { $$ = mkfield($1,mktbang($4)); }
889 constr1 : gtycon conargatype { $$ = mkconstrnew($1,$2,mknothing(),hsplineno); }
890 | gtycon OCURLY qvar DCOLON polytype CCURLY { $$ = mkconstrnew($1,$5,mkjust($3),hsplineno); }
894 dtyclses: OPAREN dtycls_list CPAREN { $$ = $2; }
895 | OPAREN CPAREN { $$ = Lnil; }
896 | qtycls { $$ = lsing($1); }
899 dtycls_list: qtycls { $$ = lsing($1); }
900 | dtycls_list COMMA qtycls { $$ = lapp($1,$3); }
903 valdef : funlhs opt_sig { checksamefn($1); }
904 get_line_no valrhs { $$ = mkfbind( lsing(mkpmatch( lsing($1), $2, $5 )), $4); }
906 /* Special case for f :: type = e
907 We treat it as a special kind of pattern binding */
908 | qvark DCOLON tautype
909 get_line_no valrhs { $$ = mkpbind( mkrestr( mkident($1), $3 ), $5, $4 );
910 FN = NULL; SAMEFN = 0; }
913 get_line_no valrhs { $$ = mkpbind($1, $3, $2);
914 FN = NULL; SAMEFN = 0; }
916 get_line_no : { $$ = hsplineno; /* startlineno; */ }
918 /* This grammar still isn't quite right
921 you should get a function binding, but actually the (x+3) will
922 parse as a pattern, and you'll get a parse error. */
924 funlhs : patk qvarop cpat { $$ = mkinfixap($2,$1,$3); }
925 | funlhs1 apat { $$ = mkap( $1, $2 ); }
927 funlhs1 : oparenkey funlhs2 CPAREN { $$ = mkpar($2); }
928 | funlhs1 apat { $$ = mkap( $1, $2 ); }
929 | qvark { $$ = mkident($1); }
932 funlhs2 : cpat qvarop cpat { $$ = mkinfixap($2,$1,$3); }
933 | funlhs3 apat { $$ = mkap( $1, $2 ); }
935 funlhs3 : OPAREN funlhs2 CPAREN { $$ = mkpar($2); }
936 | funlhs3 apat { $$ = mkap( $1, $2 ); }
937 | qvar { $$ = mkident($1); }
940 opt_sig : { $$ = mknothing(); }
941 | DCOLON tautype { $$ = mkjust($2); }
944 /* opt_asig is the same, but with a parenthesised type */
945 opt_asig : { $$ = mknothing(); }
946 | DCOLON atype { $$ = mkjust($2); }
949 valrhs : EQUAL get_line_no exp maybe_where { $$ = mkpnoguards($2, $3, $4); }
950 | gdrhs maybe_where { $$ = mkpguards($1, $2); }
953 gdrhs : gd EQUAL get_line_no exp { $$ = lsing(mkpgdexp($1,$3,$4)); }
954 | gd EQUAL get_line_no exp gdrhs { $$ = mklcons(mkpgdexp($1,$3,$4),$5); }
957 maybe_where: /* empty */ { $$ = mknullbind(); }
958 | WHERE where_body { $$ = $2; }
959 | WHERE { $$ = mknullbind(); }
962 where_body : ocurly decls ccurly { $$ = $2; }
963 | vocurly non_empty_decls vccurly { $$ = $2; }
966 gd : VBAR quals { $$ = $2; }
970 /**********************************************************************
976 **********************************************************************/
978 exp : oexp DCOLON polytype { $$ = mkrestr($1,$3); }
983 Operators must be left-associative at the same precedence for
984 precedence parsing to work.
986 /* 10 S/R conflicts on qop -> shift */
987 oexp : oexp qop dexp %prec MINUS { $$ = mkinfixap($2,$1,$3); }
992 This comes here because of the funny precedence rules concerning
995 dexp : MINUS kexp { $$ = mknegate($2); }
1000 We need to factor out a leading let expression so we can set
1001 pat_check=FALSE when parsing (non let) expressions inside stmts and quals
1003 expLno : oexpLno DCOLON polytype { $$ = mkrestr($1,$3); }
1006 oexpLno : oexpLno qop oexp %prec MINUS { $$ = mkinfixap($2,$1,$3); }
1009 dexpLno : MINUS kexp { $$ = mknegate($2); }
1013 expL : oexpL DCOLON polytype { $$ = mkrestr($1,$3); }
1016 oexpL : oexpL qop oexp %prec MINUS { $$ = mkinfixap($2,$1,$3); }
1021 let/if/lambda/case have higher precedence than infix operators.
1028 /* kexpL = a let expression */
1029 kexpL : letdecls IN exp { $$ = mklet($1,$3); }
1032 /* kexpLno = any other expression more tightly binding than operator application */
1034 { hsincindent(); /* push new context for FN = NULL; */
1035 FN = NULL; /* not actually concerned about indenting */
1040 RARROW get_line_no exp /* lambda abstraction */
1041 { $$ = mklambda( mkpmatch( $3, $4, mkpnoguards( $7, $8, mknullbind() ) ) ); }
1044 | IF {$<ulong>$ = hsplineno;}
1045 exp THEN exp ELSE exp { $$ = mkife($3,$5,$7,$<ulong>2); }
1047 /* Case Expression */
1048 | CASE {$<ulong>$ = hsplineno;}
1049 exp OF caserest { $$ = mkcasee($3,$5,$<ulong>2); }
1052 | DO {$<ulong>$ = hsplineno;}
1053 dorest { $$ = mkdoe($3,$<ulong>2); }
1055 /* CCALL/CASM Expression */
1056 | CCALL ccallid aexps { $$ = mkccall($2,install_literal("n"),$3); }
1057 | CCALL_GC ccallid aexps { $$ = mkccall($2,install_literal("p"),$3); }
1058 | CASM CLITLIT aexps { $$ = mkccall($2,install_literal("N"),$3); }
1059 | CASM_GC CLITLIT aexps { $$ = mkccall($2,install_literal("P"),$3); }
1061 /* SCC Expression */
1066 "\"%s\":%d: _scc_ (`set [profiling] cost centre') ignored\n",
1067 input_filename, hsplineno);
1069 $$ = mkpar($3); /* Note the mkpar(). If we don't have it, then
1070 (x >> _scc_ y >> z) parses as (x >> (y >> z)),
1071 right associated. But the precedence reorganiser expects
1072 the parser to *left* associate all operators unless there
1073 are explicit parens. The _scc_ acts like an explicit paren,
1074 so if we omit it we'd better add explicit parens instead. */
1082 fexp : fexp aexp { $$ = mkap($1,$2); }
1086 /* simple expressions */
1087 aexp : qvar { $$ = mkident($1); }
1088 | gcon { $$ = mkident($1); }
1089 | lit_constant { $$ = mklit($1); }
1090 | OPAREN exp CPAREN { $$ = mkpar($2); } /* mkpar: stop infix parsing at ()'s */
1091 | qcon OCURLY rbinds CCURLY { $$ = mkrecord($1,$3); } /* 1 S/R conflict on OCURLY -> shift */
1092 | OBRACK list_exps CBRACK { $$ = mkllist($2); }
1093 | OPAREN exp COMMA texps CPAREN { $$ = mktuple(mklcons($2,$4)); }
1094 /* unboxed tuples */
1095 | OUNBOXPAREN texps CUNBOXPAREN { $$ = mkutuple($2); }
1097 /* only in expressions ... */
1098 | aexp OCURLY rbinds1 CCURLY { $$ = mkrupdate($1,$3); }
1099 | OBRACK exp VBAR quals CBRACK { $$ = mkcomprh($2,$4); }
1100 | OBRACK exp COMMA exp DOTDOT exp CBRACK {$$= mkeenum($2,mkjust($4),mkjust($6)); }
1101 | OBRACK exp COMMA exp DOTDOT CBRACK { $$ = mkeenum($2,mkjust($4),mknothing()); }
1102 | OBRACK exp DOTDOT exp CBRACK { $$ = mkeenum($2,mknothing(),mkjust($4)); }
1103 | OBRACK exp DOTDOT CBRACK { $$ = mkeenum($2,mknothing(),mknothing()); }
1104 | OPAREN oexp qop CPAREN { $$ = mklsection($2,$3); }
1105 | OPAREN qop1 oexp CPAREN { $$ = mkrsection($2,$3); }
1107 /* only in patterns ... */
1108 /* these add 2 S/R conflict with with aexp . OCURLY rbinds CCURLY */
1109 | qvar AT aexp { checkinpat(); $$ = mkas($1,$3); }
1110 | LAZY aexp { checkinpat(); $$ = mklazyp($2); }
1113 /* ccall arguments */
1114 aexps : aexps aexp { $$ = lapp($1,$2); }
1115 | /* empty */ { $$ = Lnil; }
1118 caserest: ocurly alts ccurly { $$ = $2; }
1119 | vocurly alts vccurly { $$ = $2; }
1121 dorest : ocurly stmts ccurly { checkdostmts($2); $$ = $2; }
1122 | vocurly stmts vccurly { checkdostmts($2); $$ = $2; }
1125 rbinds : /* empty */ { $$ = Lnil; }
1129 rbinds1 : rbind { $$ = lsing($1); }
1130 | rbinds1 COMMA rbind { $$ = lapp($1,$3); }
1133 rbind : qvar { punningNowIllegal(); }
1134 | qvar EQUAL exp { $$ = mkrbind($1,mkjust($3)); }
1137 texps : exp { $$ = lsing($1); }
1138 | exp COMMA texps { $$ = mklcons($1, $3) }
1139 /* right recursion? WDP */
1143 exp { $$ = lsing($1); }
1144 | exp COMMA exp { $$ = mklcons( $1, lsing($3) ); }
1145 | exp COMMA exp COMMA list_rest { $$ = mklcons( $1, mklcons( $3, reverse_list( $5 ))); }
1148 /* Use left recusion for list_rest, because we sometimes get programs with
1149 very long explicit lists. */
1150 list_rest : exp { $$ = lsing($1); }
1151 | list_rest COMMA exp { $$ = mklcons( $3, $1 ); }
1155 exp { $$ = lsing($1); }
1156 | exp COMMA list_exps { $$ = mklcons($1, $3); }
1158 /* right recursion? (WDP)
1160 It has to be this way, though, otherwise you
1161 may do the wrong thing to distinguish between...
1163 [ e1 , e2 .. ] -- an enumeration ...
1164 [ e1 , e2 , e3 ] -- a list
1166 (In fact, if you change the grammar and throw yacc/bison
1167 at it, it *will* do the wrong thing [WDP 94/06])
1170 letdecls: LET { pat_check = TRUE; } ocurly decls ccurly { $$ = $4; }
1171 | LET { pat_check = TRUE; } vocurly decls vccurly { $$ = $4; }
1175 When parsing patterns inside do stmt blocks or quals, we have
1176 to tentatively parse them as expressions, since we don't know at
1177 the time of parsing `p' whether it will be part of "p <- e" (pat)
1178 or "p" (expr). When we eventually can tell the difference, the parse
1179 of `p' is examined to see if it consitutes a syntactically legal pattern
1182 The expr rule used to parse the pattern/expression do contain
1183 pattern-special productions (e.g., _ , a@pat, etc.), which are
1184 illegal in expressions. Since we don't know whether what
1185 we're parsing is an expression rather than a pattern, we turn off
1186 the check and instead do it later.
1188 The rather clumsy way that this check is turned on/off is there
1189 to work around a Bison feature/shortcoming. Turning the flag
1190 on/off just around the relevant nonterminal by decorating it
1191 with simple semantic actions, e.g.,
1193 {pat_check = FALSE; } expLNo { pat_check = TRUE; }
1195 causes Bison to generate a parser where in one state it either
1196 has to reduce/perform a semantic action ( { pat_check = FALSE; })
1197 or reduce an error (the error production used to implement
1198 vccurly.) Bison picks the semantic action, which it ideally shouldn't.
1199 The work around is to lift out the setting of { pat_check = FALSE; }
1200 and then later reset pat_check. Not pretty.
1205 quals : { pat_check = FALSE;} qual { pat_check = TRUE; $$ = lsing($2); }
1206 | quals COMMA { pat_check = FALSE; } qual { pat_check = TRUE; $$ = lapp($1,$4); }
1209 qual : letdecls { $$ = mkseqlet($1); }
1210 | expL { expORpat(LEGIT_EXPR,$1); $$ = $1; }
1211 | expLno { pat_check = TRUE; } leftexp
1213 expORpat(LEGIT_EXPR,$1);
1216 expORpat(LEGIT_PATT,$1);
1222 alts : /* empty */ { $$ = Lnil; }
1223 | alt { $$ = lsing($1); }
1224 | alt SEMI alts { $$ = mklcons($1,$3); }
1225 | SEMI alts { $$ = $2; }
1228 alt : dpat opt_sig altrhs { $$ = mkpmatch( lsing($1), $2, $3 ); }
1231 altrhs : RARROW get_line_no exp maybe_where { $$ = mkpnoguards($2, $3, $4); }
1232 | gdpat maybe_where { $$ = mkpguards($1, $2); }
1235 gdpat : gd RARROW get_line_no exp { $$ = lsing(mkpgdexp($1,$3,$4)); }
1236 | gd RARROW get_line_no exp gdpat { $$ = mklcons(mkpgdexp($1,$3,$4),$5); }
1239 stmts : {pat_check = FALSE;} stmt {pat_check=TRUE; $$ = $2; }
1240 | stmts SEMI {pat_check=FALSE;} stmt {pat_check=TRUE; $$ = lconc($1,$4); }
1243 stmt : /* empty */ { $$ = Lnil; }
1244 | letdecls { $$ = lsing(mkseqlet($1)); }
1245 | expL { expORpat(LEGIT_EXPR,$1); $$ = lsing(mkdoexp($1,hsplineno)); }
1246 | expLno {pat_check=TRUE;} leftexp
1248 expORpat(LEGIT_EXPR,$1);
1249 $$ = lsing(mkdoexp($1,endlineno));
1251 expORpat(LEGIT_PATT,$1);
1252 $$ = lsing(mkdobind($1,$3,endlineno));
1258 leftexp : LARROW exp { $$ = $2; }
1259 | /* empty */ { $$ = NULL; }
1262 /**********************************************************************
1268 **********************************************************************/
1270 pat : dpat DCOLON tautype { $$ = mkrestr($1,$3); }
1274 dpat : qvar PLUS INTEGER { $$ = mkplusp($1, mkinteger($3)); }
1278 cpat : cpat qconop bpat { $$ = mkinfixap($2,$1,$3); }
1284 | qcon OCURLY rpats CCURLY { $$ = mkrecord($1,$3); }
1285 | MINUS INTEGER { $$ = mknegate(mklit(mkinteger($2))); }
1286 | MINUS FLOAT { $$ = mknegate(mklit(mkfloatr($2))); }
1289 conpat : gcon { $$ = mkident($1); }
1290 | conpat apat { $$ = mkap($1,$2); }
1293 apat : gcon { $$ = mkident($1); }
1294 | qcon OCURLY rpats CCURLY { $$ = mkrecord($1,$3); }
1298 apatc : qvar { $$ = mkident($1); }
1299 | qvar AT apat { $$ = mkas($1,$3); }
1300 | lit_constant { $$ = mklit($1); }
1301 | OPAREN pat CPAREN { $$ = mkpar($2); }
1302 | OPAREN pat COMMA pats CPAREN { $$ = mktuple(mklcons($2,$4)); }
1303 | OUNBOXPAREN pats CUNBOXPAREN { $$ = mkutuple($2); }
1304 | OBRACK pats CBRACK { $$ = mkllist($2); }
1305 | LAZY apat { $$ = mklazyp($2); }
1309 INTEGER { $$ = mkinteger($1); }
1310 | FLOAT { $$ = mkfloatr($1); }
1311 | CHAR { $$ = mkcharr($1); }
1312 | STRING { $$ = mkstring($1); }
1313 | CHARPRIM { $$ = mkcharprim($1); }
1314 | STRINGPRIM { $$ = mkstringprim($1); }
1315 | INTPRIM { $$ = mkintprim($1); }
1316 | FLOATPRIM { $$ = mkfloatprim($1); }
1317 | DOUBLEPRIM { $$ = mkdoubleprim($1); }
1318 | CLITLIT /* yurble yurble */ { $$ = mkclitlit($1); }
1321 /* Sequence of apats for a lambda abstraction */
1322 lampats : apat lampats { $$ = mklcons($1,$2); }
1323 | apat { $$ = lsing($1); }
1324 /* right recursion? (WDP) */
1327 /* Comma-separated sequence of pats */
1328 pats : pat COMMA pats { $$ = mklcons($1, $3); }
1329 | pat { $$ = lsing($1); }
1330 /* right recursion? (WDP) */
1333 /* Comma separated sequence of record patterns, each of form 'field=pat' */
1334 rpats : /* empty */ { $$ = Lnil; }
1338 rpats1 : rpat { $$ = lsing($1); }
1339 | rpats1 COMMA rpat { $$ = lapp($1,$3); }
1342 rpat : qvar { punningNowIllegal(); }
1343 | qvar EQUAL pat { $$ = mkrbind($1,mkjust($3)); }
1347 /* I can't figure out just what these ...k patterns are for.
1348 It seems to have something to do with recording the line number */
1350 /* Corresponds to a cpat */
1351 patk : patk qconop bpat { $$ = mkinfixap($2,$1,$3); }
1357 | qconk OCURLY rpats CCURLY { $$ = mkrecord($1,$3); }
1358 | minuskey INTEGER { $$ = mknegate(mklit(mkinteger($2))); }
1359 | minuskey FLOAT { $$ = mknegate(mklit(mkfloatr($2))); }
1362 conpatk : gconk { $$ = mkident($1); }
1363 | conpatk apat { $$ = mkap($1,$2); }
1366 apatck : qvark { $$ = mkident($1); }
1367 | qvark AT apat { $$ = mkas($1,$3); }
1368 | lit_constant { $$ = mklit($1); setstartlineno(); }
1369 | oparenkey pat CPAREN { $$ = mkpar($2); }
1370 | oparenkey pat COMMA pats CPAREN { $$ = mktuple(mklcons($2,$4)); }
1371 | ounboxparenkey pat COMMA pats CUNBOXPAREN
1372 { $$ = mkutuple(mklcons($2,$4)); }
1373 | obrackkey pats CBRACK { $$ = mkllist($2); }
1374 | lazykey apat { $$ = mklazyp($2); }
1379 | OBRACK CBRACK { $$ = creategid(NILGID); }
1380 | OPAREN CPAREN { $$ = creategid(UNITGID); }
1381 | OPAREN commas CPAREN { $$ = creategid($2); }
1385 | obrackkey CBRACK { $$ = creategid(NILGID); }
1386 | oparenkey CPAREN { $$ = creategid(UNITGID); }
1387 | oparenkey commas CPAREN { $$ = creategid($2); }
1390 /**********************************************************************
1393 * Keywords which record the line start *
1396 **********************************************************************/
1398 importkey: IMPORT { setstartlineno(); $$ = 0; }
1399 | IMPORT SOURCE_UPRAGMA { setstartlineno(); $$ = 1; }
1402 datakey : DATA { setstartlineno();
1405 printf("%u\n",startlineno);
1407 fprintf(stderr,"%u\tdata\n",startlineno);
1412 typekey : TYPE { setstartlineno();
1415 printf("%u\n",startlineno);
1417 fprintf(stderr,"%u\ttype\n",startlineno);
1422 newtypekey : NEWTYPE { setstartlineno();
1425 printf("%u\n",startlineno);
1427 fprintf(stderr,"%u\tnewtype\n",startlineno);
1432 instkey : INSTANCE { setstartlineno();
1435 printf("%u\n",startlineno);
1438 fprintf(stderr,"%u\tinstance\n",startlineno);
1443 defaultkey: DEFAULT { setstartlineno(); }
1446 foreignkey: FOREIGN { setstartlineno(); }
1449 classkey: CLASS { setstartlineno();
1452 printf("%u\n",startlineno);
1454 fprintf(stderr,"%u\tclass\n",startlineno);
1459 modulekey: MODULE { setstartlineno();
1462 printf("%u\n",startlineno);
1464 fprintf(stderr,"%u\tmodule\n",startlineno);
1469 oparenkey: OPAREN { setstartlineno(); }
1472 ounboxparenkey: OUNBOXPAREN { setstartlineno(); }
1475 obrackkey: OBRACK { setstartlineno(); }
1478 lazykey : LAZY { setstartlineno(); }
1481 minuskey: MINUS { setstartlineno(); }
1485 /**********************************************************************
1488 * Basic qualified/unqualified ids/ops *
1491 **********************************************************************/
1494 | OPAREN qvarsym CPAREN { $$ = $2; }
1497 | OPAREN qconsym CPAREN { $$ = $2; }
1500 | BQUOTE qvarid BQUOTE { $$ = $2; }
1503 | BQUOTE qconid BQUOTE { $$ = $2; }
1509 /* Non "-" op, used in right sections */
1514 /* Non "-" varop, used in right sections */
1516 | varsym_nominus { $$ = mknoqual($1); }
1517 | BQUOTE qvarid BQUOTE { $$ = $2; }
1522 | OPAREN varsym CPAREN { $$ = $2; }
1524 con : tycon /* using tycon removes conflicts */
1525 | OPAREN CONSYM CPAREN { $$ = $2; }
1528 | BQUOTE varid BQUOTE { $$ = $2; }
1531 | BQUOTE CONID BQUOTE { $$ = $2; }
1537 qvark : qvarid { setstartlineno(); $$ = $1; }
1538 | oparenkey qvarsym CPAREN { $$ = $2; }
1540 qconk : qconid { setstartlineno(); $$ = $1; }
1541 | oparenkey qconsym CPAREN { $$ = $2; }
1543 vark : varid { setstartlineno(); $$ = $1; }
1544 | oparenkey varsym CPAREN { $$ = $2; }
1548 | varid { $$ = mknoqual($1); }
1551 | varsym { $$ = mknoqual($1); }
1554 | tycon { $$ = mknoqual($1); } /* using tycon removes conflicts */
1557 | CONSYM { $$ = mknoqual($1); }
1560 | tycon { $$ = mknoqual($1); } /* using tycon removes conflicts */
1563 | tycon { $$ = mknoqual($1); } /* using tycon removes conflicts */
1566 varsym : varsym_nominus
1567 | MINUS { $$ = install_literal("-"); }
1570 /* PLUS, BANG are valid varsyms */
1571 varsym_nominus : VARSYM
1572 | PLUS { $$ = install_literal("+"); }
1573 | BANG { $$ = install_literal("!"); }
1574 | DOT { $$ = install_literal("."); }
1577 /* AS HIDING QUALIFIED are valid varids */
1578 varid : varid_noforall
1579 | FORALL { $$ = install_literal("forall"); }
1584 | AS { $$ = install_literal("as"); }
1585 | HIDING { $$ = install_literal("hiding"); }
1586 | QUALIFIED { $$ = install_literal("qualified"); }
1587 /* The rest of these guys are used by the FFI decls, a ghc (and hugs) extension. */
1588 | EXPORT { $$ = install_literal("export"); }
1589 | UNSAFE { $$ = install_literal("unsafe"); }
1590 | DYNAMIC { $$ = install_literal("dynamic"); }
1591 | LABEL { $$ = install_literal("label"); }
1592 | C_CALL { $$ = install_literal("ccall"); }
1593 | STDCALL { $$ = install_literal("stdcall"); }
1594 | PASCAL { $$ = install_literal("pascal"); }
1606 /* ---------------------------------------------- */
1607 tyvar : varid_noforall { $$ = $1; }
1610 /* var_list: At least one var; used mainly for tyvars */
1611 var_list : varid_noforall { $$ = lsing($1); }
1612 | varid_noforall var_list { $$ = mklcons($1,$2); }
1615 forall : /* Empty */ { $$ = Lnil }
1616 | FORALL var_list DOT { $$ = $2; }
1620 /**********************************************************************
1623 * Stuff to do with layout *
1626 **********************************************************************/
1628 ocurly : layout OCURLY { hsincindent(); }
1630 vocurly : layout { hssetindent(); }
1633 layout : { hsindentoff(); }
1639 FN = NULL; SAMEFN = 0;
1644 vccurly : { expect_ccurly = 1; } vccurly1 { expect_ccurly = 0; }
1650 FN = NULL; SAMEFN = 0;
1656 FN = NULL; SAMEFN = 0;
1663 /**********************************************************************
1665 * Error Processing and Reporting *
1667 * (This stuff is here in case we want to use Yacc macros and such.) *
1669 **********************************************************************/
1672 static void checkinpat()
1675 hsperror("pattern syntax used in expression");
1678 static void punningNowIllegal()
1680 hsperror("Haskell 98 does not support 'punning' on records");
1684 /* The parser calls "hsperror" when it sees a
1685 `report this and die' error. It sets the stage
1686 and calls "yyerror".
1688 There should be no direct calls in the parser to
1689 "yyerror", except for the one from "hsperror". Thus,
1690 the only other calls will be from the error productions
1691 introduced by yacc/bison/whatever.
1693 We need to be able to recognise the from-error-production
1694 case, because we sometimes want to say, "Oh, never mind",
1695 because the layout rule kicks into action and may save
1699 static BOOLEAN error_and_I_mean_it = FALSE;
1705 error_and_I_mean_it = TRUE;
1709 extern char *yytext;
1716 /* We want to be able to distinguish 'error'-raised yyerrors
1717 from yyerrors explicitly coded by the parser hacker.
1719 if ( expect_ccurly && ! error_and_I_mean_it ) {
1723 fprintf(stderr, "%s:%d:%d: %s on input: ",
1724 input_filename, hsplineno, hspcolno + 1, s);
1726 if (yyleng == 1 && *yytext == '\0')
1727 fprintf(stderr, "<EOF>");
1731 format_string(stderr, (unsigned char *) yytext, yyleng);
1734 fputc('\n', stderr);
1736 /* a common problem */
1737 if (strcmp(yytext, "#") == 0)
1738 fprintf(stderr, "\t(Perhaps you forgot a `-cpp' or `-fglasgow-exts' flag?)\n");
1745 format_string(fp, s, len)
1752 case '\0': fputs("\\NUL", fp); break;
1753 case '\007': fputs("\\a", fp); break;
1754 case '\010': fputs("\\b", fp); break;
1755 case '\011': fputs("\\t", fp); break;
1756 case '\012': fputs("\\n", fp); break;
1757 case '\013': fputs("\\v", fp); break;
1758 case '\014': fputs("\\f", fp); break;
1759 case '\015': fputs("\\r", fp); break;
1760 case '\033': fputs("\\ESC", fp); break;
1761 case '\034': fputs("\\FS", fp); break;
1762 case '\035': fputs("\\GS", fp); break;
1763 case '\036': fputs("\\RS", fp); break;
1764 case '\037': fputs("\\US", fp); break;
1765 case '\177': fputs("\\DEL", fp); break;
1770 fprintf(fp, "\\^%c", *s + '@');