| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301 |
- /*
- AngelCode Scripting Library
- Copyright (c) 2003-2011 Andreas Jonsson
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any
- damages arising from the use of this software.
- Permission is granted to anyone to use this software for any
- purpose, including commercial applications, and to alter it and
- redistribute it freely, subject to the following restrictions:
- 1. The origin of this software must not be misrepresented; you
- must not claim that you wrote the original software. If you use
- this software in a product, an acknowledgment in the product
- documentation would be appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and
- must not be misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source
- distribution.
- The original version of this library can be located at:
- http://www.angelcode.com/angelscript/
- Andreas Jonsson
- [email protected]
- */
- //
- // as_tokendef.h
- //
- // Definitions for tokens identifiable by the tokenizer
- //
- #ifndef AS_TOKENDEF_H
- #define AS_TOKENDEF_H
- #include "as_config.h"
- BEGIN_AS_NAMESPACE
- enum eTokenType
- {
- ttUnrecognizedToken,
- ttEnd, // End of file
- // White space and comments
- ttWhiteSpace, // ' ', '\t', '\r', '\n', UTF8 byte-order-mark
- ttOnelineComment, // // \n
- ttMultilineComment, // /* */
- // Atoms
- ttIdentifier, // abc123
- ttIntConstant, // 1234
- ttFloatConstant, // 12.34e56f
- ttDoubleConstant, // 12.34e56
- ttStringConstant, // "123"
- ttMultilineStringConstant, //
- ttHeredocStringConstant, // """text"""
- ttNonTerminatedStringConstant, // "123
- ttBitsConstant, // 0xFFFF
- // Math operators
- ttPlus, // +
- ttMinus, // -
- ttStar, // *
- ttSlash, // /
- ttPercent, // %
- ttHandle, // @
- ttAddAssign, // +=
- ttSubAssign, // -=
- ttMulAssign, // *=
- ttDivAssign, // /=
- ttModAssign, // %=
- ttOrAssign, // |=
- ttAndAssign, // &=
- ttXorAssign, // ^=
- ttShiftLeftAssign, // <<=
- ttShiftRightLAssign, // >>=
- ttShiftRightAAssign, // >>>=
- ttInc, // ++
- ttDec, // --
- ttDot, // .
- ttScope, // ::
- // Statement tokens
- ttAssignment, // =
- ttEndStatement, // ;
- ttListSeparator, // ,
- ttStartStatementBlock, // {
- ttEndStatementBlock, // }
- ttOpenParanthesis, // (
- ttCloseParanthesis, // )
- ttOpenBracket, // [
- ttCloseBracket, // ]
- ttAmp, // &
- // Bitwise operators
- ttBitOr, // |
- ttBitNot, // ~
- ttBitXor, // ^
- ttBitShiftLeft, // <<
- ttBitShiftRight, // >> // TODO: In Java this is the arithmetical shift
- ttBitShiftRightArith, // >>> // TODO: In Java this is the logical shift
- // Compare operators
- ttEqual, // ==
- ttNotEqual, // !=
- ttLessThan, // <
- ttGreaterThan, // >
- ttLessThanOrEqual, // <=
- ttGreaterThanOrEqual, // >=
- ttQuestion, // ?
- ttColon, // :
- // Reserved keywords
- ttIf, // if
- ttElse, // else
- ttFor, // for
- ttWhile, // while
- ttBool, // bool
- ttFuncDef, // funcdef
- ttImport, // import
- ttInt, // int
- ttInt8, // int8
- ttInt16, // int16
- ttInt64, // int64
- ttInterface, // interface
- ttIs, // is
- ttNotIs, // !is
- ttUInt, // uint
- ttUInt8, // uint8
- ttUInt16, // uint16
- ttUInt64, // uint64
- ttFloat, // float
- ttVoid, // void
- ttTrue, // true
- ttFalse, // false
- ttReturn, // return
- ttNot, // not
- ttAnd, // and
- ttOr, // or
- ttXor, // xor
- ttBreak, // break
- ttContinue, // continue
- ttConst, // const
- ttDo, // do
- ttDouble, // double
- ttSwitch, // switch
- ttCase, // case
- ttDefault, // default
- ttIn, // in
- ttOut, // out
- ttInOut, // inout
- ttNull, // null
- ttClass, // class
- ttTypedef, // typedef
- ttEnum, // enum
- ttCast, // cast
- ttPrivate // private
- };
- struct sTokenWord
- {
- const char *word;
- eTokenType tokenType;
- };
- sTokenWord const tokenWords[] =
- {
- {"+" , ttPlus},
- {"+=" , ttAddAssign},
- {"++" , ttInc},
- {"-" , ttMinus},
- {"-=" , ttSubAssign},
- {"--" , ttDec},
- {"*" , ttStar},
- {"*=" , ttMulAssign},
- {"/" , ttSlash},
- {"/=" , ttDivAssign},
- {"%" , ttPercent},
- {"%=" , ttModAssign},
- {"=" , ttAssignment},
- {"==" , ttEqual},
- {"." , ttDot},
- {"|" , ttBitOr},
- {"|=" , ttOrAssign},
- {"||" , ttOr},
- {"&" , ttAmp},
- {"&=" , ttAndAssign},
- {"&&" , ttAnd},
- {"^" , ttBitXor},
- {"^=" , ttXorAssign},
- {"^^" , ttXor},
- {"<" , ttLessThan},
- {"<=" , ttLessThanOrEqual},
- {"<<" , ttBitShiftLeft},
- {"<<=" , ttShiftLeftAssign},
- {">" , ttGreaterThan},
- {">=" , ttGreaterThanOrEqual},
- {">>" , ttBitShiftRight},
- {">>=" , ttShiftRightLAssign},
- {">>>" , ttBitShiftRightArith},
- {">>>=" , ttShiftRightAAssign},
- {"~" , ttBitNot},
- {";" , ttEndStatement},
- {"," , ttListSeparator},
- {"{" , ttStartStatementBlock},
- {"}" , ttEndStatementBlock},
- {"(" , ttOpenParanthesis},
- {")" , ttCloseParanthesis},
- {"[" , ttOpenBracket},
- {"]" , ttCloseBracket},
- {"?" , ttQuestion},
- {":" , ttColon},
- {"::" , ttScope},
- {"!" , ttNot},
- {"!=" , ttNotEqual},
- {"!is" , ttNotIs},
- {"@" , ttHandle},
- {"and" , ttAnd},
- {"bool" , ttBool},
- {"break" , ttBreak},
- {"case" , ttCase},
- {"cast" , ttCast},
- {"class" , ttClass},
- {"const" , ttConst},
- {"continue" , ttContinue},
- {"default" , ttDefault},
- {"do" , ttDo},
- #ifdef AS_USE_DOUBLE_AS_FLOAT
- {"double" , ttFloat},
- #else
- {"double" , ttDouble},
- #endif
- {"else" , ttElse},
- {"enum" , ttEnum},
- {"false" , ttFalse},
- {"float" , ttFloat},
- {"for" , ttFor},
- {"funcdef" , ttFuncDef},
- {"if" , ttIf},
- {"import" , ttImport},
- {"in" , ttIn},
- {"inout" , ttInOut},
- {"int" , ttInt},
- {"int8" , ttInt8},
- {"int16" , ttInt16},
- {"int32" , ttInt},
- {"int64" , ttInt64},
- {"interface" , ttInterface},
- {"is" , ttIs},
- {"not" , ttNot},
- {"null" , ttNull},
- {"or" , ttOr},
- {"out" , ttOut},
- {"private" , ttPrivate},
- {"return" , ttReturn},
- {"switch" , ttSwitch},
- {"true" , ttTrue},
- {"typedef" , ttTypedef},
- {"uint" , ttUInt},
- {"uint8" , ttUInt8},
- {"uint16" , ttUInt16},
- {"uint32" , ttUInt},
- {"uint64" , ttUInt64},
- {"void" , ttVoid},
- {"while" , ttWhile},
- {"xor" , ttXor},
- };
- const unsigned int numTokenWords = sizeof(tokenWords)/sizeof(sTokenWord);
- const char * const whiteSpace = " \t\r\n";
- // Some keywords that are not considered tokens by the parser
- // These only have meaning in specific situations. Outside these
- // situations they are treated as normal identifiers.
- const char * const THIS_TOKEN = "this";
- const char * const FROM_TOKEN = "from";
- const char * const SUPER_TOKEN = "super";
- const char * const SHARED_TOKEN = "shared";
- const char * const FINAL_TOKEN = "final";
- const char * const OVERRIDE_TOKEN = "override";
- const char * const GET_TOKEN = "get";
- const char * const SET_TOKEN = "set";
- END_AS_NAMESPACE
- #endif
|