src/Token.h
author David Anderson <dvander@alliedmods.net>
Sun Sep 16 23:15:13 2012 -0700 (2012-09-16)
changeset 192 23a804fa1d3e
parent 176 2b9141b01023
child 194 b029d63565a2
permissions -rw-r--r--
Allow structs to contain arrays.
     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_
    21 
    22 namespace ke {
    23 
    24 struct SourcePosition
    25 {
    26     int line;
    27     int col;
    28 
    29     SourcePosition()
    30       : line(-1),
    31         col(-1)
    32     {
    33     }
    34 
    35     SourcePosition(unsigned line, unsigned col)
    36       : line(line),
    37         col(col)
    38     {
    39     }
    40 };
    41 
    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     _(NONE,               "<none>")                     \
    49     _(ERROR,              "<error>")                    \
    50     _(NEW,                "'new'")                      \
    51     _(FOR,                "'for'")                      \
    52     _(RETURN,             "'return'")                   \
    53     _(NAME,               "<name>")                     \
    54     _(INTEGER_LITERAL,    "<integer>")                  \
    55     _(HEX_LITERAL,        "<hex>")                      \
    56     _(FLOAT_LITERAL,      "<float>")                    \
    57     _(STRING_LITERAL,     "<string>")                   \
    58     _(IF,                 "<if>")                       \
    59     _(ELSE,               "<else>")                     \
    60     _(ENUM,               "<enum>")                     \
    61     _(LABEL,              "<label>")                    \
    62     _(WHILE,              "<while>")                    \
    63     _(DO,                 "<do>")                       \
    64     _(BREAK,              "<break>")                    \
    65     _(CONTINUE,           "<continue>")                 \
    66     _(FORWARD,            "<forward>")                  \
    67     _(PUBLIC,             "<public>")                   \
    68     _(CONST,              "<const>")                    \
    69     _(NATIVE,             "<native>")                   \
    70     _(STOCK,              "<stock>")                    \
    71     _(TRUE,               "<true>")                     \
    72     _(FALSE,              "<false>")                    \
    73     _(STRUCT,             "<struct>")                   \
    74     _(SWITCH,             "<switch>")                   \
    75     _(CASE,               "<case>")                     \
    76     _(DEFAULT,            "<default>")                  \
    77     _(TYPEDEF,            "<typedef>")                  \
    78     _(VOID,               "<void>")                     \
    79     _(INT,                "<int>")                      \
    80     _(ELLIPSES,           "...")                        \
    81     _(PLUS,               "+")                          \
    82     _(MINUS,              "-")                          \
    83     _(STAR,               "*")                          \
    84     _(SLASH,              "/")                          \
    85     _(PERCENT,            "%")                          \
    86     _(AMPERSAND,          "&")                          \
    87     _(BITOR,              "|")                          \
    88     _(BITXOR,             "^")                          \
    89     _(SHR,                ">>")                         \
    90     _(USHR,               ">>>")                        \
    91     _(SHL,                "<<")                         \
    92     _(ASSIGN,             "=")                          \
    93     _(SEMICOLON,          ";")                          \
    94     _(LBRACE,             "{")                          \
    95     _(RBRACE,             "}")                          \
    96     _(LPAREN,             "(")                          \
    97     _(RPAREN,             ")")                          \
    98     _(LBRACKET,           "[")                          \
    99     _(RBRACKET,           "]")                          \
   100     _(ASSIGN_ADD,         "+=")                         \
   101     _(ASSIGN_SUB,         "-=")                         \
   102     _(ASSIGN_MUL,         "*=")                         \
   103     _(ASSIGN_DIV,         "/=")                         \
   104     _(ASSIGN_MOD,         "%=")                         \
   105     _(ASSIGN_BITAND,      "&=")                         \
   106     _(ASSIGN_BITOR,       "|=")                         \
   107     _(ASSIGN_BITXOR,      "^=")                         \
   108     _(ASSIGN_SHR,         ">>=")                        \
   109     _(ASSIGN_USHR,        ">>>=")                       \
   110     _(ASSIGN_SHL,         "<<=")                        \
   111     _(INCREMENT,          "++")                         \
   112     _(DECREMENT,          "--")                         \
   113     _(EQUALS,             "==")                         \
   114     _(NOTEQUALS,          "!=")                         \
   115     _(LT,                 "<")                          \
   116     _(LE,                 "<=")                         \
   117     _(GT,                 ">")                          \
   118     _(GE,                 ">=")                         \
   119     _(AND,                "&&")                         \
   120     _(OR,                 "||")                         \
   121     _(COMMA,              ",")                          \
   122     _(NOT,                "!")                          \
   123     _(TILDE,              "~")                          \
   124     _(QMARK,              "?")                          \
   125     _(COLON,              ":")                          \
   126     _(UNDERSCORE,         "_")                          \
   127     _(DOT,                ".")                          \
   128     _(EOF,                "<end-of-file>")
   129 
   130 enum TokenKind
   131 {
   132 #   define _(name, str) TOK_##name,
   133     TOKENMAP(_)
   134 #   undef _
   135     TOK_BITAND = TOK_AMPERSAND,
   136     TOKENS_TOTAL
   137 };
   138 
   139 extern const char *TokenNames[];
   140 
   141 } // namespace ke
   142 
   143 #endif //_include_jitcraft_token_h_