40 lines
850 B
C++
40 lines
850 B
C++
|
#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
|