-
Notifications
You must be signed in to change notification settings - Fork 3
/
parser.h
72 lines (55 loc) · 1.92 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
#ifndef VAIVEN_HEADER_PARSER
#define VAIVEN_HEADER_PARSER
#include <memory>
#include <string>
#include "tokenizer.h"
#include "ast/all.h"
using std::unique_ptr;
using std::string;
namespace vaiven {
class ParseError;
class Parser {
public:
Parser(Tokenizer& tokenizer)
: tokenizer(tokenizer), current(tokenizer.next()), newlineReplacement(TOKEN_TYPE_SEMICOLON),
errorLocation("top level"), ignoreNextNext(false) {}
unique_ptr<ast::Node<> > parseLogicalGroup();
unique_ptr<ast::FuncDecl<> > parseFuncDecl();
unique_ptr<ast::Statement<> > parseStatement();
unique_ptr<ast::Statement<> > parseControlStatement();
unique_ptr<ast::Block<> > parseBlock();
unique_ptr<ast::VarDecl<> > parseVarDecl();
unique_ptr<ast::IfStatement<> > parseIfStatement();
unique_ptr<ast::ForCondition<> > parseForCondition();
unique_ptr<ast::ReturnStatement<> > parseReturnStatement();
unique_ptr<ast::ExpressionStatement<> > parseExpressionStatement();
unique_ptr<ast::Expression<> > parseExpression();
unique_ptr<ast::Expression<> > parseAssignmentExpression();
unique_ptr<ast::Expression<> > parseEqualityExpression();
unique_ptr<ast::Expression<> > parseComparisonExpression();
unique_ptr<ast::Expression<> > parseAddSubExpression();
unique_ptr<ast::Expression<> > parseDivMulExpression();
unique_ptr<ast::Expression<> > parseAccess();
unique_ptr<ast::Expression<> > parseValue();
// Store this on the parser rather than using a visitor
// to keep interpreter workflow fast
bool lastLogicalGroupWasEvaluatable;
vector<ParseError> errors;
private:
bool ignoreNextNext;
void next();
void nextNoEol();
void nextOr(TokenType newlineType);
Tokenizer& tokenizer;
unique_ptr<Token> current;
TokenType newlineReplacement;
string errorLocation;
};
class ParseError {
public:
string error;
string location;
ParseError(string error, string location) : error(error), location(location) {}
};
}
#endif