-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlexer.hpp
89 lines (65 loc) · 1.74 KB
/
lexer.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
/**
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
or visit
http://www.gnu.org/licenses/gpl.txt
*****************************************************************************
*/
#ifndef ER_MARKUP_LEXER_HPP_
#define ER_MARKUP_LEXER_HPP_
#include "includes.hpp"
using namespace std;
enum TokenType { KEYWORD = 775, NAME, OPERATOR , _NONE};
enum Operator { LCURL = 1056, RCURL, SEMICOLON, HYPHEN, EQUAL , _ERROR};
enum KeyWord { ENT = 1123, WEAK,
ATTR, KEY, DERIVED, MULTI, COMPOSITE,
RELN, ONE, MANY, FROM, TO, PARTIAL, COMPLETE, DIAGRAM,
BEGIN, END, CONNECT, ERROR };
extern const char *KEYWORDS[18];
inline bool isKey(const char *str){
for(int i=0; i<18; i++)
if(strcmp(KEYWORDS[i],str)==0) return true;
return false;
}
union TokenHolder{
KeyWord kw_;
Operator op_;
char name_[100];
};
struct Token{
TokenType type_;
TokenHolder token_;
Token(){}
Token(TokenType type, const char *tok_str){
makeToken(type,tok_str);
}
void makeToken(TokenType type, const char *tok_str);
};
class Tokenizer{
public:
Tokenizer(char *prog):prog_(prog){}
inline bool next(Token &t){
bool ret = getNextToken();
DEBUG(cout<<token_<<endl;)
if(ret) t.makeToken(type_,token_);
return ret;
}
inline const char *getProgram(){
return prog_;
}
private:
char *prog_;
char token_[100];
TokenType type_;
inline bool isOp(char ch){
if(strchr("{};-=",ch)) return true;
return false;
}
bool getNextToken();
};
#endif