-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscanner.h
130 lines (114 loc) · 2.84 KB
/
scanner.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
/************************************************************************
*
* Compiler implementation for imperative programming language IFJ18
*
* Autors:
* Sasák Tomáš - xsasak01
* Venkrbec Tomáš - xvenkr01
* Krajči Martin - xkrajc21
* Dižová Natália - xdizov00
*
***********************************************************************/
#ifndef _SCAN_H
#define _SCAN_H
#include "str.h"
#include <stdio.h>
enum state {
S0 = 1, // Initial state
S1 // State after whitespaces and comments
};
enum comment {
LC = 10, // line comment
BC, // block comment
END_C, // end of block comment
TMP_C, // temporary state for BC
};
enum number {
ZERO = 100, // FS: zero
IL, // FS: integer literal
FL, // FS: floating literal
TMP_FL, // temporary state for FL
TMP_F_EX, // temporary state for FL with exponent
TMP_I_EX, // temporary state for IL with exponent
SIGN_F, // signed exponent for FL
SIGN_I, // signed exponent for IL
FL_EX, // FS: floating literal with exponent
IL_EX // FS: integer literal with exponent
};
enum ident {
ID_STATE = 1000, // FS: identifier
ID_F // FS: function identifier
};
enum string {
SL = 10000, // FS: string literal
TMP_SL, // temporary state for SL
ES, // escape sequence
X_ES, // hexadecimal escape sequence \xh
XHH_ES // hexadecimal escape sequence \xhh
};
enum symbol {
S_PLUS = 100000, // '+'
S_MINUS, // '-'
S_ASTERISK, // '*'
S_SLASH, // '/'
S_ASSIGNMENT, // '='
S_EQUAL, // '=='
S_LT, // '<'
S_LE, // '<='
S_GT, // '>'
S_GE, // '>='
S_NE, // '!='
S_OPEN_PARENTH, // '('
S_CLOSE_PARENTH, // ')'
S_COMMA // ','
};
/**
* Structure which represents token
*/
typedef struct token
{
int type; // Type of token from defines below
union { // Union containing token data, depending on the type of token
int i;
double f;
string str;
} attr ;
}tToken;
// ======= TYPES OF TOKEN =======
#define IDF 0
#define ID 1
#define INTEGER 2
#define FLOAT 3
#define STRING 4
#define END_OF_FILE 5
#define END_OF_LINE 6
#define NORETVAL 7
// KEYWORDS
#define DEF 10
#define DO 11
#define ELSE 12
#define END 13
#define IF 14
#define NOT 15
#define NIL 16
#define THEN 17
#define WHILE 18
// OPERATORS
#define PLUS 20 // '+'
#define MINUS 21 // '-'
#define ASTERISK 22 // '*'
#define SLASH 23 // '/'
#define ASSIGNMENT 24 // '='
#define EQUAL 25 // '=='
#define LESS_THAN 26 // '<'
#define LESS_EQUAL 27 // '<='
#define GREATER_THAN 28 // '>'
#define GREATER_EQUAL 29 // '>='
#define NOT_EQUAL 30 // '!='
// SPECIAL CHARACTERS
#define OPEN_PARENTH 40 // '('
#define CLOSE_PARENTH 41 // ')'
#define COMMA 42 // ','
void set_source_file(FILE *f);
struct token get_token();
#endif // _SCAN_H