jitcraft/Token.h
author David Anderson <dvander@alliedmods.net>
Tue Jul 10 02:11:13 2012 -0700 (2012-07-10)
changeset 68 b40b0e18a918
parent 67 b765a6383849
child 70 1aec996cde2d
permissions -rw-r--r--
Added support for ISourcePawnEngine natives.
     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_
    20 
    21 namespace ke {
    22 
    23 struct SourcePosition
    24 {
    25     int line;
    26     int col;
    27 
    28     SourcePosition()
    29       : line(-1),
    30         col(-1)
    31     {
    32     }
    33 };
    34 
    35 // List of tokens the scanner can recognize.
    36 //
    37 // Some restrictions:
    38 //   * (ASSIGN_ADD - TOK_PLUS) must be the delta between an operator and its
    39 //     op-and-assign equivalent.
    40 #define TOKENMAP(_)                                     \
    41     _(ERROR,              "<error>")                    \
    42     _(NEW,                "'new'")                      \
    43     _(FOR,                "'for'")                      \
    44     _(RETURN,             "'return'")                   \
    45     _(NAME,               "<name>")                     \
    46     _(INTEGER_LITERAL,    "<integer>")                  \
    47     _(FLOAT_LITERAL,      "<float>")                    \
    48     _(STRING_LITERAL,     "<string>")                   \
    49     _(IF,                 "<if>")                       \
    50     _(ELSE,               "<else>")                     \
    51     _(ENUM,               "<enum>")                     \
    52     _(LABEL,              "<label>")                    \
    53     _(WHILE,              "<while>")                    \
    54     _(DO,                 "<do>")                       \
    55     _(BREAK,              "<break>")                    \
    56     _(CONTINUE,           "<continue>")                 \
    57     _(FORWARD,            "<forward>")                  \
    58     _(PUBLIC,             "<public>")                   \
    59     _(CONST,              "<const>")                    \
    60     _(NATIVE,             "<native>")                   \
    61     _(ELLIPSES,           "...")                        \
    62     _(PLUS,               "+")                          \
    63     _(MINUS,              "-")                          \
    64     _(STAR,               "*")                          \
    65     _(SLASH,              "/")                          \
    66     _(AMPERSAND,          "&")                          \
    67     _(BITOR,              "|")                          \
    68     _(BITXOR,             "^")                          \
    69     _(SHR,                ">>")                         \
    70     _(USHR,               ">>>")                        \
    71     _(SHL,                "<<")                         \
    72     _(ASSIGN,             "=")                          \
    73     _(SEMICOLON,          ";")                          \
    74     _(LBRACE,             "{")                          \
    75     _(RBRACE,             "}")                          \
    76     _(LPAREN,             "(")                          \
    77     _(RPAREN,             ")")                          \
    78     _(LBRACKET,           "[")                          \
    79     _(RBRACKET,           "]")                          \
    80     _(ASSIGN_ADD,         "+=")                         \
    81     _(ASSIGN_SUB,         "-=")                         \
    82     _(ASSIGN_MUL,         "*=")                         \
    83     _(ASSIGN_DIV,         "/=")                         \
    84     _(ASSIGN_BITAND,      "&=")                         \
    85     _(ASSIGN_BITOR,       "|=")                         \
    86     _(ASSIGN_BITXOR,      "^=")                         \
    87     _(ASSIGN_SHR,         ">>=")                        \
    88     _(ASSIGN_USHR,        ">>>=")                       \
    89     _(ASSIGN_SHL,         "<<=")                        \
    90     _(INCREMENT,          "++")                         \
    91     _(DECREMENT,          "--")                         \
    92     _(EQUALS,             "==")                         \
    93     _(NOTEQUALS,          "!=")                         \
    94     _(LT,                 "<")                          \
    95     _(LE,                 "<=")                         \
    96     _(GT,                 ">")                          \
    97     _(GE,                 ">=")                         \
    98     _(COMMA,              ",")                          \
    99     _(EOF,                "<end-of-file>")
   100 
   101 enum TokenKind
   102 {
   103 #   define _(name, str) TOK_##name,
   104     TOKENMAP(_)
   105 #   undef _
   106     TOK_BITAND = TOK_AMPERSAND,
   107     TOKENS_TOTAL
   108 };
   109 
   110 extern const char *TokenNames[];
   111 
   112 } // namespace ke
   113 
   114 #endif //_include_jitcraft_token_h_