Guest User

Untitled

a guest
Jan 23rd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 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, false);
  22. elements.push_back(symbol);
  23. }
  24.  
  25. double SymbolTable::lookUp(string variable) const
  26. {
  27. for (int i = 0; i < elements.size(); i++)
  28. if (elements[i].variable == variable)
  29. {
  30. elements[i].used = true;
  31. return elements[i].value;
  32. }
  33. throw uninitialized_variable;
  34. }
  35.  
  36. void SymbolTable::unusedVariableCheck()
  37. {
  38. for (int i = 0; i < elements.size(); i++)
  39. if (elements[i].used == true)
  40. cout << "Warning variable " << variables[i] << " unused." << endl;
  41. }
Add Comment
Please, Sign In to add comment