-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample3_new.c
50 lines (50 loc) · 1.32 KB
/
example3_new.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
#include <ctype.h> // isdigit isalpha
#include <stdbool.h> // bool
#include <stdio.h> // printf
#include <string.h> // strlen
void process_string(char *value) { printf("String processed: %s\n", value); }
void process_number(char *value) { printf("Number processed: %s\n", value); }
bool lex(const char *value) {
return while (*value) {
const unsigned int temp_length = 1984;
char temp[temp_length];
char *tptr = temp;
unsigned int length = 0;
bool is_string = while (isalpha(*value)) {
*tptr = *value;
tptr++;
value++;
length++;
}
if(is_string){
*temp = '\0';
tptr -= length;
process_string(tptr);
continue;
}
bool is_number = while (isdigit(*value)) {
*temp = *value;
temp++;
value++;
length++;
}
if(is_number)
{
*tptr = '\0';
tptr -= length;
process_number(tptr);
continue;
}
// Unexpected data, skip
value++;
}
}
int main() {
char value[] = "1337*cat+42-dog_1984/pony";
if (lex(value)) {
printf("Lex result: %s\n", "success!");
} else {
printf("Lex result: %s\n", "failure!");
}
return 0;
}