-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParser.h
76 lines (71 loc) · 2.54 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#ifndef PARSER_H
#define PARSER_H
#include "Expression.h"
#include "Expressions/Assign.h"
#include "Expressions/Binary.h"
#include "Expressions/Grouping.h"
#include "Expressions/Literal.h"
#include "Expressions/Logical.h"
#include "Expressions/Unary.h"
#include "Expressions/Variable.h"
#include "Statement.h"
#include "Statements/Block.h"
#include "Statements/ExpressionStmnt.h"
#include "Statements/If.h"
#include "Statements/Print.h"
#include "Statements/Move.h"
#include "Statements/Copy.h"
#include "Statements/Remove.h"
#include "Statements/Find.h"
#include "Statements/FindSame.h"
#include "Statements/Var.h"
#include "Statements/While.h"
interface IParser {
public:
virtual Array<std::shared_ptr<Statement>> parse() = 0;
};
class Parser : public IParser {
public:
explicit Parser(Array<Token> tokens);
Array<std::shared_ptr<Statement>> parse() override;
private:
std::shared_ptr<Statement> statement();
std::shared_ptr<Statement> ifStatement();
std::shared_ptr<Statement> whileStatement();
Array<std::shared_ptr<Statement>> block();
std::shared_ptr<Statement> printStatement();
std::shared_ptr<Statement> moveStatement();
std::shared_ptr<Statement> copyStatement();
std::shared_ptr<Statement> removeStatement();
std::shared_ptr<Statement> findStatement();
std::shared_ptr<Statement> find_sameStatement();
std::shared_ptr<Statement> expressionStatement();
std::shared_ptr<Statement> declaration();
std::shared_ptr<Statement> floatVarDeclaration();
std::shared_ptr<Statement> intVarDeclaration();
std::shared_ptr<Statement> stringVarDeclaration();
std::shared_ptr<Statement> charVarDeclaration();
std::shared_ptr<Statement> fileVarDeclaration();
std::shared_ptr<Statement> boolVarDeclaration();
std::shared_ptr<Expression> expression();
std::shared_ptr<Expression> assignment();
std::shared_ptr<Expression> equality();
bool match(std::initializer_list<TokenType> types);
bool check(TokenType type) const;
Token advance();
bool isAtEnd() const;
Token peek() const;
Token previous() const;
std::shared_ptr<Expression> comparison();
std::shared_ptr<Expression> addition();
std::shared_ptr<Expression> multiplication();
std::shared_ptr<Expression> unary();
std::shared_ptr<Expression> primary();
std::shared_ptr<Expression> OR();
std::shared_ptr<Expression> AND();
Token consume(TokenType type, const String& message);
void error(const Token& token, const String& message) const;
Array<Token> tokens{};
int current{};
};
#endif