CommandScanner.h
1 /*
2  * PFPSim: Library for the Programmable Forwarding Plane Simulation Framework
3  *
4  * Copyright (C) 2016 Concordia Univ., Montreal
5  * Samar Abdi
6  * Umair Aftab
7  * Gordon Bailey
8  * Faras Dewal
9  * Shafigh Parsazad
10  * Eric Tremblay
11  *
12  * Copyright (C) 2016 Ericsson
13  * Bochra Boughzala
14  *
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * as published by the Free Software Foundation; either version 2
18  * of the License, or (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program; if not, write to the Free Software
27  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
28  * 02110-1301, USA.
29  */
30 
31 // Generated by Flexc++ V2.01.00 on Sun, 03 Apr 2016 08:35:18 -0400
32 
33 #ifndef CORE_CP_COMMANDSCANNER_H_
34 #define CORE_CP_COMMANDSCANNER_H_
35 #include <string>
36 
37 #ifndef pfp_cpCommandScannerBase_h_included
38 #include "NAMESPACE_HACK_BEGIN"
39 // $insert baseclass_h
40 #include "CommandScannerbase.h"
41 #include "NAMESPACE_HACK_END"
42 #endif
43 
44 #ifndef pfp_cpCommandParserBase_h_included
45 #include "NAMESPACE_HACK_BEGIN" // NOLINT(build/include)
46 #include "CommandParserbase.h"
47 #include "NAMESPACE_HACK_END" // NOLINT(build/include)
48 #endif
49 
50 // #define SCANNER_DEBUG 1
51 
52 #include "NAMESPACE_HACK_BEGIN" // NOLINT(build/include)
53 // $insert namespace-open
54 namespace pfp_cp {
55 
56 // $insert classHead
57 class CommandScanner: public CommandScannerBase {
58  public:
59  explicit CommandScanner(std::istream &in = std::cin,
60  std::ostream &out = std::cout);
61 
62  CommandScanner(std::string const &infile, std::string const &outfile);
63 
64  // $insert lexFunctionDecl
65  int lex();
66  // See https://fbb-git.github.io/bisoncpp/manual/bisonc++06.html#DVAL
67  void setSval(Meta__::SType *);
68 
69  private:
70  Meta__::SType * val;
71 
72  template <typename T>
73  void returnValue(T);
74 
75  private:
76  int lex__();
77  int executeAction__(size_t ruleNr);
78 
79  void print();
80  void preCode(); // re-implement this function for code that must
81  // be exec'ed before the patternmatching starts
82 
83  void postCode(PostEnum__ type);
84  // re-implement this function for code that must
85  // be exec'ed after the rules's actions.
86 };
87 
88 #ifdef SCANNER_DEBUG
89  #define returnToken(symbol) do { \
90  std::cout << #symbol << std::endl; \
91  return Parser::symbol;\
92  } while (0)
93 #else
94  #define returnToken(symbol) return CommandParser::symbol
95 #endif
96 
97 template <typename T>
98 void CommandScanner::returnValue(T t) {
99  val->get< Meta__::TagOf<T>::tag >() = t;
100 }
101 
102 inline void CommandScanner::setSval(Meta__::SType * sval) {
103  val = sval;
104 }
105 
106 // $insert scannerConstructors
107 inline CommandScanner::CommandScanner(std::istream &in, std::ostream &out)
108 :
109  CommandScannerBase(in, out)
110 {}
111 
112 inline CommandScanner::CommandScanner(std::string const &infile,
113  std::string const &outfile): CommandScannerBase(infile, outfile) {}
114 
115 // $insert inlineLexFunction
116 inline int CommandScanner::lex() {
117  return lex__();
118 }
119 
120 inline void CommandScanner::preCode() {
121  // optionally replace by your own code
122 }
123 
124 inline void CommandScanner::postCode(PostEnum__ type) {
125  // optionally replace by your own code
126 }
127 
128 inline void CommandScanner::print() {
129  print__();
130 }
131 
132 // $insert namespace-close
133 }; // namespace pfp_cp
134 #include "NAMESPACE_HACK_END" // NOLINT(build/include)
135 
136 #endif // CORE_CP_COMMANDSCANNER_H_
Definition: CommandParser.h:50