-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParser.h
59 lines (43 loc) · 1.3 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
#ifndef _PARSER
#define _PARSER
#include <stdio.h>
#include <map>
#include "Token.h"
//#include "Compiler.h"
#include "Expressions.h"
#include "Parselets.h"
#include "Lexer.h"
//#include "JetExceptions.h"
#include <deque>
namespace Jet
{
class Parser
{
Lexer* lexer;
std::map<TokenType, InfixParselet*> mInfixParselets;
std::map<TokenType, PrefixParselet*> mPrefixParselets;
std::map<TokenType, StatementParselet*> mStatementParselets;
std::deque<Token> mRead;
DiagnosticBuilder* diag;
public:
std::string filename;
Parser(Lexer* l, DiagnosticBuilder* diag);
~Parser();
Expression* ParseExpression(int precedence = 0);
Expression* ParseStatement(bool takeTrailingSemicolon = true);//call this until out of tokens (hit EOF)
BlockExpression* ParseBlock(bool allowsingle = true);
BlockExpression* ParseAll();
int GetPrecedence();
Token Consume();
Token Consume(TokenType expected);
Token ConsumeTemplateGT();
Token LookAhead(unsigned int num = 0);
void Error(const std::string& error, const Token& token);
bool Match(TokenType expected);
bool MatchAndConsume(TokenType expected);
void Register(TokenType token, InfixParselet* parselet);
void Register(TokenType token, PrefixParselet* parselet);
void Register(TokenType token, StatementParselet* parselet);
};
}
#endif