aboutsummaryrefslogtreecommitdiff
path: root/lexer.l
blob: f157edf1e3649bad694a7c54dc2d0f92d3706282 (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
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/* $Id$ */
/*
 * Copyright (c) 2012 Dimitri Sokolyuk <demon@dim13.org>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

%{
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "y.tab.h"
%}

%option yylineno

%x COMMENT QUOTED

WS	[ \t\r\n]+
STR	[A-Za-z0-9_]+
HEX	0x[0-9A-Fa-f]+
OCT	0[0-7]+
DEC	[0-9]+

%%

[Ss][Ee][Tt]		return SET;
[Aa][Dd][Dd]		return ADD;
[Ss][Uu][Bb]		return SUB;
[Mm][Uu][Ll]		return MUL;
[Dd][Ii][Vv]		return DIV;
[Mm][Oo][Dd]		return MOD;
[Ss][Hh][Ll]		return SHL;
[Ss][Hh][Rr]		return SHR;
[Aa][Nn][Dd]		return AND;
[Bb][Oo][Rr]		return BOR;
[Xx][Oo][Rr]		return XOR;
[Ii][Ff][Ee]		return IFE;
[Ii][Ff][Nn]		return IFN;
[Ii][Ff][Gg]		return IFG;
[Ii][Ff][Bb]		return IFB;

[Jj][Ss][Rr]		return JSR;
[Bb][Rr][Kk]		return BRK;
[Dd][Aa][Tt]		return DAT;
[Oo][Rr][Gg]		return ORG;
[Jj][Mm][Pp]		return JMP;

[Pp][Oo][Pp]		return POP;
[Pp][Ee][Ee][Kk]	return PEEK;
[Pp][Uu][Ss][Hh]	return PUSH;
[Ss][Pp]		return SP;
[Pp][Cc]		return PC;
[Oo]			return O;

[Aa]			return A;
[Bb]			return B;
[Cc]			return C;
[Xx]			return X;
[Yy]			return Y;
[Zz]			return Z;
[Ii]			return I;
[Jj]			return J;

"+"			return PLUS;
"-"			return MINUS;
"*"			return MULT;
","			return COMMA;
":"			return DP;
"["			return LBR;
"]"			return RBR;
"("			return LPAR;
")"			return RPAR;
"{"			return LBRACE;
"}"			return RBRACE;
"#"			return HASH;
"."			return DOT;

[Mm][Aa][Cc][Rr][Oo]	return MACRO;
[Ii][Nn][Cc][Ll][Uu][Dd][Ee]	return INCLUDE;

";"			BEGIN(COMMENT);
<COMMENT>[\r\n]+	BEGIN(INITIAL);
<COMMENT>.		/* eat comments */

"\""			BEGIN(QUOTED);
<QUOTED>[^\"]+		{
				yylval.sval = strdup(yytext);
				return QSTRING;
			}
<QUOTED>"\""		BEGIN(INITIAL);

{HEX}|{OCT}|{DEC}	{
				yylval.ival = strtol(yytext, (char **)NULL, 0);
				return NUMBER;
			}

{STR}			{
				yylval.sval = strdup(yytext);
				return STRING;
			}

{WS}			/* eat whitespace */

%%

int
yywrap(void)
{
	return 1;
}