Debugger: Add more operators
Vicki Pfau vi@endrift.com
Wed, 27 Dec 2017 20:57:33 -0500
3 files changed,
67 insertions(+),
18 deletions(-)
M
include/mgba/internal/debugger/parser.h
→
include/mgba/internal/debugger/parser.h
@@ -12,23 +12,20 @@ CXX_GUARD_START
#include <mgba/debugger/debugger.h> -enum LexState { - LEX_ERROR = -1, - LEX_ROOT = 0, - LEX_EXPECT_IDENTIFIER, - LEX_EXPECT_BINARY, - LEX_EXPECT_DECIMAL, - LEX_EXPECT_HEX, - LEX_EXPECT_PREFIX, - LEX_EXPECT_OPERATOR -}; - enum Operation { OP_ASSIGN, OP_ADD, OP_SUBTRACT, OP_MULTIPLY, - OP_DIVIDE + OP_DIVIDE, + OP_AND, + OP_OR, + OP_XOR, + OP_LESS, + OP_GREATER, + OP_EQUAL, + OP_LE, + OP_GE, }; struct Token {
M
src/debugger/cli-debugger.c
→
src/debugger/cli-debugger.c
@@ -560,6 +560,15 @@ dv->type = CLIDV_ERROR_TYPE;
return 0; } break; + case OP_AND: + current &= next; + break; + case OP_OR: + current |= next; + break; + case OP_XOR: + current ^= next; + break; } return current; }
M
src/debugger/parser.c
→
src/debugger/parser.c
@@ -7,6 +7,17 @@ #include <mgba/internal/debugger/parser.h>
#include <mgba-util/string.h> +enum LexState { + LEX_ERROR = -1, + LEX_ROOT = 0, + LEX_EXPECT_IDENTIFIER, + LEX_EXPECT_BINARY, + LEX_EXPECT_DECIMAL, + LEX_EXPECT_HEX, + LEX_EXPECT_PREFIX, + LEX_EXPECT_OPERATOR +}; + static struct LexVector* _lexOperator(struct LexVector* lv, char operator) { struct LexVector* lvNext = malloc(sizeof(struct LexVector)); lvNext->token.type = TOKEN_OPERATOR_TYPE;@@ -23,6 +34,15 @@ break;
case '/': lvNext->token.operatorValue = OP_DIVIDE; break; + case '&': + lvNext->token.operatorValue = OP_AND; + break; + case '|': + lvNext->token.operatorValue = OP_OR; + break; + case '^': + lvNext->token.operatorValue = OP_XOR; + break; default: lvNext->token.type = TOKEN_ERROR_TYPE; break;@@ -102,6 +122,9 @@ case '+':
case '-': case '*': case '/': + case '&': + case '|': + case '^': lv->token.type = TOKEN_IDENTIFIER_TYPE; lv->token.identifierValue = strndup(tokenStart, string - tokenStart - 1); lv = _lexOperator(lv, token);@@ -163,6 +186,9 @@ case '+':
case '-': case '*': case '/': + case '&': + case '|': + case '^': lv->token.type = TOKEN_UINT_TYPE; lv->token.uintValue = next; lv = _lexOperator(lv, token);@@ -217,6 +243,9 @@ case '+':
case '-': case '*': case '/': + case '&': + case '|': + case '^': lv->token.type = TOKEN_UINT_TYPE; lv->token.uintValue = next; lv = _lexOperator(lv, token);@@ -259,6 +288,9 @@ case '+':
case '-': case '*': case '/': + case '&': + case '|': + case '^': lv->token.type = TOKEN_UINT_TYPE; lv->token.uintValue = next; lv = _lexOperator(lv, token);@@ -292,6 +324,9 @@ case '+':
case '-': case '*': case '/': + case '&': + case '|': + case '^': lvNext = malloc(sizeof(struct LexVector)); lvNext->next = lv->next; lvNext->token.type = TOKEN_CLOSE_PAREN_TYPE;@@ -336,11 +371,19 @@ return adjusted;
} static const int _operatorPrecedence[] = { - 2, - 1, - 1, - 0, - 0 + 14, + 4, + 4, + 3, + 3, + 8, + 10, + 9, + 6, + 6, + 7, + 6, + 6 }; static struct ParseTree* _parseTreeCreate() {@@ -421,7 +464,7 @@ tree->token.type = TOKEN_ERROR_TYPE;
tree->lhs = 0; tree->rhs = 0; - _parseExpression(tree, lv, _operatorPrecedence[OP_ASSIGN], 0); + _parseExpression(tree, lv, INT_MAX, 0); } void lexFree(struct LexVector* lv) {