2 /* --------------------------------------------------------------------------
3 * Hugs parser (included as part of input.c)
5 * Expect 6 shift/reduce conflicts when passing this grammar through yacc,
6 * but don't worry; they should all be resolved in an appropriate manner.
8 * Hugs 98 is Copyright (c) Mark P Jones, Alastair Reid and the Yale
9 * Haskell Group 1994-99, and is distributed as Open Source software
10 * under the Artistic License; see the file "Artistic" that is included
11 * in the distribution for details.
13 * $RCSfile: parser.y,v $
15 * $Date: 1999/10/15 11:02:20 $
16 * ------------------------------------------------------------------------*/
22 #define defTycon(n,l,lhs,rhs,w) tyconDefn(intOf(l),lhs,rhs,w); sp-=n
23 #define sigdecl(l,vs,t) ap(SIGDECL,triple(l,vs,t))
24 #define fixdecl(l,ops,a,p) ap(FIXDECL,\
25 triple(l,ops,mkInt(mkSyntax(a,intOf(p)))))
26 #define grded(gs) ap(GUARDED,gs)
27 #define bang(t) ap(BANG,t)
28 #define only(t) ap(ONLY,t)
29 #define letrec(bs,e) (nonNull(bs) ? ap(LETREC,pair(bs,e)) : e)
30 #define qualify(ps,t) (nonNull(ps) ? ap(QUAL,pair(ps,t)) : t)
31 #define exportSelf() singleton(ap(MODULEENT, \
32 mkCon(module(currentModule).text)))
33 #define yyerror(s) /* errors handled elsewhere */
36 static Cell local gcShadow Args((Int,Cell));
37 static Void local syntaxError Args((String));
38 static String local unexpected Args((Void));
39 static Cell local checkPrec Args((Cell));
40 static Void local fixDefn Args((Syntax,Cell,Cell,List));
41 static Cell local buildTuple Args((List));
42 static List local checkContext Args((List));
43 static Cell local checkPred Args((Cell));
44 static Pair local checkDo Args((List));
45 static Cell local checkTyLhs Args((Cell));
47 static Void local noTREX Args((String));
50 /* For the purposes of reasonably portable garbage collection, it is
51 * necessary to simulate the YACC stack on the Hugs stack to keep
52 * track of all intermediate constructs. The lexical analyser
53 * pushes a token onto the stack for each token that is found, with
54 * these elements being removed as reduce actions are performed,
55 * taking account of look-ahead tokens as described by gcShadow()
58 * Of the non-terminals used below, only start, topDecl & begin
59 * do not leave any values on the Hugs stack. The same is true for the
60 * terminals EXPR and SCRIPT. At the end of a successful parse, there
61 * should only be one element left on the stack, containing the result
65 #define gc0(e) gcShadow(0,e)
66 #define gc1(e) gcShadow(1,e)
67 #define gc2(e) gcShadow(2,e)
68 #define gc3(e) gcShadow(3,e)
69 #define gc4(e) gcShadow(4,e)
70 #define gc5(e) gcShadow(5,e)
71 #define gc6(e) gcShadow(6,e)
72 #define gc7(e) gcShadow(7,e)
77 %token CASEXP OF DATA TYPE IF
78 %token THEN ELSE WHERE LET IN
79 %token INFIXN INFIXL INFIXR FOREIGN TNEWTYPE
80 %token DEFAULT DERIVING DO TCLASS TINSTANCE
81 %token REPEAT ALL NUMLIT CHARLIT STRINGLIT
82 %token VAROP VARID CONOP CONID
83 %token QVAROP QVARID QCONOP QCONID
87 %token COCO '=' UPTO '@' '\\'
88 %token '|' '-' FROM ARROW '~'
89 %token '!' IMPLIES '(' ',' ')'
90 %token '[' ';' ']' '`' '.'
91 %token TMODULE IMPORT HIDING QUALIFIED ASMOD
92 %token EXPORT UUEXPORT INTERFACE REQUIRES UNSAFE
93 %token INSTIMPORT DYNAMIC
96 /*- Top level script/module structure -------------------------------------*/
98 start : EXPR exp wherePart {inputExpr = letrec($3,$2); sp-=2;}
99 | SCRIPT topModule {valDefns = $2; sp-=1;}
100 | INTERFACE iface {sp-=1;}
101 | error {syntaxError("input");}
105 /*- GHC interface file parsing: -------------------------------------------*/
107 /* Reading in an interface file is surprisingly like reading
108 * a normal Haskell module: we read in a bunch of declarations,
109 * construct symbol table entries, etc. The "only" differences
110 * are that there's no syntactic sugar to deal with and we don't
111 * have to read in expressions.
114 /*- Top-level interface files -----------------------------*/
115 iface : INTERFACE ifName NUMLIT checkVersion WHERE ifDecls
117 | INTERFACE error {syntaxError("interface file");}
119 ifDecls: {$$=gc0(NIL);}
120 | ifDecl ';' ifDecls {$$=gc3(cons($1,$3));}
123 : VARID { $$=gc1($1); }
124 | CONID { $$=gc1($1); }
126 opt_bang : '!' {$$=gc1(NIL);}
129 ifName : CONID {openGHCIface(textOf($1));
132 : NUMLIT {$$ = gc1(NIL); }
135 : IMPORT CONID opt_bang NUMLIT COCO version_list_junk
136 { addGHCImports(intOf($4),textOf($2),
141 | INSTIMPORT CONID {$$=gc2(NIL);}
143 | UUEXPORT CONID ifEntities { addGHCExports($2,$3);
146 | NUMLIT INFIXL optDigit varid_or_conid
147 {$$ = gc4(fixdecl($2,singleton($4),
149 | NUMLIT INFIXR optDigit varid_or_conid
150 {$$ = gc4(fixdecl($2,singleton($4),
152 | NUMLIT INFIXN optDigit varid_or_conid
153 {$$ = gc4(fixdecl($2,singleton($4),
156 | TINSTANCE ifCtxInst ifInstHd '=' ifVar
157 { addGHCInstance(intOf($1),$2,$3,
160 | NUMLIT TYPE ifCon ifKindedTyvarL '=' ifType
161 { addGHCSynonym(intOf($2),$3,$4,$6);
164 | NUMLIT DATA ifCtxDecl ifConData ifKindedTyvarL ifConstrs
165 { addGHCDataDecl(intOf($2),
169 | NUMLIT TNEWTYPE ifCtxDecl ifConData ifKindedTyvarL ifNewTypeConstr
170 { addGHCNewType(intOf($2),
173 | NUMLIT TCLASS ifCtxDecl ifCon ifTyvar ifCmeths
174 { addGHCClass(intOf($2),$3,$4,$5,$6);
176 | NUMLIT ifVar COCO ifType
177 { addGHCVar(intOf($3),textOf($2),$4);
179 | error { syntaxError(
180 "interface declaration"); }
184 /*- Interface variable and constructor ids ----------------*/
185 ifTyvar : VARID {$$ = $1;}
187 ifVar : VARID {$$ = gc1($1);}
189 ifCon : CONID {$$ = gc1($1);}
191 ifQCon : CONID {$$ = gc1($1);}
192 | QCONID {$$ = gc1($1);}
194 ifConData : ifCon {$$ = gc1($1);}
195 | '(' ')' {$$ = gc2(typeUnit);}
196 | '[' ']' {$$ = gc2(typeList);}
197 | '(' ARROW ')' {$$ = gc3(typeArrow);}
199 ifTCName : CONID { $$ = gc1($1); }
200 | CONOP { $$ = gc1($1); }
201 | '(' ARROW ')' { $$ = gc3(typeArrow); }
202 | '[' ']' { $$ = gc1(typeList); }
204 ifQTCName : ifTCName { $$ = gc1($1); }
205 | QCONID { $$ = gc1($1); }
206 | QCONOP { $$ = gc1($1); }
210 /*- Interface contexts ------------------------------------*/
211 ifCtxInst /* __forall [a b] {M.C1 a, M.C2 b} => */
212 /* :: [(QConId, VarId)] */
213 : ALL ifForall ifCtxDecl {$$=gc3($3);}
214 | ALL ifForall IMPLIES {$$=gc3(NIL);}
217 ifInstHd /* { Class aType } :: (ConId, Type) */
218 : '{' ifCon ifAType '}' {$$=gc4(pair($2,$3));}
221 ifCtxDecl /* {M.C1 a, C2 b} :: [(QConId, VarId)] */
223 | '{' ifCtxDeclL '}' IMPLIES { $$ = gc4($2); }
225 ifCtxDeclT /* {M.C1 a, C2 b} :: [(QConId, VarId)] */
227 | '{' ifCtxDeclL '}' { $$ = gc3($2); }
229 ifCtxDeclL /* M.C1 a, C2 b :: [(QConId, VarId)] */
230 : ifCtxDeclLE ',' ifCtxDeclL {$$=gc3(cons($1,$3));}
231 | ifCtxDeclLE {$$=gc1(cons($1,NIL));}
234 ifCtxDeclLE /* M.C1 a :: (QConId,VarId) */
235 : ifQCon ifTyvar {$$=gc2(pair($1,$2));}
239 /*- Interface data declarations - constructor lists -------*/
240 ifConstrs /* = Con1 | ... | ConN :: [(ConId,[(Type,Text)],NIL)] */
242 | '=' ifConstrL {$$ = gc2($2);}
244 ifConstrL /* [(ConId,[(Type,Text)],NIL)] */
245 : ifConstr {$$ = gc1(singleton($1));}
246 | ifConstr '|' ifConstrL {$$ = gc3(cons($1,$3));}
248 ifConstr /* (ConId,[(Type,Text)],NIL) */
249 : ifConData ifDataAnonFieldL {$$ = gc2(triple($1,$2,NIL));}
250 | ifConData '{' ifDataNamedFieldL '}'
251 {$$ = gc4(triple($1,$3,NIL));}
253 ifDataAnonFieldL /* [(Type,Text)] */
255 | ifDataAnonField ifDataAnonFieldL
256 {$$=gc2(cons($1,$2));}
258 ifDataNamedFieldL /* [(Type,Text)] */
260 | ifDataNamedField {$$=gc1(cons($1,NIL));}
261 | ifDataNamedField ',' ifDataNamedFieldL
262 {$$=gc3(cons($1,$3));}
264 ifDataAnonField /* (Type,Text) */
265 : ifAType {$$=gc1(pair($1,NIL));}
267 ifDataNamedField /* (Type,Text) */
268 : VARID COCO ifAType {$$=gc3(pair($3,$1));}
272 /*- Interface class declarations - methods ----------------*/
273 ifCmeths /* [(VarId,Type)] */
275 | WHERE '{' ifCmethL '}' { $$ = gc4($3); }
277 ifCmethL /* [(VarId,Type)] */
278 : ifCmeth { $$ = gc1(singleton($1)); }
279 | ifCmeth ';' ifCmethL { $$ = gc3(cons($1,$3)); }
281 ifCmeth /* (VarId,Type) */
282 : ifVar COCO ifType { $$ = gc3(pair($1,$3)); }
283 | ifVar '=' COCO ifType { $$ = gc4(pair($1,$4)); }
284 /* has default method */
288 /*- Interface newtype declararions ------------------------*/
289 ifNewTypeConstr /* (ConId,Type) */
290 : '=' ifCon ifAType { $$ = gc3(pair($2,$3)); }
294 /*- Interface type expressions ----------------------------*/
295 ifType : ALL ifForall ifCtxDeclT IMPLIES ifType
298 $$=gc5(pair(QUAL,pair($3,$5)));
300 | ifBType ARROW ifType { $$ = gc3(fn($1,$3)); }
301 | ifBType { $$ = gc1($1); }
303 ifForall /* [(VarId,Kind)] */
304 : '[' ifKindedTyvarL ']' { $$ = gc3($2); }
306 ifTypes2 : ifType ',' ifType { $$ = gc3(doubleton($1,$3)); }
307 | ifType ',' ifTypes2 { $$ = gc3(cons($1,$3)); }
309 ifBType : ifAType { $$ = gc1($1); }
310 | ifBType ifAType { $$ = gc2(ap($1,$2)); }
312 ifAType : ifQTCName { $$ = gc1($1); }
313 | ifTyvar { $$ = gc1($1); }
314 | '(' ')' { $$ = gc2(typeUnit); }
315 | '(' ifTypes2 ')' { $$ = gc3(buildTuple($2)); }
316 | '[' ifType ']' { $$ = gc3(ap(typeList,$2));}
317 | '{' ifQTCName ifATypes '}' { $$ = gc4(ap(DICTAP,
319 | '(' ifType ')' { $$ = gc3($2); }
321 ifATypes : { $$ = gc0(NIL); }
322 | ifAType ifATypes { $$ = gc2(cons($1,$2)); }
326 /*- Interface kinds ---------------------------------------*/
327 ifKindedTyvarL /* [(VarId,Kind)] */
329 | ifKindedTyvar ifKindedTyvarL { $$ = gc2(cons($1,$2)); }
331 ifKindedTyvar /* (VarId,Kind) */
332 : ifTyvar { $$ = gc1(pair($1,STAR)); }
333 | ifTyvar COCO ifAKind { $$ = gc3(pair($1,$3)); }
335 ifKind : ifAKind { $$ = gc1($1); }
336 | ifAKind ARROW ifKind { $$ = gc3(fn($1,$3)); }
338 ifAKind : VAROP { $$ = gc1(STAR); }
340 | '(' ifKind ')' { $$ = gc3($2); }
344 /*- Interface version/export/import stuff -----------------*/
347 | ifEntity ifEntities { $$ = gc2(cons($1,$2)); }
350 : ifEntityOcc {$$=gc1($1);}
351 | ifEntityOcc ifStuffInside {$$=gc2(pair($1,$2));}
354 : ifVar { $$ = gc1($1); }
355 | ifCon { $$ = gc1($1); }
356 | ARROW { $$ = gc1(typeArrow); }
357 | '(' ARROW ')' { $$ = gc3(typeArrow); }
358 /* why allow both? */
361 : '{' ifValOccs '}' { $$ = gc3($2); }
365 | ifVar ifValOccs { $$ = gc2(cons($1,$2)); }
366 | ifCon ifValOccs { $$ = gc2(cons($1,$2)); }
370 | VARID NUMLIT version_list_junk {$$=gc3(cons($1,$3));}
371 | CONID NUMLIT version_list_junk {$$=gc3(cons($1,$3));}
375 /*- Haskell module header/import parsing: -----------------------------------
377 * Syntax for Haskell modules (module headers and imports) is parsed but
378 * most of it is ignored. However, module names in import declarations
379 * are used, of course, if import chasing is turned on.
380 *-------------------------------------------------------------------------*/
382 /* In Haskell 1.2, the default module header was "module Main where"
383 * In 1.3, this changed to "module Main(main) where".
384 * We use the 1.2 header because it breaks much less pre-module code.
386 topModule : startMain begin modBody end {
387 setExportList(singleton(
389 mkCon(module(currentModule).text)
393 | TMODULE modname expspec WHERE '{' modBody end
394 {setExportList($3); $$ = gc7($6);}
395 | TMODULE error {syntaxError("module definition");}
397 /* To implement the Haskell module system, we have to keep track of the
398 * current module. We rely on the use of LALR parsing to ensure that this
399 * side effect happens before any declarations within the module.
401 startMain : /* empty */ {startModule(conMain);
404 modname : CONID {startModule($1); $$ = gc1(NIL);}
406 modid : CONID {$$ = $1;}
407 | STRINGLIT { extern String scriptFile;
409 = findPathname(scriptFile,
410 textToStr(textOf($1)));
412 /* fillin pathname if known */
413 $$ = mkStr(findText(modName));
419 modBody : topDecls {$$ = $1;}
420 | impDecls chase {$$ = gc2(NIL);}
421 | impDecls ';' chase topDecls {$$ = gc4($4);}
424 /*- Exports: --------------------------------------------------------------*/
426 expspec : /* empty */ {$$ = gc0(exportSelf());}
427 | '(' ')' {$$ = gc2(NIL);}
428 | '(' exports ')' {$$ = gc3($2);}
429 | '(' exports ',' ')' {$$ = gc4($2);}
431 exports : exports ',' export {$$ = gc3(cons($3,$1));}
432 | export {$$ = gc1(singleton($1));}
434 /* The qcon should be qconid.
435 * Relaxing the rule lets us explicitly export (:) from the Prelude.
437 export : qvar {$$ = $1;}
439 | qconid '(' UPTO ')' {$$ = gc4(pair($1,DOTDOT));}
440 | qconid '(' qnames ')' {$$ = gc4(pair($1,$3));}
441 | TMODULE modid {$$ = gc2(ap(MODULEENT,$2));}
443 qnames : /* empty */ {$$ = gc0(NIL);}
444 | ',' {$$ = gc1(NIL);}
446 | qnames1 ',' {$$ = gc2($1);}
448 qnames1 : qnames1 ',' qname {$$ = gc3(cons($3,$1));}
449 | qname {$$ = gc1(singleton($1));}
451 qname : qvar {$$ = $1;}
455 /*- Import declarations: --------------------------------------------------*/
457 impDecls : impDecls ';' impDecl {imps = cons($3,imps); $$=gc3(NIL);}
458 | impDecl {imps = singleton($1); $$=gc1(NIL);}
460 chase : /* empty */ {if (chase(imps)) {
470 /* Note that qualified import ignores the import list. */
471 impDecl : IMPORT modid impspec {addQualImport($2,$2);
472 addUnqualImport($2,$3);
474 | IMPORT modid ASMOD modid impspec
475 {addQualImport($2,$4);
476 addUnqualImport($2,$5);
478 | IMPORT QUALIFIED modid ASMOD modid impspec
479 {addQualImport($3,$5);
481 | IMPORT QUALIFIED modid impspec
482 {addQualImport($3,$3);
484 | IMPORT error {syntaxError("import declaration");}
486 impspec : /* empty */ {$$ = gc0(DOTDOT);}
487 | HIDING '(' imports ')' {$$ = gc4(ap(HIDDEN,$3));}
488 | '(' imports ')' {$$ = gc3($2);}
490 imports : /* empty */ {$$ = gc0(NIL);}
491 | ',' {$$ = gc1(NIL);}
492 | imports1 {$$ = $1;}
493 | imports1 ',' {$$ = gc2($1);}
495 imports1 : imports1 ',' import {$$ = gc3(cons($3,$1));}
496 | import {$$ = gc1(singleton($1));}
498 import : var {$$ = $1;}
500 | CONID '(' UPTO ')' {$$ = gc4(pair($1,DOTDOT));}
501 | CONID '(' names ')' {$$ = gc4(pair($1,$3));}
503 names : /* empty */ {$$ = gc0(NIL);}
504 | ',' {$$ = gc1(NIL);}
506 | names1 ',' {$$ = gc2($1);}
508 names1 : names1 ',' name {$$ = gc3(cons($3,$1));}
509 | name {$$ = gc1(singleton($1));}
511 name : var {$$ = $1;}
515 /*- Top-level declarations: -----------------------------------------------*/
517 topDecls : /* empty */ {$$ = gc0(NIL);}
518 | ';' {$$ = gc1(NIL);}
519 | topDecls1 {$$ = $1;}
520 | topDecls1 ';' {$$ = gc2($1);}
522 topDecls1 : topDecls1 ';' topDecl {$$ = gc2($1);}
523 | topDecls1 ';' decl {$$ = gc3(cons($3,$1));}
524 | topDecl {$$ = gc0(NIL);}
525 | decl {$$ = gc1(cons($1,NIL));}
528 /*- Type declarations: ----------------------------------------------------*/
530 topDecl : TYPE tyLhs '=' type {defTycon(4,$3,$2,$4,SYNONYM);}
531 | TYPE tyLhs '=' type IN invars
533 ap($4,$6),RESTRICTSYN);}
534 | TYPE error {syntaxError("type definition");}
535 | DATA btype2 '=' constrs deriving
536 {defTycon(5,$3,checkTyLhs($2),
537 ap(rev($4),$5),DATATYPE);}
538 | DATA context IMPLIES tyLhs '=' constrs deriving
540 ap(qualify($2,rev($6)),
542 | DATA btype2 {defTycon(2,$1,checkTyLhs($2),
543 ap(NIL,NIL),DATATYPE);}
544 | DATA context IMPLIES tyLhs {defTycon(4,$1,$4,
547 | DATA error {syntaxError("data definition");}
548 | TNEWTYPE btype2 '=' nconstr deriving
549 {defTycon(5,$3,checkTyLhs($2),
551 | TNEWTYPE context IMPLIES tyLhs '=' nconstr deriving
555 | TNEWTYPE error {syntaxError("newtype definition");}
557 tyLhs : tyLhs varid {$$ = gc2(ap($1,$2));}
559 | error {syntaxError("type defn lhs");}
561 invars : invars ',' invar {$$ = gc3(cons($3,$1));}
562 | invar {$$ = gc1(cons($1,NIL));}
564 invar : var COCO topType {$$ = gc3(sigdecl($2,singleton($1),
568 constrs : constrs '|' pconstr {$$ = gc3(cons($3,$1));}
569 | pconstr {$$ = gc1(cons($1,NIL));}
571 pconstr : ALL varids '.' qconstr {$$ = gc4(ap(POLYTYPE,
575 qconstr : context IMPLIES constr {$$ = gc3(qualify($1,$3));}
578 constr : '!' btype conop bbtype {$$ = gc4(ap(ap($3,bang($2)),$4));}
579 | btype1 conop bbtype {$$ = gc3(ap(ap($2,$1),$3));}
580 | btype2 conop bbtype {$$ = gc3(ap(ap($2,$1),$3));}
581 | bpolyType conop bbtype {$$ = gc3(ap(ap($2,$1),$3));}
585 | con '{' fieldspecs '}' {$$ = gc4(ap(LABC,pair($1,rev($3))));}
586 | con '{' '}' {$$ = gc3(ap(LABC,pair($1,NIL)));}
587 | error {syntaxError("data type definition");}
589 btype3 : btype2 '!' atype {$$ = gc3(ap($1,bang($3)));}
590 | btype3 '!' atype {$$ = gc3(ap($1,bang($3)));}
591 | btype3 atype {$$ = gc2(ap($1,$2));}
593 btype4 : btype2 bpolyType {$$ = gc2(ap($1,$2));}
594 | btype3 bpolyType {$$ = gc2(ap($1,$2));}
595 | btype4 bpolyType {$$ = gc2(ap($1,$2));}
596 | btype4 atype {$$ = gc2(ap($1,$2));}
597 | btype4 '!' atype {$$ = gc3(ap($1,bang($3)));}
599 bbtype : '!' btype {$$ = gc2(bang($2));}
601 | bpolyType {$$ = $1;}
603 nconstr : pconstr {$$ = gc1(singleton($1));}
605 fieldspecs: fieldspecs ',' fieldspec {$$ = gc3(cons($3,$1));}
606 | fieldspec {$$ = gc1(cons($1,NIL));}
608 fieldspec : vars COCO polyType {$$ = gc3(pair(rev($1),$3));}
609 | vars COCO type {$$ = gc3(pair(rev($1),$3));}
610 | vars COCO '!' type {$$ = gc4(pair(rev($1),bang($4)));}
612 deriving : /* empty */ {$$ = gc0(NIL);}
613 | DERIVING qconid {$$ = gc2(singleton($2));}
614 | DERIVING '(' derivs0 ')' {$$ = gc4($3);}
616 derivs0 : /* empty */ {$$ = gc0(NIL);}
617 | derivs {$$ = gc1(rev($1));}
619 derivs : derivs ',' qconid {$$ = gc3(cons($3,$1));}
620 | qconid {$$ = gc1(singleton($1));}
623 /*- Processing definitions of primitives ----------------------------------*/
625 topDecl : FOREIGN IMPORT callconv ext_loc ext_name unsafe_flag var COCO type
626 {foreignImport($1,pair($4,$5),$7,$9); sp-=9;}
627 | FOREIGN EXPORT callconv DYNAMIC qvarid COCO type
628 {foreignExport($1,$4,$5,$7); sp-=7;}
631 callconv : var {$$ = gc1(NIL); /* ignored */ }
633 ext_loc : STRINGLIT {$$ = $1;}
635 ext_name : STRINGLIT {$$ = $1;}
637 unsafe_flag: /* empty */ {$$ = gc0(NIL);}
638 | UNSAFE {$$ = gc1(NIL); /* ignored */ }
642 /*- Class declarations: ---------------------------------------------------*/
644 topDecl : TCLASS crule wherePart {classDefn(intOf($1),$2,$3); sp-=3;}
645 | TINSTANCE irule wherePart {instDefn(intOf($1),$2,$3); sp-=3;}
646 | DEFAULT '(' dtypes ')' {defaultDefn(intOf($1),$3); sp-=4;}
647 | TCLASS error {syntaxError("class declaration");}
648 | TINSTANCE error {syntaxError("instance declaration");}
649 | DEFAULT error {syntaxError("default declaration");}
651 crule : context IMPLIES btype2 {$$ = gc3(pair($1,checkPred($3)));}
652 | btype2 {$$ = gc1(pair(NIL,checkPred($1)));}
654 irule : context IMPLIES btype2 {$$ = gc3(pair($1,checkPred($3)));}
655 | btype2 {$$ = gc1(pair(NIL,checkPred($1)));}
657 dtypes : /* empty */ {$$ = gc0(NIL);}
658 | dtypes1 {$$ = gc1(rev($1));}
660 dtypes1 : dtypes1 ',' type {$$ = gc3(cons($3,$1));}
661 | type {$$ = gc1(cons($1,NIL));}
664 /*- Type expressions: -----------------------------------------------------*/
666 topType : context IMPLIES topType1 {$$ = gc3(qualify($1,$3));}
667 | topType1 {$$ = $1;}
669 topType1 : bpolyType ARROW topType1 {$$ = gc3(fn($1,$3));}
670 | btype1 ARROW topType1 {$$ = gc3(fn($1,$3));}
671 | btype2 ARROW topType1 {$$ = gc3(fn($1,$3));}
674 polyType : ALL varids '.' sigType {$$ = gc4(ap(POLYTYPE,
676 | bpolyType {$$ = $1;}
678 bpolyType : '(' polyType ')' {$$ = gc3($2);}
680 varids : varids ',' varid {$$ = gc3(cons($3,$1));}
681 | varid {$$ = gc1(singleton($1));}
683 sigType : context IMPLIES type {$$ = gc3(qualify($1,$3));}
686 context : '(' ')' {$$ = gc2(NIL);}
687 | btype2 {$$ = gc1(singleton(checkPred($1)));}
688 | '(' btype2 ')' {$$ = gc3(singleton(checkPred($2)));}
689 | '(' btypes2 ')' {$$ = gc3(checkContext(rev($2)));}
691 | lacks {$$ = gc1(singleton($1));}
692 | '(' lacks1 ')' {$$ = gc3(checkContext(rev($2)));}
694 lacks : varid '\\' varid {
696 $$ = gc3(ap(mkExt(textOf($3)),$1));
698 noTREX("a type context");
702 lacks1 : btypes2 ',' lacks {$$ = gc3(cons($3,$1));}
703 | lacks1 ',' btype2 {$$ = gc3(cons($3,$1));}
704 | lacks1 ',' lacks {$$ = gc3(cons($3,$1));}
705 | btype2 ',' lacks {$$ = gc3(cons($3,cons($1,NIL)));}
706 | lacks {$$ = gc1(singleton($1));}
710 type : type1 {$$ = $1;}
713 type1 : btype1 {$$ = $1;}
714 | btype1 ARROW type {$$ = gc3(fn($1,$3));}
715 | btype2 ARROW type {$$ = gc3(fn($1,$3));}
716 | error {syntaxError("type expression");}
718 btype : btype1 {$$ = $1;}
721 btype1 : btype1 atype {$$ = gc2(ap($1,$2));}
724 btype2 : btype2 atype {$$ = gc2(ap($1,$2));}
727 atype : atype1 {$$ = $1;}
730 atype1 : varid {$$ = $1;}
731 | '(' ')' {$$ = gc2(typeUnit);}
732 | '(' ARROW ')' {$$ = gc3(typeArrow);}
733 | '(' type1 ')' {$$ = gc3($2);}
734 | '(' btype2 ')' {$$ = gc3($2);}
735 | '(' tupCommas ')' {$$ = gc3($2);}
736 | '(' btypes2 ')' {$$ = gc3(buildTuple($2));}
737 | '(' typeTuple ')' {$$ = gc3(buildTuple($2));}
741 $$ = gc3(revOnto($2,typeNoRow));
746 | '(' tfields '|' type ')' {$$ = gc5(revOnto($2,$4));}
748 | '[' type ']' {$$ = gc3(ap(typeList,$2));}
749 | '[' ']' {$$ = gc2(typeList);}
750 | '_' {$$ = gc1(inventVar());}
752 btypes2 : btypes2 ',' btype2 {$$ = gc3(cons($3,$1));}
753 | btype2 ',' btype2 {$$ = gc3(cons($3,cons($1,NIL)));}
755 typeTuple : type1 ',' type {$$ = gc3(cons($3,cons($1,NIL)));}
756 | btype2 ',' type1 {$$ = gc3(cons($3,cons($1,NIL)));}
757 | btypes2 ',' type1 {$$ = gc3(cons($3,$1));}
758 | typeTuple ',' type {$$ = gc3(cons($3,$1));}
761 tfields : tfields ',' tfield {$$ = gc3(cons($3,$1));}
762 | tfield {$$ = gc1(singleton($1));}
764 tfield : varid COCO type {$$ = gc3(ap(mkExt(textOf($1)),$3));}
768 /*- Value declarations: ---------------------------------------------------*/
770 gendecl : INFIXN optDigit ops {$$ = gc3(fixdecl($1,$3,NON_ASS,$2));}
771 | INFIXN error {syntaxError("fixity decl");}
772 | INFIXL optDigit ops {$$ = gc3(fixdecl($1,$3,LEFT_ASS,$2));}
773 | INFIXL error {syntaxError("fixity decl");}
774 | INFIXR optDigit ops {$$ = gc3(fixdecl($1,$3,RIGHT_ASS,$2));}
775 | INFIXR error {syntaxError("fixity decl");}
776 | vars COCO topType {$$ = gc3(sigdecl($2,$1,$3));}
777 | vars COCO error {syntaxError("type signature");}
779 optDigit : NUMLIT {$$ = gc1(checkPrec($1));}
780 | /* empty */ {$$ = gc0(mkInt(DEF_PREC));}
782 ops : ops ',' op {$$ = gc3(cons($3,$1));}
783 | op {$$ = gc1(singleton($1));}
785 vars : vars ',' var {$$ = gc3(cons($3,$1));}
786 | var {$$ = gc1(singleton($1));}
788 decls : '{' decls0 end {$$ = gc3($2);}
789 | '{' decls1 end {$$ = gc3($2);}
791 decls0 : /* empty */ {$$ = gc0(NIL);}
792 | decls0 ';' {$$ = gc2($1);}
793 | decls1 ';' {$$ = gc2($1);}
795 decls1 : decls0 decl {$$ = gc2(cons($2,$1));}
797 decl : gendecl {$$ = $1;}
798 | funlhs rhs {$$ = gc2(ap(FUNBIND,pair($1,$2)));}
799 | funlhs COCO type rhs {$$ = gc4(ap(FUNBIND,
802 | pat0 rhs {$$ = gc2(ap(PATBIND,pair($1,$2)));}
804 funlhs : funlhs0 {$$ = $1;}
808 funlhs0 : pat10_vI varop pat0 {$$ = gc3(ap2($2,$1,$3));}
809 | infixPat varop pat0 {$$ = gc3(ap2($2,$1,$3));}
810 | NUMLIT varop pat0 {$$ = gc3(ap2($2,$1,$3));}
811 | var varop_pl pat0 {$$ = gc3(ap2($2,$1,$3));}
812 | var '+' pat0_INT {$$ = gc3(ap2(varPlus,$1,$3));}
814 funlhs1 : '(' funlhs0 ')' apat {$$ = gc4(ap($2,$4));}
815 | '(' funlhs1 ')' apat {$$ = gc4(ap($2,$4));}
816 | '(' npk ')' apat {$$ = gc4(ap($2,$4));}
817 | var apat {$$ = gc2(ap($1,$2));}
818 | funlhs1 apat {$$ = gc2(ap($1,$2));}
820 rhs : rhs1 wherePart {$$ = gc2(letrec($2,$1));}
821 | error {syntaxError("declaration");}
823 rhs1 : '=' exp {$$ = gc2(pair($1,$2));}
824 | gdrhs {$$ = gc1(grded(rev($1)));}
826 gdrhs : gdrhs gddef {$$ = gc2(cons($2,$1));}
827 | gddef {$$ = gc1(singleton($1));}
829 gddef : '|' exp0 '=' exp {$$ = gc4(pair($3,pair($2,$4)));}
831 wherePart : /* empty */ {$$ = gc0(NIL);}
832 | WHERE decls {$$ = gc2($2);}
835 /*- Patterns: -------------------------------------------------------------*/
840 pat_npk : pat0 COCO type {$$ = gc3(ap(ESIGN,pair($1,$3)));}
843 npk : var '+' NUMLIT {$$ = gc3(ap2(varPlus,$1,$3));}
845 pat0 : var {$$ = $1;}
849 pat0_INT : var {$$ = $1;}
852 pat0_vI : pat10_vI {$$ = $1;}
853 | infixPat {$$ = gc1(ap(INFIX,$1));}
855 infixPat : '-' pat10 {$$ = gc2(ap(NEG,only($2)));}
856 | var qconop pat10 {$$ = gc3(ap(ap($2,only($1)),$3));}
857 | var qconop '-' pat10 {$$ = gc4(ap(NEG,ap2($2,only($1),$4)));}
858 | NUMLIT qconop pat10 {$$ = gc3(ap(ap($2,only($1)),$3));}
859 | NUMLIT qconop '-' pat10 {$$ = gc4(ap(NEG,ap2($2,only($1),$4)));}
860 | pat10_vI qconop pat10 {$$ = gc3(ap(ap($2,only($1)),$3));}
861 | pat10_vI qconop '-' pat10 {$$ = gc4(ap(NEG,ap2($2,only($1),$4)));}
862 | infixPat qconop pat10 {$$ = gc3(ap(ap($2,$1),$3));}
863 | infixPat qconop '-' pat10 {$$ = gc4(ap(NEG,ap(ap($2,$1),$4)));}
865 pat10 : fpat {$$ = $1;}
868 pat10_vI : fpat {$$ = $1;}
871 fpat : fpat apat {$$ = gc2(ap($1,$2));}
872 | gcon apat {$$ = gc2(ap($1,$2));}
874 apat : NUMLIT {$$ = $1;}
878 apat_vI : var '@' apat {$$ = gc3(ap(ASPAT,pair($1,$3)));}
880 | qcon '{' patbinds '}' {$$ = gc4(ap(CONFLDS,pair($1,$3)));}
882 | STRINGLIT {$$ = $1;}
883 | '_' {$$ = gc1(WILDCARD);}
884 | '(' pat_npk ')' {$$ = gc3($2);}
885 | '(' npk ')' {$$ = gc3($2);}
886 | '(' pats2 ')' {$$ = gc3(buildTuple($2));}
887 | '[' pats1 ']' {$$ = gc3(ap(FINLIST,rev($2)));}
888 | '~' apat {$$ = gc2(ap(LAZYPAT,$2));}
890 | '(' patfields ')' {
892 $$ = gc3(revOnto($2,nameNoRec));
897 | '(' patfields '|' pat ')' {$$ = gc5(revOnto($2,$4));}
900 pats2 : pats2 ',' pat {$$ = gc3(cons($3,$1));}
901 | pat ',' pat {$$ = gc3(cons($3,singleton($1)));}
903 pats1 : pats1 ',' pat {$$ = gc3(cons($3,$1));}
904 | pat {$$ = gc1(singleton($1));}
906 patbinds : /* empty */ {$$ = gc0(NIL);}
907 | patbinds1 {$$ = gc1(rev($1));}
909 patbinds1 : patbinds1 ',' patbind {$$ = gc3(cons($3,$1));}
910 | patbind {$$ = gc1(singleton($1));}
912 patbind : qvar '=' pat {$$ = gc3(pair($1,$3));}
916 patfields : patfields ',' patfield {$$ = gc3(cons($3,$1));}
917 | patfield {$$ = gc1(singleton($1));}
919 patfield : varid '=' pat {
921 $$ = gc3(ap(mkExt(textOf($1)),$3));
929 /*- Expressions: ----------------------------------------------------------*/
931 exp : exp_err {$$ = $1;}
932 | error {syntaxError("expression");}
934 exp_err : exp0a COCO sigType {$$ = gc3(ap(ESIGN,pair($1,$3)));}
937 exp0 : exp0a {$$ = $1;}
940 exp0a : infixExpa {$$ = gc1(ap(INFIX,$1));}
943 exp0b : infixExpb {$$ = gc1(ap(INFIX,$1));}
946 infixExpa : infixExpa qop '-' exp10a {$$ = gc4(ap(NEG,ap(ap($2,$1),$4)));}
947 | infixExpa qop exp10a {$$ = gc3(ap(ap($2,$1),$3));}
948 | '-' exp10a {$$ = gc2(ap(NEG,only($2)));}
949 | exp10a qop '-' exp10a {$$ = gc4(ap(NEG,
950 ap(ap($2,only($1)),$4)));}
951 | exp10a qop exp10a {$$ = gc3(ap(ap($2,only($1)),$3));}
953 infixExpb : infixExpa qop '-' exp10b {$$ = gc4(ap(NEG,ap(ap($2,$1),$4)));}
954 | infixExpa qop exp10b {$$ = gc3(ap(ap($2,$1),$3));}
955 | '-' exp10b {$$ = gc2(ap(NEG,only($2)));}
956 | exp10a qop '-' exp10b {$$ = gc4(ap(NEG,
957 ap(ap($2,only($1)),$4)));}
958 | exp10a qop exp10b {$$ = gc3(ap(ap($2,only($1)),$3));}
960 exp10a : CASEXP exp OF '{' alts end {$$ = gc6(ap(CASE,pair($2,rev($5))));}
961 | DO '{' stmts end {$$ = gc4(ap(DOCOMP,checkDo($3)));}
964 exp10b : '\\' pats ARROW exp {$$ = gc4(ap(LAMBDA,
967 | LET decls IN exp {$$ = gc4(letrec($2,$4));}
968 | IF exp THEN exp ELSE exp {$$ = gc6(ap(COND,triple($2,$4,$6)));}
970 pats : pats apat {$$ = gc2(cons($2,$1));}
971 | apat {$$ = gc1(cons($1,NIL));}
973 appExp : appExp aexp {$$ = gc2(ap($1,$2));}
976 aexp : qvar {$$ = $1;}
977 | qvar '@' aexp {$$ = gc3(ap(ASPAT,pair($1,$3)));}
978 | '~' aexp {$$ = gc2(ap(LAZYPAT,$2));}
979 | '_' {$$ = gc1(WILDCARD);}
981 | qcon '{' fbinds '}' {$$ = gc4(ap(CONFLDS,pair($1,$3)));}
982 | aexp '{' fbinds '}' {$$ = gc4(ap(UPDFLDS,
983 triple($1,NIL,$3)));}
986 | STRINGLIT {$$ = $1;}
988 | '(' exp ')' {$$ = gc3($2);}
989 | '(' exps2 ')' {$$ = gc3(buildTuple($2));}
993 $$ = gc3(revOnto($2,nameNoRec));
998 | '(' vfields '|' exp ')' {$$ = gc5(revOnto($2,$4));}
999 | RECSELID {$$ = $1;}
1001 | '[' list ']' {$$ = gc3($2);}
1002 | '(' exp10a qop ')' {$$ = gc4(ap($3,$2));}
1003 | '(' qvarop_mi exp0 ')' {$$ = gc4(ap(ap(nameFlip,$2),$3));}
1004 | '(' qconop exp0 ')' {$$ = gc4(ap(ap(nameFlip,$2),$3));}
1006 exps2 : exps2 ',' exp {$$ = gc3(cons($3,$1));}
1007 | exp ',' exp {$$ = gc3(cons($3,cons($1,NIL)));}
1010 vfields : vfields ',' vfield {$$ = gc3(cons($3,$1));}
1011 | vfield {$$ = gc1(singleton($1));}
1013 vfield : varid '=' exp {
1015 $$ = gc3(ap(mkExt(textOf($1)),$3));
1017 noTREX("an expression");
1022 alts : alts1 {$$ = $1;}
1023 | alts1 ';' {$$ = gc2($1);}
1025 alts1 : alts1 ';' alt {$$ = gc3(cons($3,$1));}
1026 | alt {$$ = gc1(cons($1,NIL));}
1028 alt : pat altRhs wherePart {$$ = gc3(pair($1,letrec($3,$2)));}
1030 altRhs : guardAlts {$$ = gc1(grded(rev($1)));}
1031 | ARROW exp {$$ = gc2(pair($1,$2));}
1032 | error {syntaxError("case expression");}
1034 guardAlts : guardAlts guardAlt {$$ = gc2(cons($2,$1));}
1035 | guardAlt {$$ = gc1(cons($1,NIL));}
1037 guardAlt : '|' exp0 ARROW exp {$$ = gc4(pair($3,pair($2,$4)));}
1039 stmts : stmts1 ';' {$$ = gc2($1);}
1042 stmts1 : stmts1 ';' stmt {$$ = gc3(cons($3,$1));}
1043 | stmt {$$ = gc1(cons($1,NIL));}
1045 stmt : exp_err FROM exp {$$ = gc3(ap(FROMQUAL,pair($1,$3)));}
1046 | LET decls {$$ = gc2(ap(QWHERE,$2));}
1047 /* | IF exp {$$ = gc2(ap(BOOLQUAL,$2));}*/
1048 | exp_err {$$ = gc1(ap(DOQUAL,$1));}
1050 fbinds : /* empty */ {$$ = gc0(NIL);}
1051 | fbinds1 {$$ = gc1(rev($1));}
1053 fbinds1 : fbinds1 ',' fbind {$$ = gc3(cons($3,$1));}
1054 | fbind {$$ = gc1(singleton($1));}
1056 fbind : var {$$ = $1;}
1057 | qvar '=' exp {$$ = gc3(pair($1,$3));}
1060 /*- List Expressions: -------------------------------------------------------*/
1062 list : exp {$$ = gc1(ap(FINLIST,cons($1,NIL)));}
1063 | exps2 {$$ = gc1(ap(FINLIST,rev($1)));}
1064 | exp '|' quals {$$ = gc3(ap(COMP,pair($1,rev($3))));}
1065 | exp UPTO exp {$$ = gc3(ap(ap(nameFromTo,$1),$3));}
1066 | exp ',' exp UPTO {$$ = gc4(ap(ap(nameFromThen,$1),$3));}
1067 | exp UPTO {$$ = gc2(ap(nameFrom,$1));}
1068 | exp ',' exp UPTO exp {$$ = gc5(ap(ap(ap(nameFromThenTo,
1071 quals : quals ',' qual {$$ = gc3(cons($3,$1));}
1072 | qual {$$ = gc1(cons($1,NIL));}
1074 qual : exp FROM exp {$$ = gc3(ap(FROMQUAL,pair($1,$3)));}
1075 | exp {$$ = gc1(ap(BOOLQUAL,$1));}
1076 | LET decls {$$ = gc2(ap(QWHERE,$2));}
1079 /*- Identifiers and symbols: ----------------------------------------------*/
1081 gcon : qcon {$$ = $1;}
1082 | '(' ')' {$$ = gc2(nameUnit);}
1083 | '[' ']' {$$ = gc2(nameNil);}
1084 | '(' tupCommas ')' {$$ = gc3($2);}
1086 tupCommas : tupCommas ',' {$$ = gc2(mkTuple(tupleOf($1)+1));}
1087 | ',' {$$ = gc1(mkTuple(2));}
1089 varid : VARID {$$ = $1;}
1090 | HIDING {$$ = gc1(varHiding);}
1091 | QUALIFIED {$$ = gc1(varQualified);}
1092 | ASMOD {$$ = gc1(varAsMod);}
1094 qconid : QCONID {$$ = $1;}
1097 var : varid {$$ = $1;}
1098 | '(' VAROP ')' {$$ = gc3($2);}
1099 | '(' '+' ')' {$$ = gc3(varPlus);}
1100 | '(' '-' ')' {$$ = gc3(varMinus);}
1101 | '(' '!' ')' {$$ = gc3(varBang);}
1102 | '(' '.' ')' {$$ = gc3(varDot);}
1104 qvar : QVARID {$$ = $1;}
1105 | '(' QVAROP ')' {$$ = gc3($2);}
1108 con : CONID {$$ = $1;}
1109 | '(' CONOP ')' {$$ = gc3($2);}
1111 qcon : QCONID {$$ = $1;}
1112 | '(' QCONOP ')' {$$ = gc3($2);}
1115 varop : '+' {$$ = gc1(varPlus);}
1116 | '-' {$$ = gc1(varMinus);}
1117 | varop_mipl {$$ = $1;}
1119 varop_mi : '+' {$$ = gc1(varPlus);}
1120 | varop_mipl {$$ = $1;}
1122 varop_pl : '-' {$$ = gc1(varMinus);}
1123 | varop_mipl {$$ = $1;}
1125 varop_mipl: VAROP {$$ = $1;}
1126 | '`' varid '`' {$$ = gc3($2);}
1127 | '!' {$$ = gc1(varBang);}
1128 | '.' {$$ = gc1(varDot);}
1130 qvarop : '-' {$$ = gc1(varMinus);}
1131 | qvarop_mi {$$ = $1;}
1133 qvarop_mi : QVAROP {$$ = $1;}
1134 | '`' QVARID '`' {$$ = gc3($2);}
1135 | varop_mi {$$ = $1;}
1138 conop : CONOP {$$ = $1;}
1139 | '`' CONID '`' {$$ = gc3($2);}
1141 qconop : QCONOP {$$ = $1;}
1142 | '`' QCONID '`' {$$ = gc3($2);}
1145 op : varop {$$ = $1;}
1148 qop : qvarop {$$ = $1;}
1152 /*- Stuff from STG hugs ---------------------------------------------------*/
1154 qvarid : varid1 {$$ = gc1($1);}
1155 | QVARID {$$ = gc1($1);}
1157 varid1 : VARID {$$ = gc1($1);}
1158 | HIDING {$$ = gc1(varHiding);}
1159 | QUALIFIED {$$ = gc1(varQualified);}
1160 | ASMOD {$$ = gc1(varAsMod);}
1163 /*- Tricks to force insertion of leading and closing braces ---------------*/
1165 begin : error {yyerrok;
1166 if (offsideON) goOffside(startColumn);}
1168 /* deal with trailing semicolon */
1169 end : '}' {$$ = $1;}
1171 if (offsideON && canUnOffside()) {
1173 /* insert extra token on stack*/
1175 pushed(0) = pushed(1);
1176 pushed(1) = mkInt(column);
1179 syntaxError("definition");
1183 /*-------------------------------------------------------------------------*/
1187 static Cell local gcShadow(n,e) /* keep parsed fragments on stack */
1190 /* If a look ahead token is held then the required stack transformation
1193 * x1 | ... | xn | la ===> e | la
1196 * Otherwise, the transformation is:
1198 * x1 | ... | xn ===> e
1202 pushed(n-1) = top();
1211 static Void local syntaxError(s) /* report on syntax error */
1213 ERRMSG(row) "Syntax error in %s (unexpected %s)", s, unexpected()
1217 static String local unexpected() { /* find name for unexpected token */
1218 static char buffer[100];
1219 static char *fmt = "%s \"%s\"";
1220 static char *kwd = "keyword";
1223 case 0 : return "end of input";
1225 #define keyword(kw) sprintf(buffer,fmt,kwd,kw); return buffer;
1226 case INFIXL : keyword("infixl");
1227 case INFIXR : keyword("infixr");
1228 case INFIXN : keyword("infix");
1229 case FOREIGN : keyword("foreign");
1230 case UNSAFE : keyword("unsafe");
1231 case TINSTANCE : keyword("instance");
1232 case TCLASS : keyword("class");
1233 case CASEXP : keyword("case");
1234 case OF : keyword("of");
1235 case IF : keyword("if");
1236 case THEN : keyword("then");
1237 case ELSE : keyword("else");
1238 case WHERE : keyword("where");
1239 case TYPE : keyword("type");
1240 case DATA : keyword("data");
1241 case TNEWTYPE : keyword("newtype");
1242 case LET : keyword("let");
1243 case IN : keyword("in");
1244 case DERIVING : keyword("deriving");
1245 case DEFAULT : keyword("default");
1246 case IMPORT : keyword("import");
1247 case TMODULE : keyword("module");
1248 case ALL : keyword("__forall");
1251 case ARROW : return "`->'";
1252 case '=' : return "`='";
1253 case COCO : return "`::'";
1254 case '-' : return "`-'";
1255 case '!' : return "`!'";
1256 case ',' : return "comma";
1257 case '@' : return "`@'";
1258 case '(' : return "`('";
1259 case ')' : return "`)'";
1260 case '{' : return "`{'";
1261 case '}' : return "`}'";
1262 case '_' : return "`_'";
1263 case '|' : return "`|'";
1264 case '.' : return "`.'";
1265 case ';' : return "`;'";
1266 case UPTO : return "`..'";
1267 case '[' : return "`['";
1268 case ']' : return "`]'";
1269 case FROM : return "`<-'";
1270 case '\\' : return "backslash (lambda)";
1271 case '~' : return "tilde";
1272 case '`' : return "backquote";
1274 case RECSELID : sprintf(buffer,"selector \"#%s\"",
1275 textToStr(extText(snd(yylval))));
1281 case CONID : sprintf(buffer,"symbol \"%s\"",
1282 textToStr(textOf(yylval)));
1287 case QCONID : sprintf(buffer,"symbol \"%s\"",
1288 identToStr(yylval));
1290 case HIDING : return "symbol \"hiding\"";
1291 case QUALIFIED : return "symbol \"qualified\"";
1292 case ASMOD : return "symbol \"as\"";
1293 case NUMLIT : return "numeric literal";
1294 case CHARLIT : return "character literal";
1295 case STRINGLIT : return "string literal";
1296 case IMPLIES : return "`=>'";
1297 default : return "token";
1301 static Cell local checkPrec(p) /* Check for valid precedence value*/
1303 if (!isInt(p) || intOf(p)<MIN_PREC || intOf(p)>MAX_PREC) {
1304 ERRMSG(row) "Precedence value must be an integer in the range [%d..%d]",
1311 static Cell local buildTuple(tup) /* build tuple (x1,...,xn) from */
1312 List tup; { /* list [xn,...,x1] */
1318 x = fst(t); /* / \ / \ */
1319 fst(t) = snd(t); /* xn . . xn */
1320 snd(t) = x; /* . ===> . */
1322 t = fun(x); /* . . */
1324 } while (nonNull(t)); /* x1 NIL (n) x1 */
1325 fst(x) = mkTuple(n);
1329 static List local checkContext(con) /* validate context */
1331 mapOver(checkPred, con);
1335 static Cell local checkPred(c) /* check that type expr is a valid */
1336 Cell c; { /* constraint */
1337 Cell cn = getHead(c);
1339 if (isExt(cn) && argCount==1)
1342 if (!isQCon(cn) || argCount==0)
1343 syntaxError("class expression");
1347 static Pair local checkDo(dqs) /* convert reversed list of dquals */
1348 List dqs; { /* to an (expr,quals) pair */
1349 if (isNull(dqs) || whatIs(hd(dqs))!=DOQUAL) {
1350 ERRMSG(row) "Last generator in do {...} must be an expression"
1353 fst(dqs) = snd(fst(dqs)); /* put expression in fst of pair */
1354 snd(dqs) = rev(snd(dqs)); /* & reversed list of quals in snd */
1358 static Cell local checkTyLhs(c) /* check that lhs is of the form */
1359 Cell c; { /* T a1 ... a */
1361 while (isAp(tlhs) && whatIs(arg(tlhs))==VARIDCELL)
1363 switch (whatIs(tlhs)) {
1364 case CONIDCELL : return c;
1367 ERRMSG(row) "Illegal left hand side in datatype definition"
1370 return 0; /* NOTREACHED */
1374 static Void local noTREX(where)
1376 ERRMSG(row) "Attempt to use TREX records while parsing %s.\n", where ETHEN
1377 ERRTEXT "(TREX is disabled in this build of Hugs)"
1382 /*-------------------------------------------------------------------------*/