torc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Scanner.hpp
Go to the documentation of this file.
1 // Torc - Copyright 2011-2013 University of Southern California. All Rights Reserved.
2 // $HeadURL$
3 // $Id$
4 
5 // This program is free software: you can redistribute it and/or modify it under the terms of the
6 // GNU General Public License as published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
11 // the GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License along with this program. If
14 // not, see <http://www.gnu.org/licenses/>.
15 
16 // FILE : scanner.hpp
17 // DATE : 08-July-2010
18 // DESCRIPTION : Declaration of torc::generic::Scanner class
19 // REVISION HISTORY:
20 // SI REVISION AUTHOR CHANGES PRs
21 // [0] Initial Version Niladri
22 
23 #ifndef TORC_GENERIC_EDIF_SCANNER_HPP
24 #define TORC_GENERIC_EDIF_SCANNER_HPP
25 
26 // Flex expects the signature of yylex to be defined in the macro YY_DECL, and
27 // the C++ parser expects it to be declared. We can factor both as follows.
28 
29 #ifndef YY_DECL
30 
31 #define YY_DECL \
32  torc::generic::Parser::token_type \
33  torc::generic::Scanner::lex( \
34  torc::generic::Parser::semantic_type* yylval, \
35  torc::generic::Parser::location_type* yylloc \
36  )
37 #endif
38 
39 #ifndef __FLEX_LEXER_H
40 #define yyFlexLexer EdifFlexLexer
42 #undef EdifFlexLexer
43 #endif
44 
46 
47 namespace torc {
48 namespace generic {
49 
50 /** Scanner is a derived class to add some extra function to the scanner
51  * class. Flex itself creates a class named FlexLexer, which is renamed using
52  * macros to EdifFlexLexer. However we change the context of the generated
53  * yylex() function to be contained within the Scanner class. This is required
54  * because the yylex() defined in EdifFlexLexer has no parameters. */
55 class Scanner : public EdifFlexLexer {
56 public:
57  /** Create a new scanner object. The streams arg_yyin and arg_yyout default
58  * to cin and cout, but that assignment is only made when initializing in
59  * yylex(). */
60  Scanner(std::istream* arg_yyin = 0, std::ostream* arg_yyout = 0);
61 
62  /** Required for virtual functions */
63  virtual ~Scanner();
64 
65  /** This is the main lexing function. It is generated by flex according to
66  * the macro declaration YY_DECL above. The generated bison parser then
67  * calls this virtual function to fetch new tokens. */
69 
70  /** Enable debug output (via arg_yyout) if compiled into the scanner. */
71  void set_debug(bool b);
72 
73  inline bool getIsIdContext() const;
74 
75  inline void setIsIdContext(bool inIsIdContext);
76 
77  void skipThisRule(char *yytext);
78 
79  inline bool getAppendToBuffer();
80 
81  void setAppendToBuffer(bool inAppendToBuffer);
82 
83  void resetBuffer();
84 
85  void addToBuffer(const char *str);
86 
87  inline std::string getBuffer();
88 
89  inline bool getAppendToUserDataBuffer();
90 
91  void setAppendToUserDataBuffer(bool inAppendToBuffer);
92 
93  void addToUserDataBuffer(const char *str);
94 
95  void resetUserDataBuffer();
96 
98 
99 private:
106 };
107 
108 inline bool Scanner::getIsIdContext() const {
109  return mIsIdContext;
110 }
111 
112 inline void Scanner::setIsIdContext(bool inIsIdContext) {
113  mIsIdContext = inIsIdContext;
114 }
115 
117  return mAppendToBuffer;
118 }
119 
121  return mBuffer;
122 }
123 
126 }
127 
129  return mUserDataBuffer;
130 }
131 
132 } // namespace generic
133 } // namespace torc
134 
135 #endif // TORC_GENERIC_EDIF_SCANNER_HPP
std::string mBuffer
Definition: Scanner.hpp:103
std::string mUserDataBuffer
Definition: Scanner.hpp:104
void setAppendToUserDataBuffer(bool inAppendToBuffer)
Definition: Scanner.cc:7098
void setAppendToBuffer(bool inAppendToBuffer)
Definition: Scanner.cc:7088
std::string string
std::string getUserDataBuffer()
Definition: Scanner.hpp:128
void addToUserDataBuffer(const char *str)
Definition: Scanner.cc:7116
void addToBuffer(const char *str)
Definition: Scanner.cc:7108
Symbol semantic values.
Definition: Parser.h:116
void set_debug(bool b)
Definition: Scanner.cc:7125
std::string getBuffer()
Definition: Scanner.hpp:120
bool getIsIdContext() const
Definition: Scanner.hpp:108
void skipThisRule(char *yytext)
Definition: Scanner.cc:7057
Scanner(std::istream *arg_yyin=0, std::ostream *arg_yyout=0)
Definition: Scanner.cc:7042
virtual Parser::token_type lex(Parser::semantic_type *yylval, Parser::location_type *yylloc)
bool getAppendToUserDataBuffer()
Definition: Scanner.hpp:124
void setIsIdContext(bool inIsIdContext)
Definition: Scanner.hpp:112