-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscanner.l
More file actions
74 lines (60 loc) · 1.65 KB
/
scanner.l
File metadata and controls
74 lines (60 loc) · 1.65 KB
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
%{
// scanner.l -- our assembler input scanning program
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "parser.h"
extern YYSTYPE yylval;
#include "yfasm.h"
%}
%option noyywrap
delim [ \t]
whitesp {delim}+
digit [0-9]
alpha [a-zA-Z]
alphanum [a-zA-Z0-9]
number [-]?{digit}*[.]?{digit}+
integer [-]?{digit}+
hex "0x"[0-9a-fA-F]+
string \"[^\"]*\"
register [rR][-]?{digit}+
comment "#"[^\n]*
identifier {alphanum}[a-zA-Z0-9_]*
%%
{register} { sscanf(yytext+1, "%d", &yylval); return REG; }
{integer} { sscanf(yytext, "%d", &yylval); return INTEGER; }
{hex} { sscanf(yytext+2, "%x", &yylval); return INTEGER; }
"\n" { return NEWLINE; }
"," { return COMMA; }
":" { return COLON; }
"NOP" { return NOP; }
"LRI" { return LRI; }
"ADD" { return ADD; }
"SUB" { return SUB; }
"OR" { return OR; }
"XOR" { return XOR; }
"HALT" { return HALT; }
"BRA" { return BRA; }
"BRANZ" { return BRANZ; }
"BRAL" { return BRAL; }
"BRALNZ" { return BRALNZ; }
"CALL" { return CALL; }
".imem" { return sIMEM; }
".regfile" { return sREGFILE; }
".base" { return sBASE; }
".define" { return sDEFINE; }
".register" { return sREGISTER; }
".end" { return END; }
{identifier} {
yylval = yf_getsymbol(yytext);
if(yylval<=0)
yylval = yf_addsymbol(yytext, ST_UNKNOWN, 0);
return IDENTIFIER;
}
{string} {
yytext[strlen(yytext)-1] = 0;
yylval = yf_addstring(&yytext[1]);
return STRING;
}
{whitesp} { /* No action and no return */ }
{comment} { /* No action and no return */ }