-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse.l
68 lines (51 loc) · 910 Bytes
/
parse.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
%{
#include <stdlib.h>
#include "machine.h"
#include "lexer.h"
YYSTYPE yylval;
int machine_serve_instruction (char *buffer, yy_size_t *read_bytes, int max);
void lexer_buffer_reset ()
{
YY_FLUSH_BUFFER;
}
#define YY_INPUT(buffer,read_bytes,max)\
{\
machine_serve_instruction(buffer,&read_bytes,max);\
}\
%}
%%
-?[0-9]+ {
yylval.val = atoi(yytext);
return TOKEN_NUMBER;
}
\"[^"]* {
yylval.str = yytext + 1;
yytext[yyleng] = '\0';
return TOKEN_STRING;
}
, {
return TOKEN_COMMA;
}
\[ {
return TOKEN_DREF_L;
}
\] {
return TOKEN_DREF_R;
}
SP|BP|IP|PTBR|PTLR|EIP|EC|EPN|EMA|CORE {
yylval.str = yytext;
return TOKEN_REGISTER;
}
P[0-3] {
yylval.str = yytext;
return TOKEN_REGISTER;
}
R[0-9]+ {
yylval.str = yytext;
return TOKEN_REGISTER;
}
[a-zA-Z]+ {
yylval.str = yytext;
return TOKEN_INSTRUCTION;
}
. ;