main.cxx 741 B

123456789101112131415161718192021222324252627282930313233343536
  1. //
  2. // main.cpp
  3. // dice-roll
  4. //
  5. // Created by Sam Jaffe on 12/1/18.
  6. // Copyright © 2018 Sam Jaffe. All rights reserved.
  7. //
  8. #include "die.h"
  9. #include "exception.h"
  10. #include "roll.h"
  11. #include <iostream>
  12. #include <sstream>
  13. void eval(std::string const & str) {
  14. try {
  15. std::stringstream ss(str);
  16. dice::dice d;
  17. ss >> d;
  18. dice::roll(d);
  19. } catch (dice::unexpected_token const & ut) {
  20. std::cerr << "Error in roll: '" << str << "': " << ut.what() << "\n";
  21. std::cerr << " " << ut.pointer(str.size()+1) << std::endl;
  22. }
  23. }
  24. int main(int argc, const char * argv[]) {
  25. std::string line;
  26. std::cout << "> ";
  27. while (std::getline(std::cin, line)) {
  28. eval(line);
  29. std::cout << "> ";
  30. }
  31. return 0;
  32. }