-
Notifications
You must be signed in to change notification settings - Fork 8
/
Parser.hpp
61 lines (39 loc) · 1.46 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
#pragma once
#include "Tokenizer.hpp"
#include "Type.hpp"
#include "FunctionDefinition.hpp"
#include "Statement.hpp"
#include <optional>
#include <string>
#include <map>
#include <vector>
namespace simpleparser {
using namespace std;
class Parser {
public:
Parser();
void parse(vector<Token> &tokens);
void debugPrint() const;
map<string, FunctionDefinition> GetFunctions() const { return mFunctions; }
private:
optional<Type> expectType();
//! Empty string means match any identifier.
optional<Token> expectIdentifier(const string& name = string());
//! Empty string means match any operator.
optional<Token> expectOperator(const string& name = string());
bool expectFunctionDefinition();
vector<Token>::iterator mCurrentToken;
vector<Token>::iterator mEndToken;
map<string, Type> mTypes;
map<string, FunctionDefinition> mFunctions;
optional<vector<Statement>> parseFunctionBody();
optional<Statement> expectOneValue();
optional<Statement> expectWhileLoop();
optional<Statement> expectStatement();
optional<Statement> expectVariableDeclaration();
optional<Statement> expectFunctionCall();
optional <Statement> expectExpression();
size_t operatorPrecedence(const string &operatorName);
Statement *findRightmostStatement(Statement *lhs, size_t rhsPrecedence);
};
}