-
Notifications
You must be signed in to change notification settings - Fork 4
/
expr.l
100 lines (96 loc) · 1.48 KB
/
expr.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
87
88
89
90
91
92
93
94
95
96
97
98
%{
#include <stdlib.h>
#include <string.h>
#include "common.h"
void exprerror(char *);
#include "expr.tab.h"
static char *inputstr;
static int inputpos = 0;
#define YY_INPUT(buf, result, max_size) \
{ \
if(inputpos > strlen(inputstr)) { \
result = YY_NULL; \
} else { \
buf[0] = inputstr[inputpos++]; \
result = 1; \
} \
}
%}
%option prefix="expr"
%%
[aA][0-7] {
exprlval.val = exprtext[1]-'0';
return AREG;
}
[dD][0-7] {
exprlval.val = exprtext[1]-'0';
return DREG;
}
\.w {
return SIZEW;
}
\.b {
return SIZEB;
}
[pP][cC] {
return PC;
}
[sS][rR] {
return SR;
}
[sS][pP] {
return SP;
}
[sS][sS][pP] {
return SSP;
}
[uU][sS][pP] {
return USP;
}
[mM][0-9] {
exprlval.val = exprtext[1]-'0';
return WIN;
}
\$[0-9a-fA-F]+ {
exprlval.val = strtol(&exprtext[1], NULL, 16);
return VAL;
}
[0-9a-fA-F]+ {
exprlval.val = strtol(exprtext, NULL, 16);
return VAL;
}
\\[0-9]+ {
exprlval.val = strtol(&exprtext[1], NULL, 10);
return VAL;
}
= { return EQ; }
== { return EQ; }
!= { return NE; }
[<] { return LT; }
[<]= { return LE; }
> { return GT; }
>= { return GE; }
& { return BAND; }
&& { return LAND; }
[|] { return BOR; }
[|][|] { return LOR; }
[\^] { return BXOR; }
~ { return BNOT; }
! { return LNOT; }
[a-zA-Z][a-zA-Z0-9_]+ {
exprlval.str = strdup(exprtext);
return LABEL;
}
[()\[\]+\-*/\n] {
return *exprtext;
}
%%
int exprwrap(void)
{
return 1;
}
void expr_set_inputstr(char *str)
{
inputpos = 0;
inputstr = str;
}