muzgen/lib/Parser.hpp

44 lines
892 B
C++

#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<Node> parse(Lexer& lexer);
private:
std::vector<std::shared_ptr<Node>> m_tokens;
size_t m_cursor = 0;
int current_line();
std::shared_ptr<Node> consume(std::optional<NodeType> type=std::nullopt);
NodeType peek(size_t lookahead=0) const;
bool next_is(NodeType type, size_t lookahead=0) const;
std::shared_ptr<Node> parse_prog();
std::shared_ptr<Node> parse_instr();
std::shared_ptr<Node> parse_dir();
std::shared_ptr<Node> parse_cmd();
std::shared_ptr<Node> parse_arg();
std::shared_ptr<Node> parse_literal();
};
}
#endif