-
Notifications
You must be signed in to change notification settings - Fork 5
/
parser.h
85 lines (62 loc) · 2.76 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
#pragma once
#include <string>
#include <map>
#include <vector>
#include <memory>
#include "lexer.h"
#include "ast.h"
#include "parser_helper.h"
using std::shared_ptr;
using std::string;
using std::vector;
using std::pair;
using std::map;
class Parser {
public:
Parser();
shared_ptr<ModuleAST> parseModule(shared_ptr<Lexer> lexer);
private:
void parseImport(vector<pair<string, string>> &imports);
void parseTypeDecl (vector<shared_ptr<DeclAST>> &decls);
void parseConstDecl (vector<shared_ptr<DeclAST>> &decls);
void parseVarDecl (vector<shared_ptr<DeclAST>> &decls);
void parseExternDecl (vector<shared_ptr<DeclAST>> &decls);
void parseForwardDecl(shared_ptr<Token> start, vector<shared_ptr<DeclAST>> &decls);
void parseProcDecl (vector<shared_ptr<DeclAST>> &decls);
void parseStatementSeq(vector<shared_ptr<StatementAST>> &stmts);
shared_ptr<AssignStatementAST> parseAssignmentStatement(shared_ptr<DesignatorAST> des);
shared_ptr<CallStatementAST> parseCallStatement(shared_ptr<DesignatorAST> des);
shared_ptr<CallStatementAST> parseNakedCallStatement(shared_ptr<DesignatorAST> des);
shared_ptr<IfStatementAST> parseIfStatement();
shared_ptr<CaseStatementAST> parseCaseStatement();
void parseCase(vector<shared_ptr<CaseClauseAST>> &clauses);
shared_ptr<WhileStatementAST> parseWhileStatement();
shared_ptr<RepeatStatementAST> parseRepeatStatement();
shared_ptr<ForStatementAST> parseForStatement();
shared_ptr<LoopStatementAST> parseLoopStatement();
shared_ptr<WithStatementAST> parseWithStatement();
void parseWithGuard(vector<shared_ptr<WithClauseAST>> &clauses);
shared_ptr<ExitStatementAST> parseExitStatement();
shared_ptr<ReturnStatementAST> parseReturnStatement();
shared_ptr<ReceiverAST> parseReceiver();
shared_ptr<QualIdentAST> parseFormalParams(vector<shared_ptr<VarDeclAST>> ¶ms);
shared_ptr<TypeAST> parseType();
shared_ptr<TypeAST> parseSimpleType(shared_ptr<Token> start);
shared_ptr<TypeAST> parseArrayType(shared_ptr<Token> start);
shared_ptr<TypeAST> parseRecordType(shared_ptr<Token> start);
shared_ptr<TypeAST> parsePointerType(shared_ptr<Token> start);
shared_ptr<TypeAST> parseProcedureType(shared_ptr<Token> start);
shared_ptr<ExprAST> parseConstExpr();
shared_ptr<ExprAST> parseExpr();
shared_ptr<ExprAST> parseUnaryExpr();
shared_ptr<ExprAST> parseBinOpRHS(shared_ptr<ExprAST> LHS, int prec);
shared_ptr<ExprAST> parseFactor();
shared_ptr<DesignatorAST> parseDesignator();
shared_ptr<IdentDefAST> parseIdentDef();
shared_ptr<QualIdentAST> parseQualIdent();
int getPrecedence(shared_ptr<Token> op);
private:
shared_ptr<Tokenizer> tok;
map<string, int> precedence;
SymbolTable symbolTable;
};