For this project you will write a program that generates a truth table for a giv
ID: 3581439 • Letter: F
Question
For this project you will write a program that generates a truth table for a given propositional sentence. The propositional letters will be p0, p1, p2, ...., pn and the following abbreviations will be used for the propositional connectives: The input will be a compound proposition fully parenthesized. More specifically, the input will be a well-formed formula that adheres to the following definition. (p0), (p1), (p2), .... are all well-formed formulas. If phi and psi are well-formed formulas, so are (phi and psi), (phi or psi), (phi rightarrow psi), (phi doubheaded arrow psi), (phi) (Look at the section Recursive Definitions and Structural Induction in your textbook for a more detailed explanation.) Your output should be the truth table for that proposition. E.g. If the proposition is (p rightarrow (q or r)), your input string would be (Trust me, as ugly as this looks it will make your parsing a lot easier). The output for this should be Your program should be able to handle an arbitrary number of propositional variables. Do not use an "eval" type function, even if your language has one.Explanation / Answer
#include #include #include #define MAX_TOKEN_STRING_LENGTH 200 #define MAX_BUFF 200 #define MAX_CODE 200 #define MAX_OUTPUT_BUFF 200 typedef enum { false, true } BOOL; char ch; // The next character BOOL cont, debug, min, showcode; jmp_buf start; // On error: empty stack and go to start BOOL exists_false, exists_true; // For the synopsis // Input buffer stuff char buff[ MAX_BUFF ]; // Input buffer storage char opvalues[ MAX_BUFF ]; // Truth value of each opeator in formula int opindex[ MAX_BUFF ]; // Cross-index of operators infix/postfix int bufferpointer; // Keep a count, so we can point to error // Output buffer char obuff[ MAX_OUTPUT_BUFF ]; int obuffpointer; int used, truevars; // Sets char code[MAX_CODE]; // Code to be evaluated int codeindex; // This idea for how to extract tokens is from // Mak, R. (1991). Writing compilers and interpreters. An applied approach. // Brisbane: John Wiley & Son, Inc; char token_string[MAX_TOKEN_STRING_LENGTH]; // Token string char *tokenp = token_string; // Token string pointer /*----------------------------------------------------------------------------*/ /* Function declarations */ /*----------------------------------------------------------------------------*/ void factor(); void term(); void expression(); void formula(); int gen( char c ); void get_token(); void get_word(); void get_char(); void printoutputbuffer(); void printinputbuffer(); void printopvalues(); void printresult(BOOL r); void printused(); void printcode(); void output(); void error( char* e ); // Helper functions BOOL in( char element, int set ); // Is element represented in set? BOOL atom( char c ); // Is c an atom? /*----------------------------------------------------------------------------*/ /* Application logic */ /*----------------------------------------------------------------------------*/ void factor() { int bp; if ( atom( ch ) ) { // put ch into the set of used atoms used = used | (1Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.