/* cradle */ #include #include #include #include int look; /* lookahead character */ void get(void) { look = getchar(); } void error(char *s) { printf("\n\aError: %s.\n", s); } void die(char *s) { error(s); exit(1); } char *dstrcat(char *a, char *b) { char *result = malloc(strlen(a) + strlen(b) + 1); if (result == NULL) die("Out of memory."); strcpy(result, a); strcat(result, b); return result; } char *dstrcat3(char *a, char *b, char *c) { char *result = malloc(strlen(a) + strlen(b) + strlen(c) + 1); if (result == NULL) die("Out of memory."); strcpy(result, a); strcat(result, b); strcat(result, c); return result; } void expected(char *s) { die(dstrcat(s, " expected")); } void match(char x) { if (look == x) get(); else { char quoted[4]; quoted[0] = '\''; quoted[1] = x; quoted[2] = '\''; quoted[3] = '\0'; expected(quoted); } } char getname() { char name; if (!isalpha(look)) expected("Name"); name = toupper(look); get(); return name; } char getnum() { char num; if (!isdigit(look)) expected("Integer"); num = look; get(); return num; } void emit(char *s) { printf("\t%s", s); } void emitln(char *s) { printf("\t%s\n", s); } void init(void) { get(); } int main(void) { init(); return 0; }