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. */
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
Scanner(Aprepro &aprepro_yyarg, std::istream *in=nullptr, std::ostream *out=nullptr)
Definition: apr_scanner.cc:3169
char * switch_handler(double x)
Definition: apr_scanner.cc:3463
virtual Parser::token_type lex(Parser::semantic_type *yylval)
void save_history_string()
Definition: apr_scanner.cc:3520
Definition: aprepro.h:178
char * rescan(char *string)
Definition: apr_scanner.cc:3397
void set_debug(bool b)
Symbol semantic values.
Definition: aprepro_parser.h:164
class Aprepro & aprepro
Definition: apr_scanner.h:62
char * case_handler(double x)
Definition: apr_scanner.cc:3484
Definition: FlexLexer.h:107
void LexerOutput(const char *buf, int size) override
Definition: apr_scanner.cc:3201
char * execute(char *string)
Definition: apr_scanner.cc:3361
~Scanner() override
Definition: apr_scanner.cc:3175
char * elseif_handler(double x)
Definition: apr_scanner.cc:3447
int LexerInput(char *buf, int max_size) override
Definition: apr_scanner.cc:3219
int yywrap() override
Definition: apr_scanner.cc:3256
A Bison parser.
Definition: aprepro_parser.h:159
void add_include_file(const std::string &filename, bool must_exist)
Definition: apr_scanner.cc:3177
Definition: apr_scanner.h:27
char * if_handler(double x)
Definition: apr_scanner.cc:3424
Definition: apr_aprepro.cc:68
yytokentype
Definition: aprepro_parser.h:191
void yyerror(const char *s)
Definition: apr_scanner.cc:3359