summaryrefslogtreecommitdiff
path: root/src/lexer.l
blob: 46f6bc6c83feaa9b35efceb1d458ae7ace929c3f (plain)
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
%{
#include <string.h>
#include <stdlib.h>
#include "parser.tab.h"
extern int yylex();
extern size_t line_number;
%}
%option noyywrap
%%
^[a-zA-Z]+                      { yylval.symbol = strdup(yytext); return T_INSTRUCTION; }
%*[a-zA-Z\_\-]+[a-zA-Z0-9\_\-]* { yylval.symbol = strdup(yytext); return T_LABEL; }
0x[0-9A-Fa-f]+                  { yylval.i_val = atoi(yytext); return T_INTEGER; }
[0-9]+                          { yylval.i_val = atoi(yytext); return T_INTEGER; }
-*[0-9]*\.*[0-9]*               { yylval.i_val = atof(yytext); return T_FLOAT; }
\".*\"                          {
    yylval.s_val = strdup(yytext+1);
    char *const close_paren = strrchr(yylval.s_val, '"');
    if (close_paren != NULL) {
        *close_paren = '\0';
    }
    return T_STRING;
}
,                               { return T_COMMA; }
\$                              { return T_IMMEDIATE; }
[ \t]                           ;
\n                              { ++line_number; return T_ENDL; }
.                               ;
%%