Aprepro  5.0x
apr_scanner.h
Go to the documentation of this file.
1 /*
2  * Copyright(C) 1999-2020 National Technology & Engineering Solutions
3  * of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
4  * NTESS, the U.S. Government retains certain rights in this software.
5  *
6  * See packages/seacas/LICENSE for details
7  */
8 #ifndef EXAMPLE_SCANNER_H
9 #define EXAMPLE_SCANNER_H
10 
11 // Flex expects the signature of yylex to be defined in the macro YY_DECL, and
12 // the C++ parser expects it to be declared. We can factor both as follows.
13 
14 #ifndef YY_DECL
15 
16 #define YY_DECL SEAMS::Parser::token_type SEAMS::Scanner::lex(SEAMS::Parser::semantic_type *yylval)
17 #endif
18 
19 #ifndef __FLEX_LEXER_H
20 #define yyFlexLexer SEAMSFlexLexer
21 #include "FlexLexer.h"
22 #undef yyFlexLexer
23 #endif
24 
25 #include <iostream>
26 
27 namespace SEAMS {
28 
29  /** Scanner is a derived class to add some extra function to the scanner
30  * class. Flex itself creates a class named yyFlexLexer, which is renamed using
31  * macros to SEAMSFlexLexer. However we change the context of the generated
32  * yylex() function to be contained within the Scanner class. This is required
33  * because the yylex() defined in SEAMSFlexLexer has no parameters. */
34  class Scanner : public SEAMSFlexLexer
35  {
36  public:
37  friend class Parser;
38 
39  /** Create a new scanner object. The streams arg_yyin and arg_yyout default
40  * to cin and cout, but that assignment is only made when initializing in
41  * yylex(). */
42  explicit Scanner(Aprepro &aprepro_yyarg, std::istream *in = nullptr,
43  std::ostream *out = nullptr);
44  /** Required for virtual functions */
45  ~Scanner() override;
46 
47  void add_include_file(const std::string &filename, bool must_exist);
48  int yywrap() override;
49  void yyerror(const char *s);
50  void LexerOutput(const char *buf, int size) override;
51  int LexerInput(char *buf, int max_size) override;
52 
53  /** This is the main lexing function. It is generated by flex according to
54  * the macro declaration YY_DECL above. The generated bison parser then
55  * calls this virtual function to fetch new tokens. */
57 
58  char *rescan(char *string);
59  char *execute(char *string);
60  char *if_handler(double x);
61  char *elseif_handler(double x);
62  char *switch_handler(double x);
63  char *case_handler(double x);
64 
65  /** Enable debug output (via arg_yyout) if compiled into the scanner. */
66  void set_debug(bool b);
67 
68  /* User arguments. */
69  class Aprepro &aprepro;
70 
71  /* save the original string for substitution history */
72  void save_history_string();
73  };
74 
75 } // namespace SEAMS
76 
77 #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:3404
SEAMS
Definition: apr_aprepro.cc:41
SEAMS::Scanner::yywrap
int yywrap() override
Definition: apr_scanner.cc:3236
SEAMS::Parser::token::yytokentype
yytokentype
Definition: aprepro_parser.h:191
SEAMS::Scanner::~Scanner
~Scanner() override
Definition: apr_scanner.cc:3155
SEAMS::Scanner::switch_handler
char * switch_handler(double x)
Definition: apr_scanner.cc:3443
FlexLexer.h
SEAMS::Scanner::add_include_file
void add_include_file(const std::string &filename, bool must_exist)
Definition: apr_scanner.cc:3157
SEAMS::Scanner::save_history_string
void save_history_string()
Definition: apr_scanner.cc:3500
SEAMS::Scanner::rescan
char * rescan(char *string)
Definition: apr_scanner.cc:3377
SEAMS::Scanner::execute
char * execute(char *string)
Definition: apr_scanner.cc:3341
SEAMS::Scanner::case_handler
char * case_handler(double x)
Definition: apr_scanner.cc:3464
SEAMS::Scanner::aprepro
class Aprepro & aprepro
Definition: apr_scanner.h:69
SEAMS::Scanner::Scanner
Scanner(Aprepro &aprepro_yyarg, std::istream *in=nullptr, std::ostream *out=nullptr)
Definition: apr_scanner.cc:3149
SEAMS::Scanner::LexerOutput
void LexerOutput(const char *buf, int size) override
Definition: apr_scanner.cc:3181
SEAMS::Scanner::set_debug
void set_debug(bool b)
SEAMS::Scanner::yyerror
void yyerror(const char *s)
Definition: apr_scanner.cc:3339
SEAMS::Scanner::elseif_handler
char * elseif_handler(double x)
Definition: apr_scanner.cc:3427
SEAMS::Scanner::lex
virtual Parser::token_type lex(Parser::semantic_type *yylval)
SEAMS::Scanner
Definition: apr_scanner.h:35
SEAMS::Aprepro
Definition: aprepro.h:159
SEAMSFlexLexer
Definition: FlexLexer.h:108
SEAMS::Scanner::LexerInput
int LexerInput(char *buf, int max_size) override
Definition: apr_scanner.cc:3199
SEAMS::Parser
A Bison parser.
Definition: aprepro_parser.h:160