Add support for 0b-style literals
Jeffrey Pfau jeffrey@endrift.com
Fri, 10 Oct 2014 02:38:05 -0700
2 files changed,
34 insertions(+),
0 deletions(-)
M
src/debugger/parser.c
→
src/debugger/parser.c
@@ -121,6 +121,33 @@ default:
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 @@ case 'x':
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 @@ }
} switch (state) { + case LEX_EXPECT_BINARY: case LEX_EXPECT_DECIMAL: case LEX_EXPECT_HEX: case LEX_EXPECT_PREFIX:
M
src/debugger/parser.h
→
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,