-
Notifications
You must be signed in to change notification settings - Fork 0
/
Parser.hpp
65 lines (58 loc) · 1.83 KB
/
Parser.hpp
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
54
55
56
57
58
59
60
61
62
63
64
// Copyright 2020-1-29 <Copyright hulin>
#ifndef PARSER_HPP_
#define PARSER_HPP_
#include <vector>
#include <memory>
#include <string>
#include <stdexcept>
#include <initializer_list>
#include "./Token.hpp"
#include "./Expr.hpp"
#include "./Stmt.hpp"
using std::vector;
using std::shared_ptr;
using std::initializer_list;
using std::string;
using std::runtime_error;
class Parser {
public:
explicit Parser(vector<Token> tokens_): tokens(tokens_) { }
vector<shared_ptr<Stmt>> parse();
private:
vector<Token> tokens;
int current = 0;
shared_ptr<Expr<Object>> assignment();
shared_ptr<Expr<Object>> orSmt();
shared_ptr<Expr<Object>> andSmt();
shared_ptr<Expr<Object>> expression();
shared_ptr<Expr<Object>> equality();
shared_ptr<Expr<Object>> comparison();
shared_ptr<Expr<Object>> addition();
shared_ptr<Expr<Object>> multiplication();
shared_ptr<Expr<Object>> unary();
shared_ptr<Expr<Object>> finishCall(shared_ptr<Expr<Object>> callee);
shared_ptr<Expr<Object>> call();
shared_ptr<Expr<Object>> primary();
bool match(const initializer_list<TokenType> &types);
bool check(TokenType type);
Token advance();
bool isAtEnd();
Token peek();
Token previous();
Token consume(TokenType type, string message);
runtime_error error(Token token, string message);
void synchronize();
shared_ptr<Stmt> statement();
shared_ptr<Stmt> forStatement();
shared_ptr<Stmt> ifStatement();
shared_ptr<Stmt> whileStatement();
shared_ptr<Stmt> printStatement();
shared_ptr<Stmt> returnStatement();
shared_ptr<Stmt> expressionStatement();
shared_ptr<Function> function(string kind);
shared_ptr<Stmt> declaration();
shared_ptr<Stmt> classDeclaration();
shared_ptr<Stmt> varDeclaration();
vector<shared_ptr<Stmt>> block();
};
#endif // PARSER_HPP_