#ifndef muz_PARSER_HPP #define muz_PARSER_HPP #include "commons.hpp" #include "Lexer.hpp" namespace muz { MUZ_ERROR(syntax_error); /** * Build an AST given a token list. * @see Node * @see Lexer **/ class Parser { public: explicit Parser(); virtual ~Parser(); std::shared_ptr parse(Lexer& lexer); private: std::vector> m_tokens; size_t m_cursor = 0; int current_line(); std::shared_ptr consume(std::optional type=std::nullopt); NodeType peek(size_t lookahead=0) const; bool next_is(NodeType type, size_t lookahead=0) const; std::shared_ptr parse_prog(); std::shared_ptr parse_instr(); std::shared_ptr parse_dir(); std::shared_ptr parse_cmd(); std::shared_ptr parse_arg(); std::shared_ptr parse_literal(); }; } #endif