#include #include "utils.h" #define MAXTOKEN 100 enum { NAME, PARENS, BRACKETS }; int gettoken(void); int tokentype; char token[MAXTOKEN]; char name[MAXTOKEN]; char datatype[MAXTOKEN]; char out[1000]; int main() { int type; int ns; char temp[MAXTOKEN]; /* it would have been so much easier to avoid redundant parenthesis by using a goto statement, but alas, that's bad form >:O */ while (gettoken() != EOF) { ns = 0; strcpy(out, token); while ((type = gettoken()) != '\n') { if (type == PARENS || type == BRACKETS) { if (ns) { temp[0] = '\0'; while (ns) { strcat(temp, "*"); ns--; } strcat(temp, out); sprintf(out, "(%s)", temp); } strcat(out, token); } else if (type == '*') { ns++; } else if (type == NAME) { temp[0] = '\0'; while (ns) { strcat(temp, "*"); ns--; } strcat(temp, out); sprintf(out, "%s", temp); sprintf(temp, "%s %s", token, out); strcpy(out, temp); } else printf("invalid input at %s\n", token); } printf("%s\n", out); } return 0; } int gettoken(void) { int c; char *p = token; while ((c = getch()) == ' ' || c == '\t'); if (c == '(') { while ((c = getch()) == ' '); if (c == ')') { strcpy(token, "()"); return tokentype = PARENS; } else { ungetch(c); return tokentype = '('; } } else if (c == '[') { for (*p++ = c; (*p++ = getch()) != ']'; ) ; *p = '\0'; return tokentype = BRACKETS; } else if (isalpha(c)) { for (*p++ = c; isalnum(c = getch()); ) *p++ = c; *p = '\0'; ungetch(c); return tokentype = NAME; } else return tokentype = c; }