Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string>
- #include <vector>
- #include <iostream>
- using namespace std;
- #include <exception>
- class uninitialized_variable: public exception
- {
- virtual const char* what() const throw()
- {
- return "Uninitialized variable.";
- }
- }uninitialized_variable;
- #include "symboltable.h"
- void SymbolTable::insert(string variable, double value)
- {
- const Symbol& symbol = Symbol(variable, value, false);
- elements.push_back(symbol);
- }
- double SymbolTable::lookUp(string variable) const
- {
- for (int i = 0; i < elements.size(); i++)
- if (elements[i].variable == variable)
- {
- elements[i].used = true;
- return elements[i].value;
- }
- throw uninitialized_variable;
- }
- void SymbolTable::unusedVariableCheck()
- {
- for (int i = 0; i < elements.size(); i++)
- if (elements[i].used == true)
- cout << "Warning variable " << variables[i] << " unused." << endl;
- }
Add Comment
Please, Sign In to add comment