Aprepro 5.0x
Loading...
Searching...
No Matches
apr_scanner.h
Go to the documentation of this file.
1/*
2 * Copyright(C) 1999-2020, 2022, 2023 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 APR_SCANNER_H
9#define APR_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#undef YY_DECL
15#define YY_DECL SEAMS::Parser::token_type SEAMS::Scanner::lex(SEAMS::Parser::semantic_type *yylval)
16
17#ifndef __FLEX_LEXER_H
18#define yyFlexLexer SEAMSFlexLexer
19#include "FlexLexer.h"
20#undef yyFlexLexer
21#endif
22
23#include <iostream>
24
25namespace SEAMS {
26
27 /** Scanner is a derived class to add some extra function to the scanner
28 * class. Flex itself creates a class named yyFlexLexer, which is renamed using
29 * macros to SEAMSFlexLexer. However we change the context of the generated
30 * yylex() function to be contained within the Scanner class. This is required
31 * because the yylex() defined in SEAMSFlexLexer has no parameters. */
32 class Aprepro;
33 class Scanner : public SEAMSFlexLexer
34 {
35 public:
36 friend class Parser;
37
38 /** Create a new scanner object. The streams arg_yyin and arg_yyout default
39 * to cin and cout, but that assignment is only made when initializing in
40 * yylex(). */
41 explicit Scanner(Aprepro &aprepro_yyarg, std::istream *in = nullptr,
42 std::ostream *out = nullptr);
43 /** Required for virtual functions */
44 ~Scanner() override;
45
46 bool add_include_file(const std::string &filename, bool must_exist);
47 int yywrap() override;
48 void yyerror(const char *s);
49 void LexerOutput(const char *buf, int size) override;
50 int LexerInput(char *buf, int max_size) override;
51
52 /** This is the main lexing function. It is generated by flex according to
53 * the macro declaration YY_DECL above. The generated bison parser then
54 * calls this virtual function to fetch new tokens. */
56
57 char *rescan(char *string);
58 char *execute(char *string);
59 char *import_handler(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. */
70
71 /* save the original string for substitution history */
73 };
74
75} // namespace SEAMS
76
77#endif // APR_SCANNER_H
Definition FlexLexer.h:108
Definition aprepro.h:90
A Bison parser.
Definition aprepro_parser.h:183
Definition apr_scanner.h:34
void LexerOutput(const char *buf, int size) override
int LexerInput(char *buf, int max_size) override
class Aprepro & aprepro
Definition apr_scanner.h:69
void save_history_string()
Scanner(Aprepro &aprepro_yyarg, std::istream *in=nullptr, std::ostream *out=nullptr)
void set_debug(bool b)
bool add_include_file(const std::string &filename, bool must_exist)
char * execute(char *string)
char * import_handler(char *string)
~Scanner() override
char * elseif_handler(double x)
char * if_handler(double x)
int yywrap() override
char * switch_handler(double x)
virtual Parser::token_type lex(Parser::semantic_type *yylval)
char * rescan(char *string)
void yyerror(const char *s)
char * case_handler(double x)
Definition apr_aprepro.cc:57
token_kind_type
Definition aprepro_parser.h:216
Symbol semantic values.
Definition aprepro_parser.h:192