-
Notifications
You must be signed in to change notification settings - Fork 88
/
Copy pathreflexexample11.lxx
47 lines (36 loc) · 1.26 KB
/
reflexexample11.lxx
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
/* Demonstrates Bison C++ complete interface see Bison 10.1.6.2 Complete Symbols */
/* Compile: reflex --bison-complete --bison-locations reflexexample11.lxx */
/* Compile: bison -d reflexexample11.yxx */
%top{
#include "parser.hpp" /* Generated by bison. */
#include "location.hpp" /* Generated by bison %locations. */
%}
%class{
public:
std::map<std::wstring,double> map;
%}
%option bison-complete
%option bison-cc-namespace=yy
%option bison-cc-parser=parser
%option bison-locations
/* throw an exception in the scanner's default rule */
%option exception="yy::parser::syntax_error(location(), \"Unknown token.\")"
%option tabs=8
%option namespace=yy
%option lexer=scanner
%option outfile=scanner.cpp
%option header-file=scanner.hpp
%option fast
%option unicode
%option freespace
var \p{UnicodeIdentifierStart} \p{UnicodeIdentifierPart}*
exp [Ee] [-+]? \d+
num \d* (\d | \.\d | \d\.) \d* {exp}?
%%
\s // ignore space
\"[^"]*\" { return yy::parser::make_STR(wstr(), location()); }
{var} { return yy::parser::make_VAR(wstr(), location()); }
{num} { return yy::parser::make_NUM(strtod(text(), NULL), location()); }
[-+*/=();] { return yy::parser::symbol_type(chr(), location()); }
<<EOF>> { return yy::parser::make_EOF(location()); }
%%