#ifndef PARSER_HH #define PARSER_HH #include "expr.hh" #include "stmt.hh" #include "../tokenizer.hh" #include #include #include struct ParseException : public std::exception { ParseException() : message{""} {} ParseException(const std::string& message) : message{message} {} const char* what() const noexcept override { return message.c_str(); } private: std::string message; }; struct Parser { Parser(std::vector tokens) : tokens{tokens} {} std::vector parse(); Stmt declaration(); Stmt var_declaration(); Stmt statement(); std::vector block_statement(); Stmt print_statement(); Stmt expression_statement(); Expr expression(); Expr assignment(); Expr equality(); Expr comparison(); Expr term(); Expr factor(); Expr unary(); Expr primary(); Token advance(); Token peek(); Token previous(); Token consume(TokenType type, std::string &&message); bool match(std::vector types); bool check(TokenType type); bool is_at_end(); ParseException error(Token token, std::string &message); ParseException error(Token token, std::string &&message); void synchronize(); std::vector tokens; size_t current = 0; }; #endif