• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

spl/interp/JsLex.h

00001 /*
00002  *   This file is part of the Standard Portable Library (SPL).
00003  *
00004  *   SPL is free software: you can redistribute it and/or modify
00005  *   it under the terms of the GNU General Public License as published by
00006  *   the Free Software Foundation, either version 3 of the License, or
00007  *   (at your option) any later version.
00008  *
00009  *   SPL is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details.
00013  *
00014  *   You should have received a copy of the GNU General Public License
00015  *   along with SPL.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 #ifndef _jslex_h
00018 #define _jslex_h
00019 
00020 #include <spl/Debug.h>
00021 #include <spl/Memory.h>
00022 #include <spl/io/IStream.h>
00023 #include <spl/String.h>
00024 #include <spl/text/StringBuffer.h>
00025 
00026 class JsLex : public IMemoryValidate
00027 {
00028 public:
00029         typedef enum _Token
00030         {
00031                 T_LEXERROR = 0,
00032                 T_IF = 257,
00033                 T_WHILE = 258,
00034                 T_FOR = 259,
00035                 T_VAR = 260,
00036                 T_RETURN = 261,
00037                 T_CLASS = 262,
00038                 T_PUBLIC = 263,
00039                 T_PRIVATE = 264,
00040                 T_PROTECTED = 265,
00041                 T_LBRACE = 266,
00042                 T_RBRACE = 267,
00043                 T_LPAR = 268,
00044                 T_RPAR = 269,
00045                 T_LBRAC = 270,
00046                 T_RBRAC = 271,
00047                 T_ID = 272,
00048                 T_CHAR = 273,
00049                 T_STRING = 274,
00050                 T_INT = 275,
00051                 T_REAL = 276,
00052                 T_ISNEQ = 277,
00053                 T_BANG = 278,
00054                 T_ISEQUAL = 279,
00055                 T_PLUSEQ = 280,
00056                 T_MINUSEQ = 281,
00057                 T_TIMESEQ = 282,
00058                 T_DIVEQ = 283,
00059                 T_MODEQ = 284,
00060                 T_XOREQ = 285,
00061                 T_ASSIGN = 286,
00062                 T_INC = 287,
00063                 T_DEC = 288,
00064                 T_PLUS = 289,
00065                 T_MINUS = 290,
00066                 T_STAR = 291,
00067                 T_SLASH = 293,
00068                 T_AND = 294,
00069                 T_AMPR = 295,
00070                 T_OR = 296,
00071                 T_PIPE = 297,
00072                 T_XOR = 298,
00073                 T_MOD = 299,
00074                 T_SCOPE = 300,
00075                 T_COLON = 301,
00076                 T_SEMI = 302,
00077                 T_DOT = 303,
00078                 T_COMMA = 304,
00079                 T_JEOF = 305,
00080                 T_STATIC = 306,
00081                 T_ELSE = 307,
00082                 T_BREAK = 308,
00083                 T_LT = 309,
00084                 T_GT = 310,
00085                 T_LTEQ = 311,
00086                 T_GTEQ = 312,
00087                 T_COMP = 313,
00088                 T_COMPEQ = 314,
00089                 T_DO = 315,
00090                 T_CONTINUE = 316,
00091                 T_OREQ = 317,
00092                 T_ANDEQ = 318,
00093                 T_HEX = 319,
00094                 T_SWITCH = 320,
00095                 T_CASE = 321,
00096                 T_NEW = 322,
00097                 T_DELETE = 323,
00098                 T_CONST = 324,
00099                 T_JNULL = 325,
00100                 T_TRY = 326,
00101                 T_CATCH = 327,
00102                 T_FINALLY = 329,
00103                 T_YYFALSE = 330,
00104                 T_YYTRUE = 331,
00105                 T_DEFAULT = 332,
00106                 T_THROW = 333,
00107                 T_LSHIFT = 334,
00108                 T_RSHIFT = 335
00109         } Token;
00110 
00111 private:
00112         spl::IStreamPtr m_text;
00113         int m_pushBack;
00114         int m_lineNo;
00115         StringBuffer m_lexum;
00116         Token m_token;
00117         
00118         inline bool IsWs(const int ch)
00119         {
00120                 return ! (isalnum(ch) || ispunct( ch ) || ch == -1);
00121         }
00122         
00123         int GetCh();
00124         void UnGetCh(const int ch);
00125         int GetEscape();
00126         void StripWS();
00127         
00128 public:
00129         JsLex();
00130         JsLex(spl::IStreamPtr stream);
00131         JsLex(const String& text);
00132         JsLex(const JsLex& lex);
00133         virtual ~JsLex();
00134   
00135         JsLex& operator =(const JsLex& lex);
00136         
00137         void Init(const String& text);
00138         void Init(spl::IStreamPtr text);
00139         
00140         Token Next();
00141         
00142         inline const StringBuffer& Lexum() { return m_lexum; }
00143         
00144         inline int LineNumber() const { return m_lineNo; }
00145 
00146 #if defined(DEBUG) || defined(_DEBUG)
00147         void CheckMem() const;
00148         void ValidateMem() const;
00149 #endif
00150 };
00151 
00152 #endif