-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser.h
47 lines (36 loc) · 951 Bytes
/
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
#ifndef PARSER_H
#define PARSER_H
#include "treenode.h"
#include "lexer.h"
class Parser
{
public:
Parser(Lexer & s);
void parse();
TreeNode * root() { return root_; }
private:
TreeNode * stmtSequence();
TreeNode * statement();
TreeNode * ifStmt();
TreeNode * repeatStmt();
TreeNode * assignStmt();
TreeNode * readStmt();
TreeNode * writeStmt();
TreeNode * expr();
TreeNode * simpleExpr();
TreeNode * term();
TreeNode * factor();
TreeNode * allocStmtSeq();
TreeNode * allocStmt(StmtKind k);
TreeNode * allocExpr(ExprKind k);
void getToken();
const std::string & tokenId() { return scanner_.id(); }
int tokenNum() { return scanner_.num(); }
size_t tokenLineNo() { return scanner_.line(); }
void match(TokenType token);
void syntaxError(const std::string & err);
TreeNode * root_;
Lexer & scanner_;
TokenType token_;
};
#endif // PARSER_H