summaryrefslogtreecommitdiff
path: root/ghc/compiler/parser/infix.c
diff options
context:
space:
mode:
authorsimonmar <unknown>1999-06-01 16:41:09 +0000
committersimonmar <unknown>1999-06-01 16:41:09 +0000
commit904f158f9fe208b8154029dff655a6eab4b2828e (patch)
tree6672415bda27fbb353fa85f09a3b03cedc505cf2 /ghc/compiler/parser/infix.c
parent6ee2f67e582427f931c21c1fc58f62f8619d40b7 (diff)
downloadhaskell-904f158f9fe208b8154029dff655a6eab4b2828e.tar.gz
[project @ 1999-06-01 16:40:41 by simonmar]
This commit replaces the old yacc parser with a Happy-generated one. Notes: - The generated .hs file is *big*. Best to use a recent version of Happy, and even better to add the -c flag to use unsafeCoerce# with ghc (versions 4.02+ please). - The lexer has grown all sorts of unsightly growths and should be put down as soon as possible. - Parse errors may result in strange diagnostics. I'm looking into this. - HsSyn now contains a few extra constructors due to the way patterns are parsed as expressions in the parser. - The layout rule is implemented according to the Haskell report. I found a couple of places in the libraries where we previously weren't adhering to this - in particular the rule about "nested contexts must be more indented than outer contexts". The rule is necessary to disambiguate in the presence of empty declaration lists.
Diffstat (limited to 'ghc/compiler/parser/infix.c')
-rw-r--r--ghc/compiler/parser/infix.c200
1 files changed, 0 insertions, 200 deletions
diff --git a/ghc/compiler/parser/infix.c b/ghc/compiler/parser/infix.c
deleted file mode 100644
index 627fb92473..0000000000
--- a/ghc/compiler/parser/infix.c
+++ /dev/null
@@ -1,200 +0,0 @@
-/*
- * Infix operator stuff -- modified from LML
- */
-
-#include <stdio.h>
-
-#include "hspincl.h"
-#include "hsparser.tab.h"
-#include "constants.h"
-#include "utils.h"
-
-static struct infix {
- char *imod;
- char *iop;
- short thismod;
- short unqualok;
- short ifixity;
- short iprecedence;
-} infixtab[MAX_INFIX];
-
-static int ninfix = 0;
-
-void
-makeinfix(opid, fixity, precedence, modid, imported,
- withas, impmodid, impasid, withqual,
- withspec, withhiding, importspec)
- id opid;
- int fixity, precedence;
- long imported, withas, withqual, withspec, withhiding;
- id modid, impmodid, impasid;
- list importspec;
-/*
- ToDo: Throw away infix operator if hidden by importspec!
-*/
-{
- int i;
- char *op = id_to_string(opid);
- char *mod = id_to_string(imported ? (withas ? impasid : impmodid) : modid);
- short thismod = ! imported;
- short unqualok = ! (imported && withqual);
-
- for(i=0; i < ninfix; ++i)
- {
- if(strcmp(op,infixtab[i].iop)==0 &&
- strcmp(mod,infixtab[i].imod)==0 &&
- unqualok==infixtab[i].unqualok)
- {
- /* Allow duplicate definitions if they are identical */
- if (infixtab[i].ifixity==fixity &&
- infixtab[i].iprecedence==precedence)
- {
- return;
- }
-
- /* Allow local definition to override an import */
- else if(thismod && !infixtab[i].thismod)
- {
- /*continue*/
- }
-
- else
- {
- char errbuf[ERR_BUF_SIZE];
- sprintf(errbuf,"%s.%s %s already declared to be %s %d\n",
- mod, op, unqualok ? "(unqualified)" : "(qualified)",
- infixstr(infixtab[i].ifixity),
- infixtab[i].iprecedence);
- hsperror(errbuf);
- }
- }
- }
-
- if (ninfix >= MAX_INFIX) {
- char errbuf[ERR_BUF_SIZE];
- sprintf(errbuf,"Too many Infix identifiers (> %d)",MAX_INFIX);
- hsperror(errbuf);
- }
-
-#ifdef HSP_DEBUG
- fprintf(stderr,"makeinfix: %s.%s, fixity=%d prec=%d\n",mod,op,infixint(fixity),precedence);
-#endif
- infixtab[ninfix].imod = mod;
- infixtab[ninfix].iop = op;
- infixtab[ninfix].thismod = thismod;
- infixtab[ninfix].unqualok = unqualok;
- infixtab[ninfix].ifixity = fixity;
- infixtab[ninfix].iprecedence = precedence;
- ninfix++;
-}
-
-struct infix *
-infixlookup(name)
- qid name;
-{
- int i;
- struct infix *found = NULL;
- char *op = qid_to_string(name);
- char *mod = qid_to_mod(name);
- short unqual = mod == NULL;
-
- for(i = 0; i < ninfix; i++)
- {
- if(strcmp(op,infixtab[i].iop)==0 &&
- ( (unqual && infixtab[i].unqualok) ||
- (!unqual && strcmp(mod,infixtab[i].imod)==0)
- ))
- {
- if (! found)
- {
- /* first find */
- found = infixtab+i;
- }
- else if (found && ! found->thismod && infixtab[i].thismod)
- {
- /* new find for this module; overrides */
- found = infixtab+i;
- }
- else if (found && found->thismod && ! infixtab[i].thismod)
- {
- /* prev find for this module */
- }
- else if (found->ifixity == infixtab[i].ifixity &&
- found->iprecedence == infixtab[i].iprecedence)
- {
- /* finds are identical */
- }
- else
- {
- char errbuf[ERR_BUF_SIZE];
- sprintf(errbuf,"conflicting infix declarations for %s.%s\n %s.%s %s (%s,%d) and %s.%s %s (%s,%d)\n",
- qid_to_pmod(name), op,
- found->imod, found->iop, found->unqualok ? "(unqualified)" : "(qualified)",
- infixstr(found->ifixity),found->iprecedence,
- infixtab[i].imod, infixtab[i].iop, infixtab[i].unqualok ? "(unqualified)" : "(qualified)",
- infixstr(infixtab[i].ifixity),infixtab[i].iprecedence);
- hsperror(errbuf);
-
- }
- }
- }
-
-#ifdef HSP_DEBUG
- fprintf(stderr,"infixlookup: %s.%s = fixity=%d prec=%d\n",qid_to_pmod(name),op,infixint(pfixity(found)),pprecedence(found));
-#endif
-
- return(found);
-}
-
-int
-pfixity(ip)
- struct infix *ip;
-{
- return(ip == NULL? INFIXL: ip->ifixity);
-}
-
-int
-pprecedence(ip)
- struct infix *ip;
-{
- return(ip == NULL? 9: ip->iprecedence);
-}
-
-char *
-infixstr(n)
- int n;
-{
- switch(n) {
- case INFIXL:
- return "infixl";
-
- case INFIXR:
- return "infixr";
-
- case INFIX:
- return "infix";
-
- default:
- hsperror("infixstr");
- }
-}
-
-long
-infixint(n)
- int n;
-{
- switch(n) {
- case INFIXL:
- return -1;
-
- case INFIX:
- return 0;
-
- case INFIXR:
- return 1;
-
- default:
- hsperror("infixint");
- }
-}
-