-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathscanner.l
100 lines (82 loc) · 1.89 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
89
90
91
92
93
94
95
96
97
98
99
100
%option noyywrap
%option yylineno
%{
/* Copyright (c) 2005-2019 Matteo Corti <[email protected]>
* This file is part of roll
*
* You may distribute this file under the terms the GNU General Public
* License. See the file COPYING for more information.
*/
#include <limits.h>
#include "parser.h"
#ifdef DEBUG
extern int debug_flag;
#endif
%}
%%
[0-9]+ {
errno = 0;
long number = strtol( yytext, NULL, 10);
if ( errno != 0 && errno != ERANGE && number == 0 ) {
printf("Error: incorrect number %s\n", yytext);
exit(EXIT_FAILURE);
}
// we only accept integers
if ( number > INT_MAX ) {
printf("Error: %s is too large\n", yytext );
exit(EXIT_FAILURE);
}
yylval.int_type = (int)number;
#ifdef DEBUG
if (debug_flag > 0) {
printf("[DBG] [SCAN] NUMBER = %i\n", yylval.int_type);
}
#endif
return NUMBER;
}
\+ { return PLUS; }
\- {
#ifdef DEBUG
if (debug_flag > 0) {
printf("[DBG] [SCAN] MINUS\n");
}
#endif
return MINUS;
}
["*"x] { return TIMES; }
\/ { return DIV; }
d|D|w|W|t|T {
#ifdef DEBUG
if (debug_flag > 0) {
printf("[DBG] [SCAN] DICE\n");
}
#endif
return DICE;
}
DD66 {
#ifdef DEBUG
if (debug_flag > 0) {
printf("[DBG] [SCAN] DD66\n");
}
#endif
return D66;
}
f|F { return FUDGE; }
h|H|k|K { return HIGH; }
l|L { return LOW; }
X { return X; }
"(" { return LPAREN; }
")" { return RPAREN; }
"{" { return LCURLY; }
"}" { return RCURLY; }
">" { return GT; }
">=" { return GE; }
"<" { return LT; }
"<=" { return LE; }
"!=" { return NE; }
"<>" { return NE; }
"%" { return PERCENT; }
, { return COMMA; }
[[:blank:]] /* ignore spaces */
. { printf("Error: unknown symbol '%s'\n", yytext); exit(EXIT_FAILURE); }
%%