1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/Token.h Tue Jul 24 23:53:34 2012 -0700
1.3 @@ -0,0 +1,128 @@
1.4 +/*
1.5 + * Copyright (C) 2012 David Anderson
1.6 + *
1.7 + * This file is part of JITCraft.
1.8 + *
1.9 + * JITCraft is free software: you can redistribute it and/or modify it under
1.10 + * the terms of the GNU General Public License as published by the Free
1.11 + * Software Foundation, either version 3 of the License, or (at your option)
1.12 + * any later version.
1.13 + *
1.14 + * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY
1.15 + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.16 + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
1.17 + *
1.18 + * You should have received a copy of the GNU General Public License along with
1.19 + * JITCraft. If not, see http://www.gnu.org/licenses/.
1.20 + */
1.21 +#ifndef _include_jitcraft_token_h_
1.22 +#define _include_jitcraft_token_h_
1.23 +
1.24 +namespace ke {
1.25 +
1.26 +struct SourcePosition
1.27 +{
1.28 + int line;
1.29 + int col;
1.30 +
1.31 + SourcePosition()
1.32 + : line(-1),
1.33 + col(-1)
1.34 + {
1.35 + }
1.36 +
1.37 + SourcePosition(unsigned line, unsigned col)
1.38 + : line(line),
1.39 + col(col)
1.40 + {
1.41 + }
1.42 +};
1.43 +
1.44 +// List of tokens the scanner can recognize.
1.45 +//
1.46 +// Some restrictions:
1.47 +// * (ASSIGN_ADD - TOK_PLUS) must be the delta between an operator and its
1.48 +// op-and-assign equivalent.
1.49 +#define TOKENMAP(_) \
1.50 + _(ERROR, "<error>") \
1.51 + _(NEW, "'new'") \
1.52 + _(FOR, "'for'") \
1.53 + _(RETURN, "'return'") \
1.54 + _(NAME, "<name>") \
1.55 + _(INTEGER_LITERAL, "<integer>") \
1.56 + _(FLOAT_LITERAL, "<float>") \
1.57 + _(STRING_LITERAL, "<string>") \
1.58 + _(IF, "<if>") \
1.59 + _(ELSE, "<else>") \
1.60 + _(ENUM, "<enum>") \
1.61 + _(LABEL, "<label>") \
1.62 + _(WHILE, "<while>") \
1.63 + _(DO, "<do>") \
1.64 + _(BREAK, "<break>") \
1.65 + _(CONTINUE, "<continue>") \
1.66 + _(FORWARD, "<forward>") \
1.67 + _(PUBLIC, "<public>") \
1.68 + _(CONST, "<const>") \
1.69 + _(NATIVE, "<native>") \
1.70 + _(ELLIPSES, "...") \
1.71 + _(PLUS, "+") \
1.72 + _(MINUS, "-") \
1.73 + _(STAR, "*") \
1.74 + _(SLASH, "/") \
1.75 + _(PERCENT, "%") \
1.76 + _(AMPERSAND, "&") \
1.77 + _(BITOR, "|") \
1.78 + _(BITXOR, "^") \
1.79 + _(SHR, ">>") \
1.80 + _(USHR, ">>>") \
1.81 + _(SHL, "<<") \
1.82 + _(ASSIGN, "=") \
1.83 + _(SEMICOLON, ";") \
1.84 + _(LBRACE, "{") \
1.85 + _(RBRACE, "}") \
1.86 + _(LPAREN, "(") \
1.87 + _(RPAREN, ")") \
1.88 + _(LBRACKET, "[") \
1.89 + _(RBRACKET, "]") \
1.90 + _(ASSIGN_ADD, "+=") \
1.91 + _(ASSIGN_SUB, "-=") \
1.92 + _(ASSIGN_MUL, "*=") \
1.93 + _(ASSIGN_DIV, "/=") \
1.94 + _(ASSIGN_MOD, "%=") \
1.95 + _(ASSIGN_BITAND, "&=") \
1.96 + _(ASSIGN_BITOR, "|=") \
1.97 + _(ASSIGN_BITXOR, "^=") \
1.98 + _(ASSIGN_SHR, ">>=") \
1.99 + _(ASSIGN_USHR, ">>>=") \
1.100 + _(ASSIGN_SHL, "<<=") \
1.101 + _(INCREMENT, "++") \
1.102 + _(DECREMENT, "--") \
1.103 + _(EQUALS, "==") \
1.104 + _(NOTEQUALS, "!=") \
1.105 + _(LT, "<") \
1.106 + _(LE, "<=") \
1.107 + _(GT, ">") \
1.108 + _(GE, ">=") \
1.109 + _(AND, "&&") \
1.110 + _(OR, "||") \
1.111 + _(COMMA, ",") \
1.112 + _(NOT, "!") \
1.113 + _(TILDE, "~") \
1.114 + _(QMARK, "?") \
1.115 + _(COLON, ":") \
1.116 + _(EOF, "<end-of-file>")
1.117 +
1.118 +enum TokenKind
1.119 +{
1.120 +# define _(name, str) TOK_##name,
1.121 + TOKENMAP(_)
1.122 +# undef _
1.123 + TOK_BITAND = TOK_AMPERSAND,
1.124 + TOKENS_TOTAL
1.125 +};
1.126 +
1.127 +extern const char *TokenNames[];
1.128 +
1.129 +} // namespace ke
1.130 +
1.131 +#endif //_include_jitcraft_token_h_