00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef _TOKENIZER_H_
00011 #define _TOKENIZER_H_
00012
00013 #include <string>
00014 #include <iostream>
00015
00016 using namespace std;
00017
00018
00019 class Tokenizer
00020 {
00021 public:
00022 enum TokenType
00023 {
00024 TokenName = 0,
00025 TokenString = 1,
00026 TokenNumber = 2,
00027 TokenBegin = 3,
00028 TokenEnd = 4,
00029 TokenNull = 5,
00030 TokenBeginGroup = 6,
00031 TokenEndGroup = 7,
00032 TokenBeginArray = 8,
00033 TokenEndArray = 9,
00034 TokenEquals = 10,
00035 TokenError = 11,
00036 TokenBar = 12,
00037 };
00038
00039 Tokenizer(istream*);
00040
00041 TokenType nextToken();
00042 TokenType getTokenType();
00043 void pushBack();
00044 double getNumberValue();
00045 string getNameValue();
00046 string getStringValue();
00047
00048 int getLineNumber() const;
00049
00050 private:
00051 enum State
00052 {
00053 StartState = 0,
00054 NameState = 1,
00055 NumberState = 2,
00056 FractionState = 3,
00057 ExponentState = 4,
00058 ExponentFirstState = 5,
00059 DotState = 6,
00060 CommentState = 7,
00061 StringState = 8,
00062 ErrorState = 9,
00063 StringEscapeState = 10,
00064 UnicodeEscapeState = 11,
00065 };
00066
00067 istream* in;
00068
00069 int nextChar;
00070 TokenType tokenType;
00071 bool haveValidNumber;
00072 bool haveValidName;
00073 bool haveValidString;
00074
00075 unsigned int unicodeValue;
00076 unsigned int unicodeEscapeDigits;
00077
00078 bool pushedBack;
00079
00080 int readChar();
00081 void syntaxError(const char*);
00082
00083 double numberValue;
00084
00085 string textToken;
00086
00087 int lineNum;
00088 };
00089
00090 #endif // _TOKENIZER_H_