-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassembler.l
30 lines (29 loc) · 1.05 KB
/
assembler.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
/*
* This file contains the flex declaration, which handles the tokenizing
* portion of the assmebler. Built using the Flex & Bison guide found here
* https://aquamentus.com/flex_bison.html#20
* Authors: [email protected], Tyler Linquata
*/
%{
#include <iostream>
#include "assembler.tab.h" // to get token types from Bison
using namespace std;
extern int yylex();
int lineNum = 1;
%}
%option noyywrap
%%
[ \t] ;
codedumpster { return CODEDUMPSTER; }
end { return END; }
[$][-]?[0-9]+ { yylval.immval = strdup(yytext); return IMM; }
[R][0-9]+ { yylval.regval = strdup(yytext); return REG; }
[0-9]+\.[0-9]+ { yylval.fval = atof(yytext); return FLOAT; }
[0-9]+ { yylval.ival = atoi(yytext); return INT; }
[A-Z]{2,5} { yylval.sval = strdup(yytext); return INSTR; }
[-]?[0-9]+[(][R][0-9]+[)] { yylval.relval = strdup(yytext); return REL; }
[\/\/].* { yylval.comment = strdup(yytext); return COMMENT; }
[.][a-zA-Z0-9]+ { yylval.label = strdup(yytext); return LABEL; }
\n { ++lineNum; return ENDL; }
, ;
%%