-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.hpp
More file actions
53 lines (45 loc) · 1.31 KB
/
parser.hpp
File metadata and controls
53 lines (45 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#pragma once
#include <algorithm>
#include <memory>
#include <string>
#include <vector>
#include <stdexcept>
#include "scanner.hpp"
#include "expr.hpp"
#include "debug.hpp"
#include "visitor.hpp"
#include "stmt.hpp"
class Parser{
private:
struct ParseError: public std::runtime_error{
using std::runtime_error::runtime_error;
};
const std::vector<Token> tokens;
int current = 0;
ParseError error(const Token&, const std::string&);
void synchronize();
bool isAtEnd();
bool check(const TokenType&);
template<class...T>
bool match(T...types);
Token previous();
Token peek();
Token advance();
Token consume(const TokenType&, const std::string&);
std::shared_ptr<Expr> expression();
std::shared_ptr<Expr> equality();
std::shared_ptr<Expr> comparison();
std::shared_ptr<Expr> term();
std::shared_ptr<Expr> factor();
std::shared_ptr<Expr> unary();
std::shared_ptr<Expr> primary();
std::shared_ptr<Expr> assignment();
std::shared_ptr<Statement::Stmt> statement();
std::shared_ptr<Statement::Stmt> printStatement();
std::shared_ptr<Statement::Stmt> expressionStatement();
std::shared_ptr<Statement::Stmt> assignmentStatement();
std::shared_ptr<Statement::Stmt> declaration();
public:
Parser(const std::vector<Token>&);
std::vector<std::shared_ptr<Statement::Stmt>> parser();
};