-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlex.l
81 lines (72 loc) · 1.59 KB
/
lex.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
%{
#include <stdio.h>
#include "yacc.h"
extern int ndas_error;
int linecount = 0;
%}
%option noinput
%option nounput
ws [ \t]
letter [A-Za-z]
digit [0-9]
hexdigit [0-9a-fA-F]
symbolchar {letter}|[\.$_]
symbol {symbolchar}({symbolchar}|{digit})*
gpreg [ABCXYZIJabcxyzij]
xreg SP|PC|EX|POP|PEEK|PUSH|PICK|sp|pc|ex|pop|peek|push|pick
op2 SET|ADD|SUB|MUL|MLI|DIV|DVI|MOD|MDI|AND|[BX]OR|SH[LR]|ASR|IF[BCENGALU]|ADX|SBX|ST[ID]
op2_lc set|add|sub|mul|mli|div|dvi|mod|mdi|and|[bx]or|sh[lr]|asr|if[bcengalu]|adx|sbx|st[id]
op1 JSR|HCF|INT|RFI|IA[GSQ]|HW[NQI]
op1_lc jsr|hcf|int|rfi|ia[gsq]|hw[nqi]
%%
:{symbol} {
yylval.string = yytext + 1;
return LABEL;
}
{symbol}: {
yylval.string = yytext;
yytext[strlen(yytext) - 1] = '\0';
return LABEL;
}
0x{hexdigit}+ {
yylval.integer = str2num(yytext);
return NUMBER;
}
{digit}+ {
yylval.integer = str2num(yytext);
return NUMBER;
}
{gpreg}|{xreg} {
yylval.integer = str2reg(yytext);
return REG;
}
{op2}|{op2_lc} {
yylval.integer = str2opcode(yytext);
return OP2;
}
{op1}|{op1_lc} {
yylval.integer = str2opcode(yytext);
return OP1;
}
{symbol} {
yylval.string = yytext;
return SYMBOL;
}
\"(\\.|[^\\"])*\" {
yylval.string = yytext;
return STRING;
}
[,\+\[\]\n] return *yytext;
[ \t\r]+ ; /* whitespace + DOS line endings */
;.* ; /* comment */
. {
fprintf(stderr,
"error: line %d: unknown character %c\n",
linecount, *yytext);
ndas_error = 1;
}
%%
int yywrap(void)
{
return 1;
}