-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser.hpp
104 lines (82 loc) · 2.47 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/**
RIGHT TO USE, DISTRIBUTE AND MODIFY
===================================
Copyright (C) 2015 Ganesh Prasad Sahoo - All Rights Reserved
You may use, distribute and modify this code under the Terms
of GNU GPL V3 License. You should have received a copy of the
GNU GPL v3 License with this file. If not please write to
sir.gnsp@gmail.com
or visit
http://www.gnu.org/licenses/gpl.txt
*****************************************************************************
*/
#ifndef ER_MARKUP_PARSER_HPP_
#define ER_MARKUP_PARSER_HPP_
#include "includes.hpp"
#include "lexer.hpp"
#include "structure.hpp"
#include "symbolTable.hpp"
extern EntityTable entTbl_;
class Parser{
public:
Parser(char *prog):lex_(prog),prog_(prog){}
void parse(){
check = lex_.next(t);
if(!check){
error("Empty source file");
return;
}
if(t.type_ == KEYWORD){
if(t.token_.kw_ == DIAGRAM ){
check = lex_.next(t);
if(!check) error("Incomplete Description of ER Diagram");
if(t.type_ == NAME){
strcpy(diagram_.name_, t.token_.name_);
check = lex_.next(t);
if(!check) error("Incomplete Description of ER Diagram");
if(t.type_ != OPERATOR && t.token_.op_ != SEMICOLON)
error("Expected SEMICOLON at the end of statement");
}
else error("Invalid naming of the ER Diagram");
check = lex_.next(t);
if(!check)error("No entities or relationships described");
}
else{
strcpy(diagram_.name_,"--UNNAMED--");
}
}
else error("Invalid syntax");
DEBUG(cout<<t.type_<<" "<<t.token_.kw_<<endl;)
if(t.type_ == KEYWORD && t.token_.kw_ == BEGIN){
check = lex_.next(t);
if(!check)error("No description of the Diagram found");
while(t.type_ == KEYWORD
&& (t.token_.kw_ == ENT || t.token_.kw_ == RELN
|| t.token_.kw_ == END)){
if(t.token_.kw_ == ENT) parseEnt();
else if(t.token_.kw_ == RELN) parseReln();
else if(t.token_.kw_ == END) break;
else error("Invalid syntax");
check = lex_.next(t);
if(!check) error("expected END here");
}
}
else error("expected BEGIN here");
}
void generateCode(const char *outFileName);
private:
Tokenizer lex_;
ER_Diagram diagram_;
//EntityTable entTbl_;
char *prog_;
Token t;
bool check;
void parseEnt();
void parseEntAttr(Entity &ent);
void parseAttr(Attribute &a);
void parseAttrAttr(Attribute &a);
void parseReln();
void parseEdges(Relation &rel, bool from);
void parseEdge(Edge &ed);
};
#endif