|
@@ -134,6 +134,28 @@ static bool tParseNumber(int c) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+static bool tAddTokenChecked(int c, Token tc, Token te, Token t) {
|
|
|
|
+ if(tReadIf(c)) {
|
|
|
|
+ return tAddToken(tc);
|
|
|
|
+ } else if(tReadIf('=')) {
|
|
|
|
+ return tAddToken(te);
|
|
|
|
+ }
|
|
|
|
+ return tAddToken(t);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static bool tAddLongTokenChecked(int c, Token tce, Token tc, Token te, Token t) {
|
|
|
|
+ if(tReadIf(c)) {
|
|
|
|
+ if(tReadIf('=')) {
|
|
|
|
+ return tAddToken(tce);
|
|
|
|
+ } else {
|
|
|
|
+ return tAddToken(tc);
|
|
|
|
+ }
|
|
|
|
+ } else if(tReadIf('=')) {
|
|
|
|
+ return tAddToken(te);
|
|
|
|
+ }
|
|
|
|
+ return tAddToken(t);
|
|
|
|
+}
|
|
|
|
+
|
|
static bool tParseToken() {
|
|
static bool tParseToken() {
|
|
int c = tRead();
|
|
int c = tRead();
|
|
if(c == EOF) {
|
|
if(c == EOF) {
|
|
@@ -146,17 +168,19 @@ static bool tParseToken() {
|
|
switch(c) {
|
|
switch(c) {
|
|
case ' ': return true;
|
|
case ' ': return true;
|
|
case '\n': line++; return true;
|
|
case '\n': line++; return true;
|
|
- case '+': return tReadIf('+') ? tAddToken(T_INCREMENT) : tReadIf('=') ? tAddToken(T_ADD_SET) : tAddToken(T_ADD);
|
|
+ case '+': return tAddTokenChecked('+', T_INCREMENT, T_ADD_SET, T_ADD);
|
|
- case '-': return tReadIf('-') ? tAddToken(T_DECREMENT) : tReadIf('=') ? tAddToken(T_SUB_SET) : tAddToken(T_SUB);
|
|
+ case '-': return tAddTokenChecked('-', T_DECREMENT, T_SUB_SET, T_SUB);
|
|
case '*': return tReadIf('=') ? tAddToken(T_MUL_SET) : tAddToken(T_MUL);
|
|
case '*': return tReadIf('=') ? tAddToken(T_MUL_SET) : tAddToken(T_MUL);
|
|
case '/': return tReadIf('=') ? tAddToken(T_DIV_SET) : tAddToken(T_DIV);
|
|
case '/': return tReadIf('=') ? tAddToken(T_DIV_SET) : tAddToken(T_DIV);
|
|
case '%': return tReadIf('=') ? tAddToken(T_MOD_SET) : tAddToken(T_MOD);
|
|
case '%': return tReadIf('=') ? tAddToken(T_MOD_SET) : tAddToken(T_MOD);
|
|
- case '<': return tReadIf('=') ? tAddToken(T_LESS_EQUAL) : tAddToken(T_LESS);
|
|
+ case '<': return tAddLongTokenChecked('<', T_LEFT_SHIFT_SET, T_LEFT_SHIFT, T_LESS_EQUAL, T_LESS);
|
|
- case '>': return tReadIf('=') ? tAddToken(T_GREATER_EQUAL) : tAddToken(T_GREATER);
|
|
+ case '>': return tAddLongTokenChecked('>', T_RIGHT_SHIFT_SET, T_RIGHT_SHIFT, T_GREATER_EQUAL, T_GREATER);
|
|
case '=': return tReadIf('=') ? tAddToken(T_EQUAL) : tAddToken(T_SET);
|
|
case '=': return tReadIf('=') ? tAddToken(T_EQUAL) : tAddToken(T_SET);
|
|
case '!': return tReadIf('=') ? tAddToken(T_NOT_EQUAL) : tAddToken(T_NOT);
|
|
case '!': return tReadIf('=') ? tAddToken(T_NOT_EQUAL) : tAddToken(T_NOT);
|
|
- case '&': return tReadIf('&') ? tAddToken(T_AND) : tAddToken(T_BIT_AND);
|
|
+ case '&': return tAddTokenChecked('&', T_AND, T_BIT_AND_SET, T_BIT_AND);
|
|
- case '|': return tReadIf('|') ? tAddToken(T_OR) : tAddToken(T_BIT_OR);
|
|
+ case '|': return tAddTokenChecked('|', T_OR, T_BIT_OR_SET, T_BIT_OR);
|
|
|
|
+ case '~': return tAddToken(T_BIT_NOT);
|
|
|
|
+ case '^': return tReadIf('=') ? tAddToken(T_BIT_XOR_SET) : tAddToken(T_BIT_XOR);
|
|
case ',': return tAddToken(T_COMMA);
|
|
case ',': return tAddToken(T_COMMA);
|
|
case ';': return tAddToken(T_SEMICOLON);
|
|
case ';': return tAddToken(T_SEMICOLON);
|
|
case '(': return tAddToken(T_OPEN_BRACKET);
|
|
case '(': return tAddToken(T_OPEN_BRACKET);
|
|
@@ -264,14 +288,23 @@ const char* tGetTokenName(Token token) {
|
|
case T_NOT: return "!";
|
|
case T_NOT: return "!";
|
|
case T_AND: return "&&";
|
|
case T_AND: return "&&";
|
|
case T_OR: return "||";
|
|
case T_OR: return "||";
|
|
|
|
+ case T_BIT_NOT: return "~";
|
|
case T_BIT_AND: return "&";
|
|
case T_BIT_AND: return "&";
|
|
case T_BIT_OR: return "|";
|
|
case T_BIT_OR: return "|";
|
|
|
|
+ case T_BIT_XOR: return "^";
|
|
|
|
+ case T_LEFT_SHIFT: return "<<";
|
|
|
|
+ case T_RIGHT_SHIFT: return ">>";
|
|
case T_SET: return "=";
|
|
case T_SET: return "=";
|
|
case T_ADD_SET: return "+=";
|
|
case T_ADD_SET: return "+=";
|
|
case T_SUB_SET: return "-=";
|
|
case T_SUB_SET: return "-=";
|
|
case T_MUL_SET: return "*=";
|
|
case T_MUL_SET: return "*=";
|
|
case T_DIV_SET: return "/=";
|
|
case T_DIV_SET: return "/=";
|
|
case T_MOD_SET: return "%=";
|
|
case T_MOD_SET: return "%=";
|
|
|
|
+ case T_BIT_AND_SET: return "&=";
|
|
|
|
+ case T_BIT_OR_SET: return "|=";
|
|
|
|
+ case T_BIT_XOR_SET: return "^=";
|
|
|
|
+ case T_LEFT_SHIFT_SET: return "<<=";
|
|
|
|
+ case T_RIGHT_SHIFT_SET: return ">>=";
|
|
case T_INCREMENT: return "++";
|
|
case T_INCREMENT: return "++";
|
|
case T_DECREMENT: return "--";
|
|
case T_DECREMENT: return "--";
|
|
case T_LITERAL: return "literal";
|
|
case T_LITERAL: return "literal";
|