From 6aee0693ec67d5234ad6426a7f12a7e81dcb5aca Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Fri, 10 Oct 2014 02:38:05 -0700 Subject: [PATCH] Add support for 0b-style literals --- src/debugger/parser.c | 33 +++++++++++++++++++++++++++++++++ src/debugger/parser.h | 1 + 2 files changed, 34 insertions(+) diff --git a/src/debugger/parser.c b/src/debugger/parser.c index bb31c2a67..1eb9379f7 100644 --- a/src/debugger/parser.c +++ b/src/debugger/parser.c @@ -121,6 +121,33 @@ size_t lexExpression(struct LexVector* lv, const char* string, size_t length) { break; } break; + case LEX_EXPECT_BINARY: + switch (token) { + case '0': + case '1': + // TODO: handle overflow + next <<= 1; + next += token - '0'; + break; + case '+': + case '-': + case '*': + case '/': + lv->token.type = TOKEN_UINT_TYPE; + lv->token.uintValue = next; + lv = _lexOperator(lv, token); + state = LEX_ROOT; + break; + case ')': + lv->token.type = TOKEN_UINT_TYPE; + lv->token.uintValue = next; + state = LEX_EXPECT_OPERATOR; + break; + default: + state = LEX_ERROR; + break; + } + break; case LEX_EXPECT_DECIMAL: switch (token) { case '0': @@ -217,6 +244,11 @@ size_t lexExpression(struct LexVector* lv, const char* string, size_t length) { next = 0; state = LEX_EXPECT_HEX; break; + case 'B': + case 'b': + next = 0; + state = LEX_EXPECT_BINARY; + break; case '+': case '-': case '*': @@ -257,6 +289,7 @@ size_t lexExpression(struct LexVector* lv, const char* string, size_t length) { } switch (state) { + case LEX_EXPECT_BINARY: case LEX_EXPECT_DECIMAL: case LEX_EXPECT_HEX: case LEX_EXPECT_PREFIX: diff --git a/src/debugger/parser.h b/src/debugger/parser.h index 78cbfa2fe..b4cf29ed3 100644 --- a/src/debugger/parser.h +++ b/src/debugger/parser.h @@ -8,6 +8,7 @@ enum LexState { LEX_ERROR = -1, LEX_ROOT = 0, LEX_EXPECT_IDENTIFIER, + LEX_EXPECT_BINARY, LEX_EXPECT_DECIMAL, LEX_EXPECT_HEX, LEX_EXPECT_PREFIX,