parser.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. Parser functions and class definitions for malio interpreter
  3. For details on specifications of the Malio language, please see:
  4. https://notabug.org/Malio
  5. Copyright 2015 - Malio dev team
  6. This file is part of malio-cpp
  7. malio-cpp is free software: you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation, either version 3 of the License, or
  10. (at your option) any later version.
  11. malio-cpp is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <iostream>
  19. #include <string>
  20. #include <fstream>
  21. #include <vector>
  22. #include <map>
  23. #ifndef PARSER_H
  24. #define PARSER_H
  25. namespace malio {
  26. // shorthand function that will read the contents of a file:
  27. int read(std::string filename);
  28. // line-by-line parser
  29. std::tuple<std::string, std::string> parse(std::string line);
  30. // -- Exceptions raised by the interpreter:
  31. // basic exception class: contains solely a string indicating what
  32. // kind of error happened.
  33. class Exception {
  34. public:
  35. Exception(std::string err);
  36. protected:
  37. std::string errortype;
  38. };
  39. // a generic syntax error for malformed statements
  40. class SyntaxError : public Exception {
  41. public:
  42. SyntaxError(std::string what);
  43. private:
  44. std::string explanation;
  45. };
  46. // error raised when an undeclared name is mentioned, and is not from the
  47. // malio builtins.
  48. class NameError : public Exception {
  49. public:
  50. NameError(std::string what);
  51. private:
  52. std::string explanation;
  53. };
  54. } // namespace malio
  55. #endif