-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSTLscanner.ll
138 lines (112 loc) · 3.62 KB
/
STLscanner.ll
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
%{ /* -*- C++ -*- */
#include <cerrno>
#include <climits>
#include <float.h>
#include <cstdlib>
#include <string>
#include <STLdriver.h>
#include <STLparser.hh>
// Work around an incompatibility in flex (at least versions
// 2.5.31 through 2.5.33): it generates code that does
// not conform to C89. See Debian bug 333231
// <http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=333231>.
#undef yywrap
#define yywrap() 1
// The location of the current token.
static yy::location loc;
%}
%option noyywrap nounput batch debug noinput
id [a-zA-Z][a-zA-Z_0-9]*
int [0-9]+
float [0-9]+\.[0-9]+
blank [ \t]
%{
// Code run each time a pattern is matched.
# define YY_USER_ACTION loc.columns (yyleng);
%}
%%
%{
// Code run each time yylex is called.
loc.step();
%}
{blank}+ loc.step();
[\n]+ loc.lines(yyleng); loc.step();
"%%" return yy::STLparser::make_BODYSTART(loc);
"=" return yy::STLparser::make_ASSIGN(loc);
"step" return yy::STLparser::make_STEP(loc);
"diff" return yy::STLparser::make_DIFF(loc);
"abs" return yy::STLparser::make_ABS(loc);
"," return yy::STLparser::make_COMMA(loc);
";" return yy::STLparser::make_SEMICOLON(loc);
":" return yy::STLparser::make_COLON(loc);
"-" return yy::STLparser::make_MINUS(loc);
"+" return yy::STLparser::make_PLUS(loc);
"*" return yy::STLparser::make_STAR(loc);
"/" return yy::STLparser::make_SLASH(loc);
"(" return yy::STLparser::make_LRPAREN(loc);
")" return yy::STLparser::make_RRPAREN(loc);
"[" return yy::STLparser::make_LSPAREN(loc);
"]" return yy::STLparser::make_RSPAREN(loc);
"{" return yy::STLparser::make_LCPAREN(loc);
"}" return yy::STLparser::make_RCPAREN(loc);
">=" return yy::STLparser::make_GEQ(loc);
"<=" return yy::STLparser::make_LEQ(loc);
">" return yy::STLparser::make_GREATER(loc);
"<" return yy::STLparser::make_SMALLER(loc);
"==" return yy::STLparser::make_EQUAL(loc);
"!=" return yy::STLparser::make_NEQUAL(loc);
"&&" return yy::STLparser::make_AND(loc);
"||" return yy::STLparser::make_OR(loc);
"!" return yy::STLparser::make_NOT(loc);
"[]" return yy::STLparser::make_ALWAYS(loc);
"[]_" return yy::STLparser::make_ALWAYST(loc);
"<>" return yy::STLparser::make_EVENTUALLY(loc);
"<>_" return yy::STLparser::make_EVENTUALLYT(loc);
"U" return yy::STLparser::make_UNTIL(loc);
"U_" return yy::STLparser::make_UNTILT(loc);
"AND" return yy::STLparser::make_ANDSTL(loc);
"TRUE" return yy::STLparser::make_TRUE(loc);
"FALSE" return yy::STLparser::make_FALSE(loc);
"//".* {
/* Single line comment */
}
[/][*][^*]*[*]+([^*/][^*]*[*]+)*[/] {
/* Multiline comment */
}
[/][*] {
driver.error (loc, "Unterminated comment");
}
{int} {
errno = 0;
long n = strtol(yytext, NULL, 10);
if (! (INT_MIN <= n && n <= INT_MAX && errno != ERANGE))
driver.error (loc, "integer is out of range");
//return yy::STLparser::make_INUM(n, loc);
return yy::STLparser::make_INUM(yytext, loc);
}
{float} {
errno = 0;
long double n = strtold(yytext, NULL);
if (! (DBL_MIN <= n && n <= DBL_MAX && errno != ERANGE))
driver.error (loc, "floating point number is out of range");
//return yy::STLparser::make_FNUM(n, loc);
return yy::STLparser::make_FNUM(yytext, loc);
}
{id} return yy::STLparser::make_VAR(yytext, loc);
. driver.error (loc, "invalid character");
<<EOF>> return yy::STLparser::make_END(loc);
%%
void STLdriver::scan_begin()
{
yy_flex_debug = trace_scanning;
if (file.empty () || file == "-") {
yyin = stdin;
} else if (!(yyin = fopen (file.c_str (), "r"))) {
error ("cannot open " + file + ": " + strerror(errno));
exit (EXIT_FAILURE);
}
}
void STLdriver::scan_end()
{
fclose (yyin);
}