init
This commit is contained in:
66
parser.h
Normal file
66
parser.h
Normal file
@@ -0,0 +1,66 @@
|
||||
#ifndef CAMELLYA_PARSER_H
|
||||
#define CAMELLYA_PARSER_H
|
||||
|
||||
#include "lexer.h"
|
||||
#include "ast.h"
|
||||
#include <stdexcept>
|
||||
|
||||
namespace camellya {
|
||||
|
||||
class ParseError : public std::runtime_error {
|
||||
public:
|
||||
explicit ParseError(const std::string& message) : std::runtime_error(message) {}
|
||||
};
|
||||
|
||||
class Parser {
|
||||
public:
|
||||
explicit Parser(std::vector<Token> tokens);
|
||||
|
||||
Program parse();
|
||||
|
||||
private:
|
||||
std::vector<Token> tokens_;
|
||||
size_t current_ = 0;
|
||||
|
||||
// Utility methods
|
||||
Token peek() const;
|
||||
Token previous() const;
|
||||
bool is_at_end() const;
|
||||
Token advance();
|
||||
bool check(TokenType type) const;
|
||||
bool match(std::initializer_list<TokenType> types);
|
||||
Token consume(TokenType type, const std::string& message);
|
||||
|
||||
ParseError error(const Token& token, const std::string& message);
|
||||
void synchronize();
|
||||
|
||||
// Parsing methods
|
||||
StmtPtr declaration();
|
||||
StmtPtr class_declaration();
|
||||
StmtPtr function_declaration();
|
||||
StmtPtr var_declaration();
|
||||
StmtPtr statement();
|
||||
StmtPtr if_statement();
|
||||
StmtPtr while_statement();
|
||||
StmtPtr for_statement();
|
||||
StmtPtr return_statement();
|
||||
StmtPtr block_statement();
|
||||
StmtPtr expression_statement();
|
||||
|
||||
ExprPtr expression();
|
||||
ExprPtr assignment();
|
||||
ExprPtr logical_or();
|
||||
ExprPtr logical_and();
|
||||
ExprPtr equality();
|
||||
ExprPtr comparison();
|
||||
ExprPtr term();
|
||||
ExprPtr factor();
|
||||
ExprPtr unary();
|
||||
ExprPtr call();
|
||||
ExprPtr primary();
|
||||
ExprPtr finish_call(ExprPtr callee);
|
||||
};
|
||||
|
||||
} // namespace camellya
|
||||
|
||||
#endif // CAMELLYA_PARSER_H
|
||||
Reference in New Issue
Block a user