Parser.hpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #if !defined(Parser_HPP)
  2. #define Parser_HPP
  3. #include "Util.hpp"
  4. #include "ParserTokens.hpp"
  5. #include "Class.hpp"
  6. #include <unordered_map>
  7. //from main.cpp
  8. extern bool parser_exit;
  9. extern bool system_allowed;
  10. //most comments in Parser.cpp
  11. class Parser
  12. {
  13. private:
  14. void define(const string &identifier);
  15. inline bool is_defined(const string& identifier) {return (classes.find(identifier) != classes.end());}
  16. void array();
  17. void declare();
  18. void declare_library();
  19. void recursive();
  20. Class *current_class;
  21. ParserTokenKind temp_type;
  22. void void_function(); //expects '(' ')' with nothing inside
  23. ParserToken string_function(); //expects '(' STRING_LITERAL ')' and then returns the STRING_LITErAL token
  24. bool special_case(); //`type` and `link`
  25. bool object_method(); //all object methods
  26. string child;
  27. private:
  28. ParserToken current;
  29. vector<ParserToken> tokens;
  30. std::unordered_map<string, Class*> classes;
  31. int32_t index = -1; //will be incremented to 0
  32. inline const ParserToken next() {
  33. return tokens[++index];
  34. }
  35. //there are MANY better ways of doing this... but i'm lazy
  36. bool expect_bool();
  37. void expect_type();
  38. void expect(ParserTokenKind type);
  39. void expect(ParserTokenKind type, ParserTokenKind type2);
  40. void expect_and_then(ParserTokenKind type, ParserTokenKind type2);
  41. void expect(ParserTokenKind type, ParserTokenKind type2, ParserTokenKind type3);
  42. void expect(ParserTokenKind type, ParserTokenKind type2, ParserTokenKind type3, ParserTokenKind type4);
  43. void expect(ParserTokenKind type, ParserTokenKind type2, ParserTokenKind type3, ParserTokenKind type4, ParserTokenKind type5);
  44. void parse(); //called from constructor, should be rewritten to not do that
  45. public:
  46. Parser(const string& file_name);
  47. ~Parser();
  48. };
  49. #endif