#include /* Part 1 of Project 1. Students: your job is to implement the eval_wff function. The eval_wff function takes as input three parameters: wff: a string of characters (a null-terminated array of characters) that represents a WFF. val: an array of integers (1 represents true, 0 represents false) that say whether a propositional variable is true or false. For example, val['p'] says whether p is true or false. start: is the position of the start of a WFF within the wff array. The eval_wff function returns a struct containing two data members. The first data member, named end, is the index for one-past the last character in the WFF that started at start. The second, named value, is 1 if the WFF starting at start is true and returns 0 if the WFF starting at start is false. Hint: implement eval_wff as a recursive function (it calls itself) that is similar to the check_wff function given below. */ struct eval_ret { int end; int value; }; struct eval_ret eval_wff(char wff[], int val[], int start); /* check_wff inputs: wff: is an array of characters, possibly representing a WFF start: is the position of the start of a WFF within the wff array. output: -1 if wff is not a WFF, or a positive integer that is one past the end of the WFF that started at start */ int check_wff(char wff[], int start) { switch (wff[start]) { case 'N': return check_wff(wff, start + 1); case 'C': start = check_wff(wff, start + 1); if (start == -1) return -1; return check_wff(wff, start); case 'A': start = check_wff(wff, start + 1); if (start == -1) return -1; return check_wff(wff, start); case 'K': start = check_wff(wff, start + 1); if (start == -1) return -1; return check_wff(wff, start); case 'E': start = check_wff(wff, start + 1); if (start == -1) return -1; return check_wff(wff, start); case 'p': case 'q': case 'r': case 's': return start + 1; default: return -1; } } const int val_len = 128; /* true_vars is a NULL terminated string */ void init_val(int* val, char* true_vars) { int i; for (i = 0; i != val_len; ++i) val[i] = 0; for (i = 0; true_vars[i] != 0; ++i) val[true_vars[i]] = 1; } int main(int argc, char* argv[]) { FILE* f; char true_vars[5]; int val[val_len]; char c, wff[10000]; int result, i; f = fopen(argv[1], "r"); i = 0; while ((c = fgetc(f)) != '\n') true_vars[i++] = c; true_vars[i] = 0; init_val(val, true_vars); fscanf(f, "%s", wff); fclose(f); result = check_wff(wff, 0); if (result == -1) printf("not a wff\n"); if (eval_wff(wff, val, 0).value) printf("true\n"); else printf("false\n"); return 0; }