#include #include #include "getch.h" #include "token.h" enum { NO, YES }; char tokentype; char token[MAXTOKEN]; char prevtoken; int gettoken(void) { char c, *p = token; char getch(void); void ungetch(char); if (prevtoken == YES) { prevtoken = NO; return tokentype; } while(isblank(c = getch())) ; if (c == '/') { /* ignore comments */ if ((c = getch()) == '/') { while ((c = getch()) != '\n') ; } else if (c == '*') { while (getch() != '*' || (c = getch()) != '/') if (c == '*') ungetch('*'); return gettoken(); } else { ungetch(c); c = '/'; } } if (c == '(') { if ((c = getch()) == ')') { strcpy(token, "()"); return tokentype = PARENS; } else { ungetch(c); return tokentype = '('; } } else if (c == '[') { for (*p++ = '['; (*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; } } int peaktoken() { char type; type = gettoken(); prevtoken = YES; return type; }