Aprepro 5.0x

apr_scanner.h
Go to the documentation of this file.
1 #ifndef EXAMPLE_SCANNER_H
2 #define EXAMPLE_SCANNER_H
3
4 // Flex expects the signature of yylex to be defined in the macro YY_DECL, and
5 // the C++ parser expects it to be declared. We can factor both as follows.
6
7 #ifndef YY_DECL
8
9 #define YY_DECL SEAMS::Parser::token_type SEAMS::Scanner::lex(SEAMS::Parser::semantic_type *yylval)
10 #endif
11
12 #ifndef __FLEX_LEXER_H
13 #define yyFlexLexer SEAMSFlexLexer
14 #include "FlexLexer.h"
15 #undef yyFlexLexer
16 #endif
17
18 #include <iostream>
19
20 namespace SEAMS {
21
22 /** Scanner is a derived class to add some extra function to the scanner
23 * class. Flex itself creates a class named yyFlexLexer, which is renamed using
24 * macros to SEAMSFlexLexer. However we change the context of the generated
25 * yylex() function to be contained within the Scanner class. This is required
26 * because the yylex() defined in SEAMSFlexLexer has no parameters. */
27 class Scanner : public SEAMSFlexLexer
28 {
29 public:
30 friend class Parser;
31
32 /** Create a new scanner object. The streams arg_yyin and arg_yyout default
33 * to cin and cout, but that assignment is only made when initializing in
34 * yylex(). */
35 explicit Scanner(Aprepro &aprepro_yyarg, std::istream *in = nullptr,
36 std::ostream *out = nullptr);
37 /** Required for virtual functions */
38 ~Scanner() override;
39
40 void add_include_file(const std::string &filename, bool must_exist);
41 int yywrap() override;
42 void yyerror(const char *s);
43 void LexerOutput(const char *buf, int size) override;
44 int LexerInput(char *buf, int max_size) override;
45
46 /** This is the main lexing function. It is generated by flex according to
47 * the macro declaration YY_DECL above. The generated bison parser then
48 * calls this virtual function to fetch new tokens. */
49 virtual Parser::token_type lex(Parser::semantic_type *yylval);
50
51 char *rescan(char *string);
52 char *execute(char *string);
53 char *if_handler(double x);
54 char *elseif_handler(double x);
55 char *switch_handler(double x);
56 char *case_handler(double x);
57
58 /** Enable debug output (via arg_yyout) if compiled into the scanner. */
59 void set_debug(bool b);
60
61 /* User arguments. */
62 class Aprepro &aprepro;
63
64 /* save the original string for substitution history */
65 void save_history_string();
66 };
67
68 } // namespace SEAMS
69
70 #endif // EXAMPLE_SCANNER_H
SEAMS::Parser::semantic_type
Symbol semantic values.
Definition: aprepro_parser.h:164
SEAMS::Scanner::if_handler
char * if_handler(double x)
Definition: apr_scanner.cc:3417
SEAMS
Definition: apr_aprepro.cc:68
SEAMS::Scanner::yywrap
int yywrap() override
Definition: apr_scanner.cc:3251
SEAMS::Parser::token::yytokentype
yytokentype
Definition: aprepro_parser.h:191
SEAMS::Scanner::~Scanner
~Scanner() override
Definition: apr_scanner.cc:3172
SEAMS::Scanner::switch_handler
char * switch_handler(double x)
Definition: apr_scanner.cc:3456
FlexLexer.h
SEAMS::Scanner::add_include_file
void add_include_file(const std::string &filename, bool must_exist)
Definition: apr_scanner.cc:3174
SEAMS::Scanner::save_history_string
void save_history_string()
Definition: apr_scanner.cc:3513
SEAMS::Scanner::rescan
char * rescan(char *string)
Definition: apr_scanner.cc:3390
SEAMS::Scanner::execute
char * execute(char *string)
Definition: apr_scanner.cc:3354
SEAMS::Scanner::case_handler
char * case_handler(double x)
Definition: apr_scanner.cc:3477
SEAMS::Scanner::aprepro
class Aprepro & aprepro
Definition: apr_scanner.h:62
SEAMS::Scanner::Scanner
Scanner(Aprepro &aprepro_yyarg, std::istream *in=nullptr, std::ostream *out=nullptr)
Definition: apr_scanner.cc:3166
SEAMS::Scanner::LexerOutput
void LexerOutput(const char *buf, int size) override
Definition: apr_scanner.cc:3198
SEAMS::Scanner::set_debug
void set_debug(bool b)
SEAMS::Scanner::yyerror
void yyerror(const char *s)
Definition: apr_scanner.cc:3352
SEAMS::Scanner::elseif_handler
char * elseif_handler(double x)
Definition: apr_scanner.cc:3440
SEAMS::Scanner::lex
virtual Parser::token_type lex(Parser::semantic_type *yylval)
SEAMS::Scanner
Definition: apr_scanner.h:27
SEAMS::Aprepro
Definition: aprepro.h:183
SEAMSFlexLexer
Definition: FlexLexer.h:107
SEAMS::Scanner::LexerInput
int LexerInput(char *buf, int max_size) override
Definition: apr_scanner.cc:3214
SEAMS::Parser
A Bison parser.
Definition: aprepro_parser.h:159