| author | David Anderson <dvander@alliedmods.net> |
| Sat Aug 04 21:06:47 2012 -0700 (2012-08-04) | |
| changeset 149 | b01ee7446984 |
| parent 148 | c0740249963c |
| child 172 | 48cffae8c9e0 |
| permissions | -rw-r--r-- |
1 /* vim: set ts=4 sw=4 tw=99 et:
2 *
3 * Copyright (C) 2012 David Anderson
4 *
5 * This file is part of SourcePawn.
6 *
7 * SourcePawn is free software: you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License as published by the Free
9 * Software Foundation, either version 3 of the License, or (at your option)
10 * any later version.
11 *
12 * SourcePawn is distributed in the hope that it will be useful, but WITHOUT ANY
13 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * SourcePawn. If not, see http://www.gnu.org/licenses/.
18 */
19 #ifndef _include_jitcraft_token_h_
20 #define _include_jitcraft_token_h_
22 namespace ke {
24 struct SourcePosition
25 {
26 int line;
27 int col;
29 SourcePosition()
30 : line(-1),
31 col(-1)
32 {
33 }
35 SourcePosition(unsigned line, unsigned col)
36 : line(line),
37 col(col)
38 {
39 }
40 };
42 // List of tokens the scanner can recognize.
43 //
44 // Some restrictions:
45 // * (ASSIGN_ADD - TOK_PLUS) must be the delta between an operator and its
46 // op-and-assign equivalent.
47 #define TOKENMAP(_) \
48 _(ERROR, "<error>") \
49 _(NEW, "'new'") \
50 _(FOR, "'for'") \
51 _(RETURN, "'return'") \
52 _(NAME, "<name>") \
53 _(INTEGER_LITERAL, "<integer>") \
54 _(FLOAT_LITERAL, "<float>") \
55 _(STRING_LITERAL, "<string>") \
56 _(IF, "<if>") \
57 _(ELSE, "<else>") \
58 _(ENUM, "<enum>") \
59 _(LABEL, "<label>") \
60 _(WHILE, "<while>") \
61 _(DO, "<do>") \
62 _(BREAK, "<break>") \
63 _(CONTINUE, "<continue>") \
64 _(FORWARD, "<forward>") \
65 _(PUBLIC, "<public>") \
66 _(CONST, "<const>") \
67 _(NATIVE, "<native>") \
68 _(STOCK, "<stock>") \
69 _(TRUE, "<true>") \
70 _(FALSE, "<false>") \
71 _(STRUCT, "<struct>") \
72 _(ELLIPSES, "...") \
73 _(PLUS, "+") \
74 _(MINUS, "-") \
75 _(STAR, "*") \
76 _(SLASH, "/") \
77 _(PERCENT, "%") \
78 _(AMPERSAND, "&") \
79 _(BITOR, "|") \
80 _(BITXOR, "^") \
81 _(SHR, ">>") \
82 _(USHR, ">>>") \
83 _(SHL, "<<") \
84 _(ASSIGN, "=") \
85 _(SEMICOLON, ";") \
86 _(LBRACE, "{") \
87 _(RBRACE, "}") \
88 _(LPAREN, "(") \
89 _(RPAREN, ")") \
90 _(LBRACKET, "[") \
91 _(RBRACKET, "]") \
92 _(ASSIGN_ADD, "+=") \
93 _(ASSIGN_SUB, "-=") \
94 _(ASSIGN_MUL, "*=") \
95 _(ASSIGN_DIV, "/=") \
96 _(ASSIGN_MOD, "%=") \
97 _(ASSIGN_BITAND, "&=") \
98 _(ASSIGN_BITOR, "|=") \
99 _(ASSIGN_BITXOR, "^=") \
100 _(ASSIGN_SHR, ">>=") \
101 _(ASSIGN_USHR, ">>>=") \
102 _(ASSIGN_SHL, "<<=") \
103 _(INCREMENT, "++") \
104 _(DECREMENT, "--") \
105 _(EQUALS, "==") \
106 _(NOTEQUALS, "!=") \
107 _(LT, "<") \
108 _(LE, "<=") \
109 _(GT, ">") \
110 _(GE, ">=") \
111 _(AND, "&&") \
112 _(OR, "||") \
113 _(COMMA, ",") \
114 _(NOT, "!") \
115 _(TILDE, "~") \
116 _(QMARK, "?") \
117 _(COLON, ":") \
118 _(UNDERSCORE, "_") \
119 _(DOT, ".") \
120 _(EOF, "<end-of-file>")
122 enum TokenKind
123 {
124 # define _(name, str) TOK_##name,
125 TOKENMAP(_)
126 # undef _
127 TOK_BITAND = TOK_AMPERSAND,
128 TOKENS_TOTAL
129 };
131 extern const char *TokenNames[];
133 } // namespace ke
135 #endif //_include_jitcraft_token_h_