-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlexer.l
43 lines (34 loc) · 968 Bytes
/
lexer.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
%top{
#include <cstdlib>
#include <string>
#include <map>
// fixes problem with Bison 2.7 that needs the Lexer class type:
//class REFLEX_OPTION_lexer; // = %option lexer (which is 'Lexer' by default)
#include "parser.h"
#include "../calc.h"
}
%{
extern void yyerror(Lexer *lexer, const char *msg);
%}
%class{
public:
Token token;
}
%option fast unicode freespace
var \p{UnicodeIdentifierStart} \p{UnicodeIdentifierPart}*
exp [Ee] [-+]? \d+
num \d* (\d | \.\d | \d\.) \d* {exp}?
%%
{var} { token.str = wstr(); return IDENTIFIER; }
{num} { token.value = strtod(text(), NULL); return INTEGER; }
"-" { return MINUS; }
"+" { return PLUS; }
"*" { return TIMES; }
"/" { return DIVIDE; }
"(" { return LPAR; }
")" { return RPAR; }
"=" { return ASSIGN; }
\" { return 0; }
\s // ignore space
. { std::cout<<"mystery character"; }
%%