Listing 1
int lexical (char *buf, long long *idx, MESSAGE *m) {
int c, i, j;
int is_float = 0;
int tmpint;
double tmpfloat;
char tmpbuf[MAXMSG];
char *q;
c = buf[(*idx)++];
/* WHITESPACE */
if (c == ' ' || c == '\t' || c == '\f') {
if (!isspace ((int)buf[*idx])) {
sprintf (m -> name, "%c", c);
m -> tokentype = WHITESPACE;
return WHITESPACE;
}
for (i = 0, (*idx)--;
((buf[*idx + i] == ' ') || (buf[*idx + i] == '\t') ||
(buf[*idx] == '\f'));
i++, (*idx)++)
m -> name[i] = buf[*idx];
m -> name[i] = 0;
m -> tokentype = WHITESPACE;
return WHITESPACE;
}
/* LABEL */
if (isalnum ((int)c) || c == '_') {
(*idx)--;
q = tmpbuf;
while (isalnum ((int)buf[*idx]) || (buf[*idx] == '_'))
*q++ = buf[(*idx)++];
*q = 0;
strcpy (m -> name, tmpbuf);
m -> tokentype = LABEL;
return LABEL;
}
.
.
.
sprintf (m -> name, "%c", c);
m -> tokentype = CHAR;
return c;
}