-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleximiser.c
104 lines (85 loc) · 2.58 KB
/
leximiser.c
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
#include <stdio.h>
#include <string.h>
#define RESERVED 32
#define RESERVED_LENGTH 10
#define SPECIALSYM 13
#define STRIMAX 256
char special[SPECIALSYM] = {'+', '-', '*', '/', '(', ')', '=', ',' , '.', '<', '>', ';' , ':'};
char reservedWords[RESERVED][RESERVED_LENGTH] = {"NULL", "", "", "+", "-", "*",
"/", "odd", "=", "!=", "<", "<=",
">", ">=", "(", ")", ",", ";", ".",
":=", "{", "}", "if", "then", "while",
"do", "call", "const", "int", "procedure",
"write", "read"};
char program[250] = "int x, y;{ y := 3; x := y + 56;}.";
//29 2 x 17 2 y 18 21 2 y 20 3 3 18 2 x 20 2 y 4 3 56 18 22 19
struct token {
char string[STRIMAX];
int size;
int id;
};
int token_num = 0;
int token_size = 0;
char **leximiser(char *file, int size);
int main ()
{
int i;
int j;
for(i = 0; i < RESERVED; i++)
{
for(j = 0; j < RESERVED; j++)
{
printf("%c", reservedWords[i][j]);
}
}
}
char **groups(char *file, int size)
{
}
int isLetter(char dude)
{
int upper = 65;
int lower = 97;
for(upper = 65; upper <=90; upper++)
if(dude == upper)
return 1;
for(lower = 97; lower <= 112; lower++)
if(dude == lower)
return 1;
return 0;
}
int isReserved(struct token *tokens)
{
int counter = 0;
while(counter < RESERVED)
{
if(strcmp(tokens->string, reservedWords[counter]) == 0)
tokens->id = counter + 1;
counter++;
}
return 0;
}
struct token * tokeniser(struct token *tokens)
{
int x = 0;
int y = 0;
int counter = 0;
while(counter < token_num)
{
if(isReserved(tokens))
{
tokens[counter].id = isReserved(tokens);
}
counter++;
}
}
int isVarNum(struct token *tokens)
{
int counter = 0;
for(counter = 0; counter < STRIMAX; counter++)
if(tokens->string[counter] == '0'||tokens->string[counter] == '1'
||tokens->string[counter] == '2'||tokens->string[counter] == '3'
||tokens->string[counter] == '4'||tokens->string[counter] == '5'
||tokens->string[counter] == '6'||tokens->string[counter] == '7'
||tokens->string[counter] == '8'||tokens->string[counter] == '9')
}