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