-
Notifications
You must be signed in to change notification settings - Fork 0
/
Parser.l
86 lines (59 loc) · 1.63 KB
/
Parser.l
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
%{
// Write all the supporting C - code declaration / definations
// Define all supportive data structures BEGIN
// Define all supportive data structures END
// dedicated to declare all global variables which parser will use BEGIN
#ifdef __cplusplus
extern "C" {
#endif
int yylex(void);
#ifdef __cplusplus
}
#endif
char lex_buffer[512];
// dedicated to declare all global variable which the parser will use END
#include "MexprEnums.h"
%}
%%
// comofsldfjsldfj
\n {
return PARSER_EOL;
}
0|-?[1-9][0-9]* {
return MATH_C_INT;
}
-?[0-9]*\.[0-9]+ {
return MATH_C_DOUBLE;
}
[a-zA-Z0-9_]+ {
return MATH_C_VARIABLE;
}
(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9]) {
return MATH_C_IPV4;
}
[ ] {
// for space to be ignored
}
. {
printf("ignored non parsable character -> %s\n", yytext);
}
%%
// C main functions
int main(int argc, char** argv){
printf("Number of args -> %d\t First Args -> %s\n", argc, argv[0]);
while(1){
fgets(lex_buffer, sizeof(lex_buffer), stdin);
if(lex_buffer[0] == '\n'){
lex_buffer[0] = 0;
continue;
}
yy_scan_string(lex_buffer);
int token_code;
token_code = yylex();
while (token_code != PARSER_EOL){
printf("token code -> %d token -> %s token len -> %lu\n", token_code, yytext, yyleng);
token_code = yylex();
}
}
return 0;
}