2023-09-27 18:18:05 +00:00
|
|
|
#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();
|
2023-09-28 19:37:10 +00:00
|
|
|
std::shared_ptr<Node> parse_extern();
|
|
|
|
std::shared_ptr<Node> parse_fundecl();
|
|
|
|
std::shared_ptr<Node> parse_params();
|
|
|
|
std::shared_ptr<Node> parse_ret();
|
|
|
|
std::shared_ptr<Node> parse_block();
|
2023-09-27 18:18:05 +00:00
|
|
|
std::shared_ptr<Node> parse_dir();
|
2023-09-28 19:37:10 +00:00
|
|
|
|
2023-09-27 18:18:05 +00:00
|
|
|
std::shared_ptr<Node> parse_expr();
|
2023-09-29 18:11:39 +00:00
|
|
|
std::shared_ptr<Node> parse_or();
|
|
|
|
std::shared_ptr<Node> parse_and();
|
|
|
|
|
|
|
|
std::shared_ptr<Node> parse_eqne();
|
|
|
|
std::shared_ptr<Node> parse_cmp();
|
2023-09-27 18:18:05 +00:00
|
|
|
|
2023-09-27 21:05:04 +00:00
|
|
|
std::shared_ptr<Node> parse_addsub();
|
|
|
|
std::shared_ptr<Node> parse_muldivmod();
|
|
|
|
std::shared_ptr<Node> parse_literal();
|
2023-09-28 19:37:10 +00:00
|
|
|
std::shared_ptr<Node> parse_call();
|
|
|
|
std::shared_ptr<Node> parse_args();
|
|
|
|
|
2023-09-29 09:18:03 +00:00
|
|
|
std::shared_ptr<Node> parse_ns();
|
|
|
|
|
2023-09-27 18:18:05 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|