#include #include #include #include const int MAX_PROGRAM_LENGTH = 38911; // FILE* outfile; for compiler. char* input; char* token; char delims[] = " \n\r\t"; void next_token() { static int started = 0; if (! started) { token = strtok (input, delims); started = 1; } else { token = strtok (NULL, delims); } if (token == NULL) token = "EOF"; } void error(char* nt) { fprintf(stderr, "Error in %s at token '%s'\n", nt, token); exit(1); } void Opnd () { if (! strcmp (token, "true")) { next_token(); } else if (! strcmp(token, "false")) { next_token(); } else error("Opnd"); } void Expr () { if (! strcmp(token,"or")) { next_token(); Expr(); Expr(); } else if (! strcmp(token,"and")){ next_token(); Expr(); Expr(); } else if (! strcmp(token,"exor")){ next_token(); Expr(); Expr(); } else if (! strcmp(token,"not")) { next_token(); Expr(); } else Opnd(); } void Start () { next_token(); Expr(); if (strcmp(token, "EOF")) { error("Start"); } } int main(void) { FILE* infile = fopen("in.truth", "r"); input = malloc(MAX_PROGRAM_LENGTH); fgets(input, MAX_PROGRAM_LENGTH, infile); Start(); fclose(infile); return 0; }