-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlexan.h
executable file
·148 lines (140 loc) · 2.41 KB
/
lexan.h
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*dodelat elemetnty &&, ||, new*/
#ifndef __LEXAN__
#define __LEXAN__
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <math.h>
#include <queue>
#include "exception.h"
using namespace std;
enum LexElementType{
END_FILE,
ERROR,
PLUS,
MINUS,
MUL,
DIV,
ASIGNMENT,
EQUAL,
NOT_EQUAL,
GREATER,
GREATER_OR_EQUAL,
LESSER,
LESSER_OR_EQUAL,
NOT,
INTEGER,
DOUBLE,
STRING,
IDENTIFICATOR,
OPEN_ROUND_BRACKET,
CLOSE_ROUND_BRACKET,
OPEN_BRACKET,
CLOSE_BRACKET,
OPEN_BRACE,
CLOSE_BRACE,
SEMICOLON,
COMMA,
IF,
ELSE,
FOR,
WHILE,
CLASS,
STATIC,
VOID,
INT,
DOUBLE_KEY,
STRING_KEY,
TRUE,
FALSE,
DOT,
NULL_KEY,
BOOLEAN,
NEW,
OR,
AND,
RETURN
};
static int nrKeyWords = 16;
static struct{
LexElementType keyWord;
char word[20];
} keywords[] = {
{ IF, "if" },
{ ELSE, "else" },
{ FOR, "for" },
{ WHILE, "while" },
{ CLASS, "class" },
{ STATIC, "static" },
{ VOID, "void" },
{ INT, "int" },
{ DOUBLE_KEY, "double" },
{ TRUE , "true" },
{ FALSE , "false" },
{ NULL_KEY, "null" },
{ BOOLEAN, "boolean" },
{ NEW, "new" },
{ RETURN, "return" },
{ STRING_KEY, "String"}
};
class LexElement{
LexElementType type;
int intValue;
double doubleValue;
char charValue[100];
public:
LexElement(){}
LexElement(LexElementType type){
this->type = type;
}
LexElement(LexElementType type, char* s){
this->type = type;
strncpy(this->charValue,s,100);
}
LexElement(LexElementType type, int intValue){
this->type = type;
this->intValue = intValue;
}
LexElement(LexElementType type, double doubleValue){
this->type = type;
this->doubleValue = doubleValue;
}
LexElementType getType() const{
return type;
}
int getIntValue() const{
return intValue;
}
double getDoubleValue() const{
return doubleValue;
}
char* getCharValue(){
return charValue;
}
};
class Lexan{
queue<LexElement> back;
FILE* source;
bool init;
int line;
public:
Lexan(char* path){
source = fopen(path, "r");
line = 1;
if (source == NULL) {
throw new ParserException("Soubor se nepodarilo otevrit");
init = false;
}
init = true;
}
LexElement nextToken();
void pushBack(LexElement e){
back.push(e);
}
int getLine(){ return line;}
~Lexan(){
fclose(source);
}
};
#endif