as_tokendef.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. /*
  2. AngelCode Scripting Library
  3. Copyright (c) 2003-2011 Andreas Jonsson
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any
  6. damages arising from the use of this software.
  7. Permission is granted to anyone to use this software for any
  8. purpose, including commercial applications, and to alter it and
  9. redistribute it freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you
  11. must not claim that you wrote the original software. If you use
  12. this software in a product, an acknowledgment in the product
  13. documentation would be appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and
  15. must not be misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source
  17. distribution.
  18. The original version of this library can be located at:
  19. http://www.angelcode.com/angelscript/
  20. Andreas Jonsson
  21. [email protected]
  22. */
  23. //
  24. // as_tokendef.h
  25. //
  26. // Definitions for tokens identifiable by the tokenizer
  27. //
  28. #ifndef AS_TOKENDEF_H
  29. #define AS_TOKENDEF_H
  30. #include "as_config.h"
  31. BEGIN_AS_NAMESPACE
  32. enum eTokenType
  33. {
  34. ttUnrecognizedToken,
  35. ttEnd, // End of file
  36. // White space and comments
  37. ttWhiteSpace, // ' ', '\t', '\r', '\n', UTF8 byte-order-mark
  38. ttOnelineComment, // // \n
  39. ttMultilineComment, // /* */
  40. // Atoms
  41. ttIdentifier, // abc123
  42. ttIntConstant, // 1234
  43. ttFloatConstant, // 12.34e56f
  44. ttDoubleConstant, // 12.34e56
  45. ttStringConstant, // "123"
  46. ttMultilineStringConstant, //
  47. ttHeredocStringConstant, // """text"""
  48. ttNonTerminatedStringConstant, // "123
  49. ttBitsConstant, // 0xFFFF
  50. // Math operators
  51. ttPlus, // +
  52. ttMinus, // -
  53. ttStar, // *
  54. ttSlash, // /
  55. ttPercent, // %
  56. ttHandle, // @
  57. ttAddAssign, // +=
  58. ttSubAssign, // -=
  59. ttMulAssign, // *=
  60. ttDivAssign, // /=
  61. ttModAssign, // %=
  62. ttOrAssign, // |=
  63. ttAndAssign, // &=
  64. ttXorAssign, // ^=
  65. ttShiftLeftAssign, // <<=
  66. ttShiftRightLAssign, // >>=
  67. ttShiftRightAAssign, // >>>=
  68. ttInc, // ++
  69. ttDec, // --
  70. ttDot, // .
  71. ttScope, // ::
  72. // Statement tokens
  73. ttAssignment, // =
  74. ttEndStatement, // ;
  75. ttListSeparator, // ,
  76. ttStartStatementBlock, // {
  77. ttEndStatementBlock, // }
  78. ttOpenParanthesis, // (
  79. ttCloseParanthesis, // )
  80. ttOpenBracket, // [
  81. ttCloseBracket, // ]
  82. ttAmp, // &
  83. // Bitwise operators
  84. ttBitOr, // |
  85. ttBitNot, // ~
  86. ttBitXor, // ^
  87. ttBitShiftLeft, // <<
  88. ttBitShiftRight, // >> // TODO: In Java this is the arithmetical shift
  89. ttBitShiftRightArith, // >>> // TODO: In Java this is the logical shift
  90. // Compare operators
  91. ttEqual, // ==
  92. ttNotEqual, // !=
  93. ttLessThan, // <
  94. ttGreaterThan, // >
  95. ttLessThanOrEqual, // <=
  96. ttGreaterThanOrEqual, // >=
  97. ttQuestion, // ?
  98. ttColon, // :
  99. // Reserved keywords
  100. ttIf, // if
  101. ttElse, // else
  102. ttFor, // for
  103. ttWhile, // while
  104. ttBool, // bool
  105. ttFuncDef, // funcdef
  106. ttImport, // import
  107. ttInt, // int
  108. ttInt8, // int8
  109. ttInt16, // int16
  110. ttInt64, // int64
  111. ttInterface, // interface
  112. ttIs, // is
  113. ttNotIs, // !is
  114. ttUInt, // uint
  115. ttUInt8, // uint8
  116. ttUInt16, // uint16
  117. ttUInt64, // uint64
  118. ttFloat, // float
  119. ttVoid, // void
  120. ttTrue, // true
  121. ttFalse, // false
  122. ttReturn, // return
  123. ttNot, // not
  124. ttAnd, // and
  125. ttOr, // or
  126. ttXor, // xor
  127. ttBreak, // break
  128. ttContinue, // continue
  129. ttConst, // const
  130. ttDo, // do
  131. ttDouble, // double
  132. ttSwitch, // switch
  133. ttCase, // case
  134. ttDefault, // default
  135. ttIn, // in
  136. ttOut, // out
  137. ttInOut, // inout
  138. ttNull, // null
  139. ttClass, // class
  140. ttTypedef, // typedef
  141. ttEnum, // enum
  142. ttCast, // cast
  143. ttPrivate // private
  144. };
  145. struct sTokenWord
  146. {
  147. const char *word;
  148. eTokenType tokenType;
  149. };
  150. sTokenWord const tokenWords[] =
  151. {
  152. {"+" , ttPlus},
  153. {"+=" , ttAddAssign},
  154. {"++" , ttInc},
  155. {"-" , ttMinus},
  156. {"-=" , ttSubAssign},
  157. {"--" , ttDec},
  158. {"*" , ttStar},
  159. {"*=" , ttMulAssign},
  160. {"/" , ttSlash},
  161. {"/=" , ttDivAssign},
  162. {"%" , ttPercent},
  163. {"%=" , ttModAssign},
  164. {"=" , ttAssignment},
  165. {"==" , ttEqual},
  166. {"." , ttDot},
  167. {"|" , ttBitOr},
  168. {"|=" , ttOrAssign},
  169. {"||" , ttOr},
  170. {"&" , ttAmp},
  171. {"&=" , ttAndAssign},
  172. {"&&" , ttAnd},
  173. {"^" , ttBitXor},
  174. {"^=" , ttXorAssign},
  175. {"^^" , ttXor},
  176. {"<" , ttLessThan},
  177. {"<=" , ttLessThanOrEqual},
  178. {"<<" , ttBitShiftLeft},
  179. {"<<=" , ttShiftLeftAssign},
  180. {">" , ttGreaterThan},
  181. {">=" , ttGreaterThanOrEqual},
  182. {">>" , ttBitShiftRight},
  183. {">>=" , ttShiftRightLAssign},
  184. {">>>" , ttBitShiftRightArith},
  185. {">>>=" , ttShiftRightAAssign},
  186. {"~" , ttBitNot},
  187. {";" , ttEndStatement},
  188. {"," , ttListSeparator},
  189. {"{" , ttStartStatementBlock},
  190. {"}" , ttEndStatementBlock},
  191. {"(" , ttOpenParanthesis},
  192. {")" , ttCloseParanthesis},
  193. {"[" , ttOpenBracket},
  194. {"]" , ttCloseBracket},
  195. {"?" , ttQuestion},
  196. {":" , ttColon},
  197. {"::" , ttScope},
  198. {"!" , ttNot},
  199. {"!=" , ttNotEqual},
  200. {"!is" , ttNotIs},
  201. {"@" , ttHandle},
  202. {"and" , ttAnd},
  203. {"bool" , ttBool},
  204. {"break" , ttBreak},
  205. {"case" , ttCase},
  206. {"cast" , ttCast},
  207. {"class" , ttClass},
  208. {"const" , ttConst},
  209. {"continue" , ttContinue},
  210. {"default" , ttDefault},
  211. {"do" , ttDo},
  212. #ifdef AS_USE_DOUBLE_AS_FLOAT
  213. {"double" , ttFloat},
  214. #else
  215. {"double" , ttDouble},
  216. #endif
  217. {"else" , ttElse},
  218. {"enum" , ttEnum},
  219. {"false" , ttFalse},
  220. {"float" , ttFloat},
  221. {"for" , ttFor},
  222. {"funcdef" , ttFuncDef},
  223. {"if" , ttIf},
  224. {"import" , ttImport},
  225. {"in" , ttIn},
  226. {"inout" , ttInOut},
  227. {"int" , ttInt},
  228. {"int8" , ttInt8},
  229. {"int16" , ttInt16},
  230. {"int32" , ttInt},
  231. {"int64" , ttInt64},
  232. {"interface" , ttInterface},
  233. {"is" , ttIs},
  234. {"not" , ttNot},
  235. {"null" , ttNull},
  236. {"or" , ttOr},
  237. {"out" , ttOut},
  238. {"private" , ttPrivate},
  239. {"return" , ttReturn},
  240. {"switch" , ttSwitch},
  241. {"true" , ttTrue},
  242. {"typedef" , ttTypedef},
  243. {"uint" , ttUInt},
  244. {"uint8" , ttUInt8},
  245. {"uint16" , ttUInt16},
  246. {"uint32" , ttUInt},
  247. {"uint64" , ttUInt64},
  248. {"void" , ttVoid},
  249. {"while" , ttWhile},
  250. {"xor" , ttXor},
  251. };
  252. const unsigned int numTokenWords = sizeof(tokenWords)/sizeof(sTokenWord);
  253. const char * const whiteSpace = " \t\r\n";
  254. // Some keywords that are not considered tokens by the parser
  255. // These only have meaning in specific situations. Outside these
  256. // situations they are treated as normal identifiers.
  257. const char * const THIS_TOKEN = "this";
  258. const char * const FROM_TOKEN = "from";
  259. const char * const SUPER_TOKEN = "super";
  260. const char * const SHARED_TOKEN = "shared";
  261. const char * const FINAL_TOKEN = "final";
  262. const char * const OVERRIDE_TOKEN = "override";
  263. const char * const GET_TOKEN = "get";
  264. const char * const SET_TOKEN = "set";
  265. END_AS_NAMESPACE
  266. #endif