Guest User

Untitled

a guest
Jan 23rd, 2018
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #include <string>
  2. #include <vector>
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. #include <exception>
  7.  
  8. class uninitialized_variable: public exception
  9. {
  10. virtual const char* what() const throw()
  11. {
  12. return "Uninitialized variable.";
  13. }
  14. }uninitialized_variable;
  15.  
  16. #include "symboltable.h"
  17.  
  18.  
  19. void SymbolTable::insert(string variable, double value)
  20. {
  21. const Symbol& symbol = Symbol(variable, value);
  22. elements.push_back(symbol);
  23. variables.push_back(variable);
  24. }
  25.  
  26. double SymbolTable::lookUp(string variable) const
  27. {
  28. for (int i = 0; i < elements.size(); i++)
  29. if (elements[i].variable == variable)
  30. {
  31. for (int j = 0; j < variables.size(); j++)
  32. if (variables[j] == variable)
  33. variables.erase (j);
  34. return elements[i].value;
  35. }
  36. throw uninitialized_variable;
  37. }
  38.  
  39. void SymbolTable::unusedVariableCheck()
  40. {
  41. for (int i = 0; i < variables.size(); i++)
  42. cout << "Warning variable " << variables[i] << " unused." << endl;
  43. }
Add Comment
Please, Sign In to add comment