| 1 |
/*========================== begin_copyright_notice ============================ |
| 2 |
|
| 3 |
Copyright (C) 2017-2021 Intel Corporation |
| 4 |
|
| 5 |
SPDX-License-Identifier: MIT |
| 6 |
|
| 7 |
============================= end_copyright_notice ===========================*/ |
| 8 |
|
| 9 |
#ifndef _IGA_LEXEMES_HPP_ |
| 10 |
#define _IGA_LEXEMES_HPP_ |
| 11 |
|
| 12 |
namespace iga { |
| 13 |
|
| 14 |
enum Lexeme { |
| 15 |
LEXICAL_ERROR = 0, // Windows GDI #define's "ERROR" |
| 16 |
NEWLINE, |
| 17 |
|
| 18 |
// delimiters |
| 19 |
LANGLE, // < |
| 20 |
RANGLE, // > |
| 21 |
LBRACK, // [ |
| 22 |
RBRACK, // ] |
| 23 |
LBRACE, // { |
| 24 |
RBRACE, // } |
| 25 |
LPAREN, // ( |
| 26 |
RPAREN, // ) |
| 27 |
|
| 28 |
// separators |
| 29 |
DOT, // . |
| 30 |
COMMA, // , |
| 31 |
SEMI, // ; |
| 32 |
COLON, // : |
| 33 |
|
| 34 |
// source modifiers and saturation |
| 35 |
// NEG (see SUB), // - negation (src modifier) |
| 36 |
TILDE, // ~ bitwise complement |
| 37 |
// TODO: this is unsafe (abs) + 4 could be an imm. expression if abs bound |
| 38 |
ABS, // (abs) absolute value |
| 39 |
SAT, // (sat) saturatuation |
| 40 |
|
| 41 |
// reserved symbols |
| 42 |
BANG, // ! |
| 43 |
AT, // @ |
| 44 |
DOLLAR, // $ |
| 45 |
HASH, // # |
| 46 |
EQ, // = |
| 47 |
|
| 48 |
// operators (reserved for future arithmetic) |
| 49 |
MUL, // * |
| 50 |
DIV, // / |
| 51 |
MOD, // % |
| 52 |
ADD, // + |
| 53 |
SUB, // - |
| 54 |
LSH, // << |
| 55 |
RSH, // >> |
| 56 |
AMP, // & |
| 57 |
CIRC, // ^ (circumflex) |
| 58 |
PIPE, // | |
| 59 |
|
| 60 |
// variable lexemes |
| 61 |
IDENT, // e.g. myVar |
| 62 |
INTLIT02, // 0b1101 |
| 63 |
INTLIT10, // 13 |
| 64 |
INTLIT16, // 0x123 |
| 65 |
FLTLIT, // 1.3, 0.1, 1e9, 1e-4 |
| 66 |
|
| 67 |
// unused currently |
| 68 |
CHRLIT, // character literals |
| 69 |
STRLIT, // string literals |
| 70 |
|
| 71 |
END_OF_FILE, // special lexeme that indicates end of file |
| 72 |
NUM_LEXEMES |
| 73 |
}; |
| 74 |
|
| 75 |
static inline const char *LexemeString(const Lexeme &l) { |
| 76 |
#define IGA_LEXEME_TOKEN(T) \ |
| 77 |
case Lexeme::T: \ |
| 78 |
return #T |
| 79 |
switch (l) { |
| 80 |
IGA_LEXEME_TOKEN(LEXICAL_ERROR); |
| 81 |
IGA_LEXEME_TOKEN(NEWLINE); |
| 82 |
|
| 83 |
IGA_LEXEME_TOKEN(LANGLE); // < |
| 84 |
IGA_LEXEME_TOKEN(RANGLE); // > |
| 85 |
IGA_LEXEME_TOKEN(LBRACK); // [ |
| 86 |
IGA_LEXEME_TOKEN(RBRACK); // ] |
| 87 |
IGA_LEXEME_TOKEN(LBRACE); // { |
| 88 |
IGA_LEXEME_TOKEN(RBRACE); // } |
| 89 |
IGA_LEXEME_TOKEN(LPAREN); // ( |
| 90 |
IGA_LEXEME_TOKEN(RPAREN); // ) |
| 91 |
|
| 92 |
IGA_LEXEME_TOKEN(AMP); // & |
| 93 |
IGA_LEXEME_TOKEN(PIPE); // | |
| 94 |
IGA_LEXEME_TOKEN(DOT); // . |
| 95 |
IGA_LEXEME_TOKEN(COMMA); // , |
| 96 |
IGA_LEXEME_TOKEN(SEMI); // ; |
| 97 |
IGA_LEXEME_TOKEN(COLON); // : |
| 98 |
|
| 99 |
IGA_LEXEME_TOKEN(TILDE); // ~ |
| 100 |
IGA_LEXEME_TOKEN(ABS); // (abs) |
| 101 |
IGA_LEXEME_TOKEN(SAT); // (sat) |
| 102 |
|
| 103 |
IGA_LEXEME_TOKEN(BANG); // ! |
| 104 |
IGA_LEXEME_TOKEN(AT); // @ |
| 105 |
IGA_LEXEME_TOKEN(HASH); // # |
| 106 |
IGA_LEXEME_TOKEN(EQ); // = |
| 107 |
|
| 108 |
IGA_LEXEME_TOKEN(MUL); // * |
| 109 |
IGA_LEXEME_TOKEN(DIV); // / |
| 110 |
IGA_LEXEME_TOKEN(MOD); // % |
| 111 |
IGA_LEXEME_TOKEN(ADD); // + |
| 112 |
IGA_LEXEME_TOKEN(SUB); // - |
| 113 |
IGA_LEXEME_TOKEN(LSH); // << |
| 114 |
IGA_LEXEME_TOKEN(RSH); // >> |
| 115 |
|
| 116 |
IGA_LEXEME_TOKEN(IDENT); // [_a-zA-Z][_a-zA-Z0-9]* |
| 117 |
IGA_LEXEME_TOKEN(INTLIT02); // an integral pattern (base 2) |
| 118 |
IGA_LEXEME_TOKEN(INTLIT10); // an integral pattern (base 10) |
| 119 |
IGA_LEXEME_TOKEN(INTLIT16); // an integral pattern (base 16) |
| 120 |
IGA_LEXEME_TOKEN(FLTLIT); // a floating point pattern |
| 121 |
|
| 122 |
// currently unused |
| 123 |
IGA_LEXEME_TOKEN(CHRLIT); // a character literal |
| 124 |
IGA_LEXEME_TOKEN(STRLIT); // a string literal |
| 125 |
|
| 126 |
IGA_LEXEME_TOKEN(END_OF_FILE); |
| 127 |
|
| 128 |
default: |
| 129 |
return "?"; |
| 130 |
// default: { |
| 131 |
// static char buf[16]; |
| 132 |
// sprintf(buf,"%d?",(int)l); |
| 133 |
// return buf; |
| 134 |
// } |
| 135 |
} |
| 136 |
#undef IGA_LEXEME_TOKEN |
| 137 |
} |
| 138 |
|
| 139 |
} // namespace iga |
| 140 |
#endif // _LEXEMES_HPP_ |