Home /
Expert Answers /
Computer Science /
this-file-contains-the-class-definition-of-the-symboltable-class-the-symbol-table-is-represente-pa255
(Solved): // This file contains the class definition of the SymbolTable class. The symbol table is represente ...
// This file contains the class definition of the SymbolTable class. The symbol table is represented // with a vector (list) of type symbol which is a pair consisting of a variable and its associated value. // The body of its functions are defined in symboltable.cpp. class SymbolTable \\{ public: SymbolTable() \\{\\} void insert(string variable, double value); double lookUp(string variable) const; private: struct Symbol \\{ Symbol(string variable, double value) \\{ this \\( > \\) variable \\( = \\) variable; \\} this \\( \\rightarrow \\) value = value; string variable; \\}; double value; vector elements; ; ; // This file contains the body of the functions contained in The SymbolTable class. The insert function // inserts a new variable symbol and its value into the symbol table and the lookUp function returns // that value of the supplied variable symbol name. \\#include \\#include using namespace std; \\#include \"symboltable.h\" void SymbolTable::insert(string variable, double value) \\{ const Symbol\\& symbol = Symbol (variable, value); \\} elements.push_back(symbol); double SymbolTable: :lookUp(string variable) const \\{ for (int \\( i=0 ; i< \\) elements.size(); \\( i++ \\) ) if (elements \\( [i] \\).variable \\( == \\) variable) return elements [i].value; \\} return -1 ; // This file contains the class definition of the Variable class. The variable is represented by its // name, which the construcor initializes. Because this class is a subclass of Operand which in turn is // a subclass of Expression, it must implement the function evaluate, whose body is defined in // variable.cpp. class Variable: public Operand \\{ public: Variable(string name) \\{ \\} this->name \\( = \\) name; double evaluate(); private: string name; ; ; // This file contains the body of the function contained in The Variable class. The evaluate function // looks up te value of a variable in the symbol table and returns that value. \\#include \\#include using namespace std; \\#include \"expression.h\" \\#include \"operand.h\" \\#include \"variable.h\" \\#include \"symboltable.h\" extern SymbolTable symbolTable; double Variable: :evaluate() \\{ \\} return symbolTable. lookUp(name); // This file contains the input (input.txt) \\( (x+y), x=2, y=6 ; \\) \\( (x-y) x=2 \\quad y=6 \\)