-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.h
44 lines (38 loc) · 1.43 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
#pragma once
#include <list>
#include "token.h"
#include "astNode.h"
#include "util/tokenUtil.h"
class Parser {
public:
explicit Parser(std::list<Token> & tokens);
ASTNode * parse();
private:
std::list<Token> & tokens;
std::list<Token>::iterator tokenIterator;
ASTNode * root;
Token t;
void next();
void expect(const TokenType & type);
TokenType lookahead(int amount);
void reject(std::string const & str);
// Non-terminals
ASTNode * program(); // { <function> | <declaration> }
ASTNode * declaration();
ASTNode * variableDeclaration();
ASTNode * parameterList(); // <parameter> | parameterList "," <parameter>
ASTNode * parameter(); // <typeSpecifier> <identifier>
ASTNode * function(); // <typeSpecifier> <identifier> "(" [<parameter-list>] ")" <functionBody>
ASTNode * functionBody(); // "{" {<statement>} "}"
ASTNode * statement(); // if, else, etc.
ASTNode * assignment(); // <identifier> [ "[" <expression> "]" ] "=" <expression>
ASTNode * expression(); // FROM THING (adding, subtracting, etc.)
ASTNode * arrayIndex(); // <expression>
ASTNode * binaryExpression();
// Terminals
ASTNode * type(); // <type>
ASTNode * identifier();
ASTNode * op();
ASTNode * number(); // Number token
ASTNode * character();
};