-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscanner.h
121 lines (97 loc) · 2.29 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
/***************************
* PROJECT:
* IFJ20 - Compiler for imperative programming language IFJ20
*
* UNIVERSITY:
* Faculty of Information Technology, Brno University of Technology
*
* FILE:
* scanner.h
*
* DESCRIPTION:
* Lexical analysis
*
* AUTHORS:
* Kolaříková Mirka <[email protected]>
* Žovinec Martin <[email protected]>
*/
#ifndef SCANNER_H
#define SCANNER_H
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include "str.h"
#include "main.h"
#include "error.h"
/*** State definitions ***/
#define ID 0
/* Key words */
#define KW_FUNC 1
#define KW_RETURN 2
#define KW_FLOAT64 3
#define KW_INT 4
#define KW_STRING 5
#define KW_FOR 6
#define KW_IF 7
#define KW_ELSE 8
#define KW_PACKAGE 9
/* Operators*/
#define ADD 10 // +
#define SUB 11 // -
#define DIV 12 // /
#define MUL 13 // *
#define EQ 20 // ==
#define NEQ 21 // !=
#define LESS 22 // <
#define GREAT 23 // >
#define LEQ 24 // <=
#define GEQ 25 // >=
/* Types */
#define T_INT 30
#define T_FLOAT 31
#define T_STRING 32
/* Special Characters */
#define L_PAR 41 // (
#define R_PAR 42 // )
#define L_BR 43 // {
#define R_BR 44 // }
#define ASSIGN 45 // =
#define COMMA 46 // ,
#define SEMICOL 47 // ;
#define VAR_DEF 48 // :=
#define EOL 50
#define ENDFILE 51
/* Non-finate states */
#define START 60
#define S_ASSIGN 61
#define S_DIV 62
#define S_L 63
#define S_G 64
#define S_NEG 65
#define S_ID 66
#define S_KW 67
#define S_INT 68
#define S_FLOAT 69
#define S_FLOAT2 70
#define S_FLOAT_E 71
#define S_STRING 72
#define L_COM 73
#define S_VAR_DEF 74
#define S_BLOCK 75
#define S_ESC 76
#define S_HEX 77
/* Build-in functions */
#define MAIN 80
#define F_INPUTS 81
#define F_INPUTI 82
#define F_INPUTF 83
#define F_PRINT 84
#define F_INT2FLOAT 85
#define F_FLOAT2INT 86
#define F_LEN 87
#define F_SUBSTR 88
#define F_ORD 89
#define F_CHR 90
int get_new_token(string *tokenStr);
int hex_to_int(char ch);
#endif /* SCANNER_H*/