-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParser.h
61 lines (52 loc) · 1.19 KB
/
Parser.h
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
#pragma once
#include "Token.h"
#include "Expr/Expr.h"
#include "Stmt.h"
#include <exception>
#include <vector>
class ParseError : public std::exception
{};
class Parser
{
private:
std::vector<Token> _tokens;
uint32_t _current = 0;
const uint32_t MAX_ARGUMENTS = 255;
public:
Parser(std::vector<Token> tokens);
~Parser() = default;
std::vector<StmtPtr> Parse();
private:
void Synchronize();
StmtPtr Declaration();
StmtPtr VarDeclaration();
StmtPtr Statement();
StmtPtr ForStatement();
StmtPtr ReturnStatement();
StmtPtr IfStatement();
StmtPtr PrintStatement();
StmtPtr WhileStatement();
StmtPtr ExpressionStatement();
StmtPtr FunctionStatement(std::string kind);
std::vector<StmtPtr> Block();
bool Match(std::vector<TokenType> types);
bool Check(TokenType type);
Token Advance();
bool IsAtEnd();
Token Peek();
Token Previous();
ParseError Error(Token token, std::string message);
Token Consume(TokenType type, std::string message);
ExprPtr Term();
ExprPtr Factor();
ExprPtr Unary_();
ExprPtr Primary();
ExprPtr Expression();
ExprPtr Assignment();
ExprPtr Or();
ExprPtr And();
ExprPtr Equality();
ExprPtr Comparison();
ExprPtr CallExpr();
ExprPtr FinishCall(ExprPtr callee);
};