-
Notifications
You must be signed in to change notification settings - Fork 26
/
scanner.h
110 lines (90 loc) · 2.43 KB
/
scanner.h
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
// Generated by Flexc++ V2.07.03 on Sun, 20 Oct 2019 22:27:45 +0200
#ifndef Scanner_H_INCLUDED_
#define Scanner_H_INCLUDED_
// $insert baseclass_h
#include "scannerbase.h"
#include <string>
#include <exception>
class ScannerException: public std::exception {
private:
std::string msg;
public:
ScannerException(): msg("unknown error") {}
ScannerException(std::string msg_): msg("scanner: "+msg_) {}
const char *what() const throw() { return msg.c_str(); }
};
// $insert classHead
class Scanner: public ScannerBase
{
public:
// Non-zero value indicates that we return that as custom
// start token to the parser in the first call of lex().
int parserStart;
explicit Scanner(std::istream &in = std::cin,
std::ostream &out = std::cout);
Scanner(std::string const &infile, std::string const &outfile);
// $insert lexFunctionDecl
int lex();
private:
#if ( FLEXCPP_VERSION >= 20700LL )
int lex_();
int executeAction_(size_t ruleNr);
#else
int lex__();
int executeAction__(size_t ruleNr);
#endif
void print();
void preCode(); // re-implement this function for code that must
// be exec'ed before the patternmatching starts
#if ( FLEXCPP_VERSION >= 20700LL )
void postCode(PostEnum_ type);
#else
void postCode(PostEnum__ type);
#endif
// re-implement this function for code that must
// be exec'ed after the rules's actions.
};
// $insert scannerConstructors
inline Scanner::Scanner(std::istream &in, std::ostream &out)
:
ScannerBase(in, out), parserStart(0)
{}
inline Scanner::Scanner(std::string const &infile, std::string const &outfile)
:
ScannerBase(infile, outfile), parserStart(0)
{}
// $insert inlineLexFunction
inline int Scanner::lex()
{
if ( parserStart!=0 ) {
int res = parserStart;
parserStart = 0;
return res;
}
#if ( FLEXCPP_VERSION >= 20700LL )
return lex_();
#else
return lex__();
#endif
}
inline void Scanner::preCode()
{
// optionally replace by your own code
}
#if ( FLEXCPP_VERSION >= 20700LL )
inline void Scanner::postCode(PostEnum_ type)
#else
inline void Scanner::postCode(PostEnum__ type)
#endif
{
// optionally replace by your own code
}
inline void Scanner::print()
{
#if ( FLEXCPP_VERSION >= 20700LL )
print_();
#else
print__();
#endif
}
#endif // Scanner_H_INCLUDED_