src/Token.h
author David Anderson <dvander@alliedmods.net>
Sun Jul 29 19:27:26 2012 -0700 (2012-07-29)
changeset 134 76dec1323d1f
parent 133 7797936ba34c
child 143 393f1b8ac8c3
permissions -rw-r--r--
Support |stock| keyword.
     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     _(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     _(ELLIPSES,           "...")                        \
    70     _(PLUS,               "+")                          \
    71     _(MINUS,              "-")                          \
    72     _(STAR,               "*")                          \
    73     _(SLASH,              "/")                          \
    74     _(PERCENT,            "%")                          \
    75     _(AMPERSAND,          "&")                          \
    76     _(BITOR,              "|")                          \
    77     _(BITXOR,             "^")                          \
    78     _(SHR,                ">>")                         \
    79     _(USHR,               ">>>")                        \
    80     _(SHL,                "<<")                         \
    81     _(ASSIGN,             "=")                          \
    82     _(SEMICOLON,          ";")                          \
    83     _(LBRACE,             "{")                          \
    84     _(RBRACE,             "}")                          \
    85     _(LPAREN,             "(")                          \
    86     _(RPAREN,             ")")                          \
    87     _(LBRACKET,           "[")                          \
    88     _(RBRACKET,           "]")                          \
    89     _(ASSIGN_ADD,         "+=")                         \
    90     _(ASSIGN_SUB,         "-=")                         \
    91     _(ASSIGN_MUL,         "*=")                         \
    92     _(ASSIGN_DIV,         "/=")                         \
    93     _(ASSIGN_MOD,         "%=")                         \
    94     _(ASSIGN_BITAND,      "&=")                         \
    95     _(ASSIGN_BITOR,       "|=")                         \
    96     _(ASSIGN_BITXOR,      "^=")                         \
    97     _(ASSIGN_SHR,         ">>=")                        \
    98     _(ASSIGN_USHR,        ">>>=")                       \
    99     _(ASSIGN_SHL,         "<<=")                        \
   100     _(INCREMENT,          "++")                         \
   101     _(DECREMENT,          "--")                         \
   102     _(EQUALS,             "==")                         \
   103     _(NOTEQUALS,          "!=")                         \
   104     _(LT,                 "<")                          \
   105     _(LE,                 "<=")                         \
   106     _(GT,                 ">")                          \
   107     _(GE,                 ">=")                         \
   108     _(AND,                "&&")                         \
   109     _(OR,                 "||")                         \
   110     _(COMMA,              ",")                          \
   111     _(NOT,                "!")                          \
   112     _(TILDE,              "~")                          \
   113     _(QMARK,              "?")                          \
   114     _(COLON,              ":")                          \
   115     _(UNDERSCORE,         "_")                          \
   116     _(EOF,                "<end-of-file>")
   117 
   118 enum TokenKind
   119 {
   120 #   define _(name, str) TOK_##name,
   121     TOKENMAP(_)
   122 #   undef _
   123     TOK_BITAND = TOK_AMPERSAND,
   124     TOKENS_TOTAL
   125 };
   126 
   127 extern const char *TokenNames[];
   128 
   129 } // namespace ke
   130 
   131 #endif //_include_jitcraft_token_h_