-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBashGenerator.h
More file actions
84 lines (51 loc) · 1.78 KB
/
BashGenerator.h
File metadata and controls
84 lines (51 loc) · 1.78 KB
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
#ifndef REPL_COMPILER_H
#define REPL_COMPILER_H
#include "ASTNode.h"
#include <string>
#include <map>
#include <cmath>
#include <algorithm>
#include "sole/sole.hpp"
class BashGenerator {
private:
struct Scope {
Scope* outer;
std::unordered_map<std::string, std::string> uuid;
Scope(Scope* outerScope) {
outer = outerScope;
}
};
std::string getUuid();
void openScope();
void closeScope();
std::string lookTopId(const std::string& id);
Scope* topScope;
int getOperatorPrecedence(BinOpNode* binOp);
std::string generateConstNumber(ConstNumberNode* node);
std::string generateConstBool(ConstBoolNode* node);
std::string generateId(IdentifierNode* node);
std::string generateReservedFuncCall(FuncCallNode* node);
std::string generateFuncCall(FuncCallNode* node);
std::string generateDeclVar(DeclVarNode* node);
std::string generateDeclFunc(DeclFuncNode* node);
std::string generateBreakStmt();
std::string generateIfStmt(IfStmtNode* node);
std::string generateForLoop(ForLoopNode* node);
std::string generateBlockStmt(BlockStmtNode* node);
std::string generateReturnStmt(ReturnStmtNode* node);
std::string generateBinaryExprMath(BinOpNode* node);
std::string generateBinaryExprAssign(BinOpNode* node);
std::string generateGetValue(ASTNode* node);
std::string generateStatement(ASTNode* node);
void addTabs(std::string& result);
int tabCount;
bool blockScope;
bool isFuncReserved(const std::string& funcName);
public:
std::string generate(ProgramTranslationNode* root);
BashGenerator(): topScope(new Scope(nullptr)), tabCount(0), blockScope(false) {};
~BashGenerator() {
delete topScope;
}
};
#endif //REPL_COMPILER_H