This repository has been archived on 2024-03-07. You can view files and clone it, but cannot push or open issues/pull-requests.
wongola/lib/Parser.hpp

40 lines
850 B
C++
Raw Normal View History

#ifndef wg_PARSER_HPP
#define wg_PARSER_HPP
#include "commons.hpp"
#include "Node.hpp"
namespace wg
{
WG_ERROR(syntax_error);
class Parser
{
public:
explicit Parser();
virtual ~Parser();
std::shared_ptr<Node> parse(std::vector<std::shared_ptr<Node>>
const& tokens);
private:
std::vector<std::shared_ptr<Node>> m_tokens;
size_t m_cursor;
Loc loc() const;
std::shared_ptr<Node> consume(NodeType type);
std::shared_ptr<Node> consume();
bool type_is(NodeType type, int lookahead=0);
bool type_isnt(NodeType type, int lookahead=0);
std::shared_ptr<Node> make_node(NodeType type) const;
std::shared_ptr<Node> parse_prog();
std::shared_ptr<Node> parse_instr();
std::shared_ptr<Node> parse_dir();
std::shared_ptr<Node> parse_expr();
};
}
#endif