-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.h
87 lines (61 loc) · 2.4 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
77
78
79
80
81
82
83
84
85
86
87
#ifndef PARSER_BUNNY_H
#define PARSER_BUNNY_H
#include <vector>
#include <string>
#include <unordered_map>
#include "lexer.h"
#include "ast.h"
#include "precedences.h"
namespace bunny
{
class Parser
{
public:
Parser(lexer &_lex);
std::vector<std::string> getErrors() {return this->errors; };
Program *parseProgram();
private:
//Functions
typedef Expression* (Parser::*PrefixParse)();
typedef Expression* (Parser::*InfixParse)(Expression *);
void nextToken();
bool expectedPeek(const tokenType &_type);
precedenza currentPrec();
precedenza peekPrec();
//Statements
Statement *parseStatement();
VarStatement *parseVarStatement();
ReferenceStatement *parseRefStatement();
ReturnStatement *parseReturnStatement();
ExpressionStatement *parseExpressionStatement();
BlockStatement *parseBlockStatement();
//Expression
Expression *parseExpression(precedenza _prec);
Expression *parseIdentifier();
Expression *parseIntegerLiteral();
Expression *parseStringLiteral();
Expression *parsePrefixExpression();
Expression *parseBoolean();
std::vector<Identifier*> parseFunctionArguments();
Expression *parseFunctionLiteral();
Expression *parseArrayLiteral();
Expression *parseGroupedExpressions();
Expression *parseIfExpression();
Expression *parseWhileExpression();
std::vector<Expression*> parseExpressionList();
Expression *parseCallExpression(Expression *func);
Expression *parseIndexExpression(Expression *arr);
Expression *parseInfixExpression(Expression *left);
void missingPrefixFunctionError(tokenType type);
void peekError(const tokenType &_type);
//Variables
lexer lex;
Token currentToken;
Token peekedToken;
//We associate the different tokenTypes their type of parsing
std::unordered_map<tokenType, PrefixParse> prefixParseFuncs;
std::unordered_map<tokenType, InfixParse> InfixParseFuncs;
std::vector<std::string> errors;
};
}
#endif // PARSER_BUNNY_H