OpenMW
components/compiler/scanner.hpp
Go to the documentation of this file.
00001 #ifndef COMPILER_SCANNER_H_INCLUDED
00002 #define COMPILER_SCANNER_H_INCLUDED
00003 
00004 #include <string>
00005 #include <iosfwd>
00006 #include <vector>
00007 
00008 #include "tokenloc.hpp"
00009 
00010 namespace Compiler
00011 {
00012     class ErrorHandler;
00013     class Parser;
00014     class Extensions;
00015 
00020 
00021     class Scanner
00022     {
00023             enum putback_type
00024             {
00025                 Putback_None, Putback_Special, Putback_Integer, Putback_Float,
00026                 Putback_Name, Putback_Keyword
00027             };
00028 
00029             ErrorHandler& mErrorHandler;
00030             TokenLoc mLoc;
00031             TokenLoc mPrevLoc;
00032             std::istream& mStream;
00033             const Extensions *mExtensions;
00034             putback_type mPutback;
00035             int mPutbackCode;
00036             int mPutbackInteger;
00037             float mPutbackFloat;
00038             std::string mPutbackName;
00039             TokenLoc mPutbackLoc;
00040 
00041         public:
00042 
00043             enum keyword
00044             {
00045                 K_begin, K_end,
00046                 K_short, K_long, K_float,
00047                 K_if, K_endif, K_else, K_elseif,
00048                 K_while, K_endwhile,
00049                 K_return,
00050                 K_messagebox,
00051                 K_set, K_to,
00052                 K_getsquareroot,
00053                 K_menumode,
00054                 K_random,
00055                 K_startscript, K_stopscript, K_scriptrunning,
00056                 K_getdistance,
00057                 K_getsecondspassed,
00058                 K_enable, K_disable, K_getdisabled
00059             };
00060 
00061             enum special
00062             {
00063                 S_newline,
00064                 S_open, S_close,
00065                 S_cmpEQ, S_cmpNE, S_cmpLT, S_cmpLE, S_cmpGT, S_cmpGE,
00066                 S_plus, S_minus, S_mult, S_div,
00067                 S_comma,
00068                 S_ref,
00069                 S_member
00070             };
00071 
00072         private:
00073 
00074         // not implemented
00075 
00076             Scanner (const Scanner&);
00077             Scanner& operator= (const Scanner&);
00078 
00079             bool get (char& c);
00080 
00081             void putback (char c);
00082 
00083             bool scanToken (Parser& parser);
00084 
00085             bool scanInt (char c, Parser& parser, bool& cont);
00086 
00087             bool scanFloat (const std::string& intValue, Parser& parser, bool& cont);
00088 
00089             bool scanName (char c, Parser& parser, bool& cont);
00090 
00091             bool scanName (char c, std::string& name);
00092 
00093             bool scanSpecial (char c, Parser& parser, bool& cont);
00094 
00095             static bool isWhitespace (char c);
00096 
00097         public:
00098 
00099             Scanner (ErrorHandler& errorHandler, std::istream& inputStream,
00100                 const Extensions *extensions = 0);
00102 
00103             void scan (Parser& parser);
00105 
00106             void putbackSpecial (int code, const TokenLoc& loc);
00108 
00109             void putbackInt (int value, const TokenLoc& loc);
00111 
00112             void putbackFloat (float value, const TokenLoc& loc);
00114 
00115             void putbackName (const std::string& name, const TokenLoc& loc);
00117 
00118             void putbackKeyword (int keyword, const TokenLoc& loc);
00120 
00121             void listKeywords (std::vector<std::string>& keywords);
00123     };
00124 }
00125 
00126 #endif