00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef CELSCRIPT_SCANNER_H_
00011 #define CELSCRIPT_SCANNER_H_
00012
00013 #include <celscript/celx.h>
00014 #include <string>
00015 #include <iostream>
00016
00017 namespace celx
00018 {
00019
00020 class Scanner
00021 {
00022 public:
00023 enum TokenType
00024 {
00025 TokenName = 0,
00026 TokenString = 1,
00027 TokenNumber = 2,
00028 TokenBegin = 3,
00029 TokenEnd = 4,
00030 TokenNull = 5,
00031 TokenBeginGroup = 6,
00032 TokenEndGroup = 7,
00033 TokenBeginArray = 8,
00034 TokenEndArray = 9,
00035 TokenEqual = 10,
00036 TokenNotEqual = 11,
00037 TokenBar = 12,
00038 TokenOpen = 13,
00039 TokenClose = 14,
00040 TokenPlus = 15,
00041 TokenMinus = 16,
00042 TokenMultiply = 17,
00043 TokenDivide = 18,
00044 TokenEndStatement = 19,
00045 TokenAssign = 20,
00046 TokenGreater = 21,
00047 TokenLesser = 22,
00048 TokenGreaterEqual = 23,
00049 TokenLesserEqual = 24,
00050 TokenNot = 25,
00051 TokenComma = 26,
00052 KeywordIf = 50,
00053 KeywordElse = 51,
00054 KeywordFor = 52,
00055 KeywordWhile = 53,
00056 KeywordTrue = 54,
00057 KeywordFalse = 55,
00058 KeywordNull = 56,
00059 KeywordVar = 57,
00060 KeywordReturn = 58,
00061 KeywordFunction = 59,
00062 KeywordLambda = 60,
00063 TokenError = 255,
00064 };
00065
00066 Scanner(std::istream*);
00067
00068 TokenType nextToken();
00069 TokenType getTokenType();
00070 void pushBack();
00071 double getNumberValue();
00072 std::string getNameValue();
00073 std::string getStringValue();
00074
00075 int getLineNumber();
00076
00077 private:
00078 enum State
00079 {
00080 StartState = 0,
00081 NameState = 1,
00082 NumberState = 2,
00083 FractionState = 3,
00084 ExponentState = 4,
00085 ExponentFirstState = 5,
00086 DotState = 6,
00087 CommentState = 7,
00088 StringState = 8,
00089 ErrorState = 9,
00090 StringEscapeState = 10,
00091 MinusState = 11,
00092 PlusState = 12,
00093 EqualState = 13,
00094 AsteriskState = 14,
00095 SlashState = 15,
00096 LessState = 16,
00097 GreaterState = 17,
00098 BangState = 18,
00099 };
00100
00101 std::istream* in;
00102
00103 int nextChar;
00104 TokenType tokenType;
00105 bool haveValidNumber;
00106 bool haveValidName;
00107 bool haveValidString;
00108
00109 bool pushedBack;
00110
00111 int readChar();
00112 void syntaxError(char*);
00113
00114 double numberValue;
00115
00116 std::string textToken;
00117 };
00118
00119 }
00120
00121 #endif // _SCANNER_H_