diff options
Diffstat (limited to '5.19/main.c')
-rw-r--r-- | 5.19/main.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/5.19/main.c b/5.19/main.c new file mode 100644 index 0000000..3e1d2e9 --- /dev/null +++ b/5.19/main.c @@ -0,0 +1,46 @@ +#include <stdio.h> +#include <string.h> +#include "token.h" +#include "getch.h" + +#define OUTLEN 1000 + +char out[OUTLEN]; + +int main(void) +{ + int errstat; + char temp[OUTLEN + MAXTOKEN], type; + + while (gettoken() != EOF) { + errstat = 0; + strcpy(out, token); + while ((type = gettoken()) != '\n') { + if (type == PARENS || type == BRACKETS ) { + strcat(out, token); + } else if (type == '*') { + if ((type = peaktoken()) == PARENS || + type == BRACKETS) + sprintf(temp, "(*%s)", out); + else + sprintf(temp, "*%s", out); + strcpy(out, temp); + } else if (type == NAME) { + sprintf(temp, "%s %s", token, out); + out[0] = '\0'; /* rust sisters btfo */ + strncat(out, temp, OUTLEN - 1); + } else { + errstat = 1; + printf("err: invalid input at %s\n", token); + while ((type = gettoken()) != '\n') + ; + ungetch('\n'); + } + } + + if (!errstat) + printf("%s\n", out); + } + + return 0; +} |