hello,
I have been trying to understand this function, there is still a few things confusing me. First, what are those weird statements like return token type = BRACKETS for? I have never seen them before.
Code:
int gettoken(void) /* return next token */
{
int c, getch(void);
void ungetch(int);
char *p = token; /* character string pointed by p */
while ((c = getch()) == ' ' || c == '\t') /* skip blanks or tabs */
;
if (c == '(') {
if ((c = getch()) == ')') {
strcpy(token, "()");
return tokentype = PARENS;
} else {
ungetch(c); /* put character back on input before prosessing new input */
return tokentype = '(';
}
} else if (c == '[') {
for (*p++ = c; (*p++ = getch()) != ']'; ) /* do nothing as long as character is not terminating bracket */
;
*p = '\0';
return tokentype = BRACKETS; /* if it is, we found it, so tokentype is brackets */
} else if (isalpha(c)) {
for (*p++ = c; isalnum(c == getch()); ) /* read characters as long as is alphanumeric */
*p++ = c;
*p = '\0';
ungetch(c); /* if not, push back into the buffer */
return tokentype = NAME /* how about these odd return statements?? */
} else
return tokentype = c;
}