diff options
author | sinanmohd <sinan@firemail.cc> | 2023-04-22 17:46:20 +0530 |
---|---|---|
committer | sinanmohd <sinan@firemail.cc> | 2023-04-23 21:30:25 +0530 |
commit | 2f3d854c1226108907651a8fcf9228767eee9742 (patch) | |
tree | a5ba21f54083291fcc2fb57b5ff676d94883afee /5.20/dcl.c | |
parent | c14dab7f3a1cf72619fadce9b81b55426dc0b32e (diff) |
5.20: initial commit
Diffstat (limited to '5.20/dcl.c')
-rw-r--r-- | 5.20/dcl.c | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/5.20/dcl.c b/5.20/dcl.c new file mode 100644 index 0000000..e504919 --- /dev/null +++ b/5.20/dcl.c @@ -0,0 +1,72 @@ +#include <stdio.h> +#include <string.h> +#include "token.h" +#include "err.h" +#include "dcl.h" + +char out[OUTLEN]; +char name[MAXTOKEN]; + +void dcl(void) +{ + int ns; + + for (ns = 0; gettoken() == '*';) + ns++; + dirdcl(); + while (ns-- > 0) + strncat(out, " pointer to", OUTLEN - 1); +} + +void dirdcl(void) +{ + int type; + + if (tokentype == '(') { + dcl(); + if (tokentype != ')') + warn("missing )"); + } else if (tokentype == ')' || tokentype == ',') { + prevtoken = YES; + } else if (tokentype == NAME) { + strcpy(name, token); + } else { + warn("expected () or name or (dcl)"); + } + + while ((type = gettoken()) == PARENS || type == BRACKETS || + type == '(' || type == ',') { + if (type == PARENS) { + strncat(out, " function returning", OUTLEN - 1); + } else if (type == '(') { + strncat(out, " function expecting", OUTLEN - 1); + parmdcl(); + strncat(out, " and returning", OUTLEN - 1); + } else if (type == ',') { + parmdcl(); + strncat(out, ",", OUTLEN - 1); + } else { + strncat(out, " array", OUTLEN - 1); + strncat(out, token, OUTLEN - 1); + strncat(out, " of", OUTLEN - 1); + } + } + + if (tokentype == '\n') + prevtoken = YES; +} + +void parmdcl(void) +{ + char parmdt[MAXTOKEN]; + parmdt[0] = '\0'; + + while (gettoken() == NAME && isdatatyp()) { + strncat(parmdt, " ", MAXTOKEN - 1); + strncat(parmdt, token, MAXTOKEN - 1); + } + + prevtoken = YES; + dcl(); + strncat(out, parmdt, OUTLEN - 1); +} |