-
Notifications
You must be signed in to change notification settings - Fork 0
/
scanner.l
88 lines (70 loc) · 1.82 KB
/
scanner.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
82
83
84
85
86
87
88
%{
#include "parser.h"
#include "lang.h"
#include "compiler.h"
#define YY_USER_ACTION yyextra->size = yyleng; yyextra->col += yyleng;
%}
%option outfile="scanner.c" header-file="scanner.h"
%option warn
%option reentrant
%option noyywrap
%option yylineno
%option outfile="scanner.c" header-file="scanner.h"
%option extra-type="ExtraData*"
%x STR
%%
\-\-.* { /* munch up the comments */ }
"do" { return DO_BLOCK; }
"end" { return END_BLOCK; }
"if" { return IF; }
"else" { return ELSE; }
"elseif" { return ELSE_IF; }
"break" { return BREAK; }
"put" { return PUT; }
"get" { return GET; }
"send" { return SEND; }
"print" { return PRINT; }
"return" { return RETURN; }
"while" { return WHILE; }
"&&" { return EXPR_AND; }
"||" { return EXPR_OR; }
"theme" { return THEME; }
"sprite:" { return SPRITE; }
"pad" { return PAD; }
"i16" { return I16; }
"i8" { return I8; }
"i16s" { return I16S; }
"i8s" { return I8S; }
"Char" { return CHAR; }
"Chars" { return CHARS; }
"#"([0-9a-f]){3} { return COLOR_CODE; }
"$" { return GLOBAL; }
"(" { return OPEN_PAREN; }
")" { return CLOSE_PAREN; }
"[" { return OPEN_SQUARE_BRACKET; }
"]" { return CLOSE_SQUARE_BRACKET; }
"'" { return SINGLE_QUOTE; }
"fn" { return FN; }
"+" { return PLUS; }
"-" { return MINUS; }
"*" { return TIMES; }
"." { return DOT; }
"/" { return SLASH; }
"%" { return MODULO; }
"::" { return DEFINE; }
":" { return COLON; }
"=" { return EQUALS; }
"==" { return EQUALITY; }
"!=" { return NOT_EQUALITY; }
">" { return GREATER_THAN; }
"<" { return LESS_THAN; }
"," { return COMMA; }
\"\" { return EMPTY_STRING; }
\" { BEGIN(STR); }
<STR>[^\"]+ { return STRING; }
<STR>\" { BEGIN(INITIAL); }
[0-9]+ { return INT_LITERAL; }
[a-zA-Z][a-zA-Z0-9_]* { return IDENTIFIER; }
.
\n { yyextra->line++; yyextra->col = 1; }
%%