The goal of this homework is to practice the builder patern and visitor patern. In
the lecture, you are given an example of parsing a string of a binary expression using
the builder patter. In that example, al nodes are of the same clas Node, which has
two pointers, m_leftChild and _rightChild. This causes eory waste because al
terminal nodes also have these two data members although they have no children.
Also, it does not have a visitor that can calculate the value of the binary expression.
In this project, you ned to design and implement clases to implement the folowing
functionalities:
1. Using the builder patern, given a binary expresion as a string, your program can
construct a binary expression tree using two types of nodes: terminal nodes, which
have no children data members, and nonterminal nodes, which have children data
members. You can refer to the example code in the lecture and Homework 12.
2. You need to develop a visitor that can calculate the value of a binary expression
tree. You may need to use a stack. You may need a function such as istringstream()
to convert a string to a value.
3. You need to develop classes so that the folowing main() function wil produce the
folowing output. Note that both the terminal node clas and the nonterminal clas
need to have print operations so that they can be used to print out the binary
expression tree.
int main(int argc, char** argv) {
ExpBuilder builder;
ExpParser parser;
parser.setBuilder(&builder);
string input="((30+50)*70)-(60/50))";
parser.parse(input);
Node* rot = builder.getExpresion();
coutprint();
StackBasedCalVisitor sbsv;
root->Acept(&sbsv);
cout
}
Output:
(((30+50)*70)-(60/50)
(((30+50)*70)-(60/50)
StackBasedSumVisitor Result: 37098.8
Due: March 2, 1:59PM, 2018.
Turn in one file via handin: the zip file of your whole NetBean directory. No UML. The
name of your zip file should be: LastName_FirstName.zip. For example, if your name
is John Smith, you should turn in one files: Smith_John.zip.