-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParser.hpp
82 lines (70 loc) · 2.19 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#pragma once
#include "Scanner.hpp"
#include "SyntaxNode.hpp"
#include "Symbol.hpp"
#include <set>
enum PriorityNames{P_Factor, P_Brace, P_Postfix, P_Term, P_PlusM, P_Shift, P_Compare,
P_TCompare, P_Andbin, P_Xor, P_Orbin, P_And, P_Or, P_Assign, P_Comma};
struct Stack{
SymTable Sym;
Stack *next, *prev;
Stack(){}
};
class TypeContainer{
public:
Symbol* type;
bool b_const;
bool b_typedef;
TypeContainer(Symbol* _type, bool _b_typedef, bool _b_const): type(_type), b_const(_b_const), b_typedef(_b_typedef){}
};
List* addListElem(List*, Symbol*);
ListStmt* addStmt(ListStmt*, StmtNode*);
class SymStack{
Stack* stack;
public:
SymStack(): stack(new Stack()){
stack->Sym.addSymbol(new SymVoid());
stack->Sym.addSymbol(new SymInt());
stack->Sym.addSymbol(new SymChar());
stack->Sym.addSymbol(new SymDouble());
stack->prev = NULL;
}
~SymStack(){for (int i = 0; stack != NULL; 1) { auto temp = stack->next; delete stack; stack = temp; } }
void pop(){stack = stack->prev; delete stack->next; stack->next = NULL;} //TODO : Underflow
void push(SymTable);
SymTable& peek(){return stack->Sym;}
Symbol* requireIdentifier(string, bool);
void notrequireIdentifier(string);
};
class CodeGen;
class Parser{
Scanner* scan;
SymStack stack;
set<string> functions;
public:
Parser(Scanner* a): scan(a){}
ExprNode* parseFactor(bool, bool, Condition);
ExprNode* parseExpr(int, bool, bool, Condition);
ExprNode* parsePostfix(bool, bool, Condition);
ExprNode* parseBrace(bool, bool, Condition);
ExprNode* parseAssign(bool, bool, Condition);
ExprNode* parsePrefix(bool, bool, Condition);
StmtNode* parseExprStmt();
StmtNode* parseStmt();
StmtNode* parseBlock();
StmtNode* parseDoWhile();
StmtNode* parseWhile();
StmtNode* parseIf();
StmtNode* parseFor();
StmtNode* parsePrintf();
void parseDeclaration(TypeContainer);
Symbol* parseSimpleDeclaration(TypeContainer);
Symbol* parsePointer(Symbol*, int*, bool); //TODO
Symbol* parseArray(Symbol*, string, bool);
Symbol* parseFunction(Symbol*, string, bool);
void parseProgramm();
TypeContainer parseType(bool, bool, bool);
TypeContainer parseStruct(bool, bool);
void print();
void generate(CodeGen&);
};