-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser.hpp
58 lines (47 loc) · 1.77 KB
/
parser.hpp
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
#ifndef __parser
#define __parser
#include "ast.hpp"
#include "scan.hpp"
#include "global.hpp"
#include "shunting_yard.h"
#include <stack>
#include <llvm/ExecutionEngine/GenericValue.h>
void HandleProgram(Scan_file *, Main_block *);
void HandleFunction(Scan_file *, Main_block *);
void HandleEnd(Scan_file *, Main_block*);
void HandleReturn(Scan_file *, Main_block*);
void HandleTopLevelExpression(Scan_file*, Main_block*);
void HandleStatement(Scan_file*, Main_block*);
void HandleIfBlock(Scan_file*, Main_block*);
CondAST* HandleIfCond(Scan_file*, Main_block*, bool);
int HandleIfOperator(Scan_file*, Main_block*);
void HandleElseBlock(Scan_file*, Main_block*);
void HandleForBlock(Scan_file*, Main_block*);
VariableAST* HandleVariableDeclaration(Scan_file *, Main_block *);
void parser(Scan_file *, Main_block *);
std::vector<BasicAST*> HandleMath(Scan_file*, Main_block*);
StringAST* HandleString(Scan_file*, Main_block*);
void ExternalFunctions(Scan_file*, Main_block*);
BasicAST* convert_tok_ast(int, std::string);
class NBlock;
using namespace llvm;
class CodeGenBlock {
public:
BasicBlock *block;
std::map<std::string, Value*> locals;
};
class MainContext {
std::stack<CodeGenBlock *> blocks;
Function *mainFunction;
std::string name;
public:
Module *module;
MainContext(std::string name) : name(name) { module = new Module(name, getGlobalContext()); }
void generateCode(NBlock& root);
GenericValue runCode();
std::map<std::string, Value*>& locals() { return blocks.top()->locals; }
BasicBlock *currentBlock() { return blocks.top()->block; }
void pushBlock(BasicBlock *block) { blocks.push(new CodeGenBlock()); blocks.top()->block = block; }
void popBlock() { CodeGenBlock *top = blocks.top(); blocks.pop(); delete top; }
};
#endif // __parser