-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsymbol.cpp
80 lines (75 loc) · 1.64 KB
/
symbol.cpp
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
#include "symbol.h"
#include "getSym.h"
#include <string.h>
#include <stdlib.h>
symbol::symbol() {
for (int i = 0; i < 1001; i++) {
this->valueStr[i] = '\0';
}
}
void symbol:: set(int state, char * value) {
if (state == CHARACH2) {
this->type = CHARACH_SYM;
this->valueCh = value[1];
this->len = 1;
}
else if (state == STR2) {
this->type = STR_SYM;
this->len = strlen(value);
value[strlen(value) - 1] = '\0';
for (int i = 1, j = 0; i <= strlen(value); i++, j++) {
if (value[i] == '\\') this->valueStr[j++] = '\\';
this->valueStr[j] = value[i];
}
}
else if (state == NUM) {
this->type = UNSNUM_SYM;
this->len = strlen(value);
this->valueNum = 0;
for (int i = 0; i < strlen(value); i++) {
this->valueNum = this->valueNum * 10 + value[i] - '0';
}
}
else if (state==SIGNINT){
this->type = NUM_SYM;
this->len = strlen(value);
this->valueNum = 0;
for (int i = 1; i < strlen(value); i++) {
this->valueNum = this->valueNum * 10 + value[i] - '0';
}
}
else {
this->len = strlen(value);
for (int i = 0; i < len; i++) {
if (value[i] >= 'A' && value[i] <= 'Z') value[i] = value[i] - 'A' + 'a';
}
int hasFound = 0;
int i;
for (i = 0; i < 31; i++) {
if (strcmp(value, token[i]) == 0) {
hasFound = 1;
break;
}
}
for (int i = 0; i <=strlen(value); i++) {
this->valueStr[i] = value[i];
}
if (hasFound) {
this->type = i;
}
else this->type = ID_SYM;
}
}
int symbol::getType() {
return this->type;
}
int symbol::getValueNum() {
return this->valueNum;
}
char symbol::getValueCh() {
return this->valueCh;
}
char * symbol::getValueStr() {
return this->valueStr;
}
symbol curSym;