Question: (C++) Given a valid vector string of a boolean characters, like T => F ^ (F v F), complete the function which breaks these up
(C++)
Given a valid vector string of a boolean characters, like "T => F ^ (F v F)", complete the function which breaks these up into a tree. I am giving all the structs but I only need help with the specific function I am asking about. There needs to be about 7 helper functions for this function. Please only write one function and then detailed psudeocode for the others. I know I need to use recursive decent, and I need several helper functions to help parse the string into its parts, but I am having a hard understanding this all.
Must use the following structs:
typedef struct tree* t_node;
struct tree{string temp; t_node child[2];};
struct tok{ bool success; vector
Here are two functions which should help make this quick. The first allows you to print the tree.
void prinTree(tree T) {
cout << endl; // If both children are NULL, just print the symbol if (T.child[0] == NULL) { cout << T.temp; return; } cout << "(" << T.temp<< " "; prinTree(*(T.child[0])); cout << " ";
if (T.child[1] != NULL) prinTree(*(T.child[1])); cout << ")"; }
pNODE cons(string s, pNODE c1, pNODE c2) { pNODE ret = new tree; ret->info = s; // same as (*ret).info = s ret->child[0] = c1; ret->child[1] = c2; return ret;
}
The function to complete is this:
result parse(vector
//complete
}
Rule information:
A Boolean constant is ["T"] or ["F"].
An unbreakable expression is either a Boolean constant, or ["("] followed by a Boolean expression followed by [")"].
A negation is either an unbreakable expression, or ["~"] followed by a negation.
A conjunction is either a negation, or a conjunction followed by ["^"] followed by a negation.
A disjunction is either a conjunction, or a disjunction followed by ["v"] followed by a conjunction.
An implication is either a disjunction, or a disjunction followed by ["=>"] followed by an implication.
A Boolean expression is either an implication, or an implication followed by ["<=>"] followed by a Boolean expression.
This grammar can be formalized in BNF notation as follows:
Const "T" | "F"
U Const | "(" B ")"
N U | "~" N
C N | C "^" N
D C | D "v" C
I D | D "=>" I
B I | I "<=>" B
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
