OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
scanner.hpp
Go to the documentation of this file.
1 #ifndef COMPILER_SCANNER_H_INCLUDED
2 #define COMPILER_SCANNER_H_INCLUDED
3 
4 #include <string>
5 #include <iosfwd>
6 #include <vector>
7 
8 #include "tokenloc.hpp"
9 
10 namespace Compiler
11 {
12  class ErrorHandler;
13  class Parser;
14  class Extensions;
15 
20 
21  class Scanner
22  {
24  {
27  };
28 
32  std::istream& mStream;
38  std::string mPutbackName;
41 
42  public:
43 
44  enum keyword
45  {
60  };
61 
62  enum special
63  {
71  };
72 
73  private:
74 
75  // not implemented
76 
77  Scanner (const Scanner&);
78  Scanner& operator= (const Scanner&);
79 
80  bool get (char& c);
81 
82  void putback (char c);
83 
84  bool scanToken (Parser& parser);
85 
86  bool scanInt (char c, Parser& parser, bool& cont);
87 
88  bool scanFloat (const std::string& intValue, Parser& parser, bool& cont);
89 
90  bool scanName (char c, Parser& parser, bool& cont);
91 
93  bool scanName (std::string& name);
94 
95  bool scanSpecial (char c, Parser& parser, bool& cont);
96 
97  bool isStringCharacter (char c, bool lookAhead = true);
98 
99  static bool isWhitespace (char c);
100 
101  public:
102 
103  Scanner (ErrorHandler& errorHandler, std::istream& inputStream,
104  const Extensions *extensions = 0);
106 
107  void scan (Parser& parser);
109 
110  void putbackSpecial (int code, const TokenLoc& loc);
112 
113  void putbackInt (int value, const TokenLoc& loc);
115 
116  void putbackFloat (float value, const TokenLoc& loc);
118 
119  void putbackName (const std::string& name, const TokenLoc& loc);
121 
122  void putbackKeyword (int keyword, const TokenLoc& loc);
124 
125  void listKeywords (std::vector<std::string>& keywords);
127 
131  void enableStrictKeywords();
132  };
133 }
134 
135 #endif
Definition: scanner.hpp:56
bool scanSpecial(char c, Parser &parser, bool &cont)
Definition: scanner.cpp:379
Definition: scanner.hpp:67
Definition: scanner.hpp:67
putback_type mPutback
Definition: scanner.hpp:34
Definition: scanner.hpp:66
Definition: scanner.hpp:49
Definition: scanner.hpp:25
Definition: scanner.hpp:66
Definition: scanner.hpp:46
TokenLoc mLoc
Definition: scanner.hpp:30
float mPutbackFloat
Definition: scanner.hpp:37
void listKeywords(std::vector< std::string > &keywords)
Append all known keywords to keywords.
Definition: scanner.cpp:619
Definition: scanner.hpp:48
bool scanInt(char c, Parser &parser, bool &cont)
Definition: scanner.cpp:165
bool scanName(char c, Parser &parser, bool &cont)
Definition: scanner.cpp:282
void enableStrictKeywords()
Definition: scanner.cpp:628
Definition: scanner.hpp:66
void putbackName(const std::string &name, const TokenLoc &loc)
put back a name token
Definition: scanner.cpp:605
Location of a token in a source file.
Definition: tokenloc.hpp:10
Scanner & operator=(const Scanner &)
Definition: scanner.hpp:56
Definition: scanner.hpp:49
Definition: scanner.hpp:64
keyword
Definition: scanner.hpp:44
Definition: scanner.hpp:26
Definition: scanner.hpp:46
Definition: scanner.hpp:25
Definition: scanner.hpp:59
Definition: scanner.hpp:48
Definition: scanner.hpp:57
TokenLoc mPutbackLoc
Definition: scanner.hpp:39
Definition: scanner.hpp:48
Definition: scanner.hpp:67
bool mStrictKeywords
Definition: scanner.hpp:40
Scanner(const Scanner &)
Error handling.
Definition: errorhandler.hpp:14
Definition: scanner.hpp:67
special
Definition: scanner.hpp:62
Definition: scanner.hpp:66
Collection of compiler extensions.
Definition: extensions.hpp:39
Definition: scanner.hpp:25
std::istream & mStream
Definition: scanner.hpp:32
void putbackSpecial(int code, const TokenLoc &loc)
put back a special token
Definition: scanner.cpp:584
Definition: scanner.hpp:53
Definition: scanner.hpp:59
Definition: scanner.hpp:56
Definition: scanner.hpp:69
Definition: scanner.hpp:26
Definition: scanner.hpp:59
std::string mPutbackName
Definition: scanner.hpp:38
void putback(char c)
Definition: scanner.cpp:43
Definition: scanner.hpp:58
Definition: scanner.hpp:66
Definition: scanner.hpp:68
Definition: scanner.hpp:65
bool scanToken(Parser &parser)
Definition: scanner.cpp:49
Definition: scanner.hpp:54
int code
Definition: crashcatcher.cpp:70
ErrorHandler & mErrorHandler
Definition: scanner.hpp:29
Definition: scanner.hpp:65
putback_type
Definition: scanner.hpp:23
Definition: scanner.hpp:47
Definition: scanner.hpp:47
Definition: scanner.hpp:47
bool isStringCharacter(char c, bool lookAhead=true)
Definition: scanner.cpp:553
Definition: scanner.hpp:52
int mPutbackCode
Definition: scanner.hpp:35
Parser base class.
Definition: parser.hpp:17
Definition: scanner.hpp:25
void putbackFloat(float value, const TokenLoc &loc)
put back a float token
Definition: scanner.cpp:598
Definition: scanner.hpp:66
void putbackInt(int value, const TokenLoc &loc)
put back an integer token
Definition: scanner.cpp:591
Definition: scanner.hpp:52
Definition: scanner.hpp:48
static bool isWhitespace(char c)
Definition: scanner.cpp:564
void scan(Parser &parser)
Scan a token and deliver it to the parser.
Definition: scanner.cpp:579
Definition: scanner.hpp:50
Definition: scanner.hpp:51
int mPutbackInteger
Definition: scanner.hpp:36
void putbackKeyword(int keyword, const TokenLoc &loc)
put back a keyword token
Definition: scanner.cpp:612
bool scanFloat(const std::string &intValue, Parser &parser, bool &cont)
Definition: scanner.cpp:223
const Extensions * mExtensions
Definition: scanner.hpp:33
Definition: scanner.hpp:55
Scanner.
Definition: scanner.hpp:21
TokenLoc mPrevLoc
Definition: scanner.hpp:31
const char * name
Definition: crashcatcher.cpp:59
Definition: scanner.hpp:70