User Guide
diffeq_lexer.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2023 Blue Brain Project, EPFL.
3  * See the top-level LICENSE file for details.
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  */
7 
8 #pragma once
9 
10 #include "parser/diffeq/diffeq_parser.hpp"
11 
12 /**
13  * Flex expects the declaration of yylex to be defined in the macro YY_DECL
14  * and C++ parser class expects it to be declared.
15  */
16 #ifndef YY_DECL
17 #define YY_DECL nmodl::parser::DiffeqParser::symbol_type nmodl::parser::DiffeqLexer::next_token()
18 #endif
19 
20 /**
21  * For creating multiple (different) lexer classes, we can use `-P` flag
22  * (or prefix option) to rename each `yyFlexLexer` to some other name like
23  * `xxFlexLexer`. And then include <FlexLexer.h> in other sources once per
24  * lexer class, first renaming `yyFlexLexer `as shown below.
25  */
26 #ifndef __FLEX_LEXER_H
27 #define yyFlexLexer DiffEqFlexLexer
28 #include "FlexLexer.h"
29 #endif
30 
31 namespace nmodl {
32 namespace parser {
33 
34 /**
35  * @addtogroup lexer
36  * @{
37  */
38 
39 /**
40  * \class DiffeqLexer
41  * \brief Represent Lexer/Scanner class for differential equation parsing
42  *
43  * Lexer defined to add some extra function to the scanner class from flex.
44  * At the moment we are using basic functionality but it could be easily
45  * extended for further development.
46  */
47 class DiffeqLexer: public DiffEqFlexLexer {
48  public:
49  /// location of the parsed token
50  location loc;
51 
52  /// \name Ctor & dtor
53  /// \{
54 
55  /*
56  * \brief DiffeqLexer constructor
57  *
58  * @param in Input stream from where tokens will be read
59  * @param out Output stream where output will be sent
60  */
61  DiffeqLexer(std::istream* in = nullptr, std::ostream* out = nullptr)
62  : DiffEqFlexLexer(in, out) {}
63 
64  ~DiffeqLexer() override = default;
65 
66  /// \}
67 
68  /**
69  * \brief Function for lexer to scan token (replacement for \c yylex())
70  *
71  * This is main lexing function generated by `flex` according to the macro
72  * declaration \c YY_DECL. The generated bison parser then calls this virtual
73  * function to fetch new tokens. Note that \c yylex() has different declaration
74  * and hence can't be used for new lexer.
75  *
76  * @return Symbol encapsulating parsed token
77  */
79 };
80 
81 /** @} */ // end of lexer
82 
83 } // namespace parser
84 } // namespace nmodl
nmodl::parser::DiffeqLexer
Represent Lexer/Scanner class for differential equation parsing.
Definition: diffeq_lexer.hpp:47
nmodl
encapsulates code generation backend implementations
Definition: ast_common.hpp:26
nmodl::parser::DiffeqLexer::~DiffeqLexer
~DiffeqLexer() override=default
nmodl::parser::DiffeqLexer::next_token
virtual DiffeqParser::symbol_type next_token()
Function for lexer to scan token (replacement for yylex())
nmodl::parser::DiffeqLexer::DiffeqLexer
DiffeqLexer(std::istream *in=nullptr, std::ostream *out=nullptr)
Definition: diffeq_lexer.hpp:61
symbol_type
void symbol_type(const std::string &name, T &value)
Definition: modtoken.cpp:32
nmodl::parser::DiffeqLexer::loc
location loc
location of the parsed token
Definition: diffeq_lexer.hpp:50