all repos — mgba @ 6aee0693ec67d5234ad6426a7f12a7e81dcb5aca

mGBA Game Boy Advance Emulator

Add support for 0b-style literals
Jeffrey Pfau jeffrey@endrift.com
Fri, 10 Oct 2014 02:38:05 -0700
commit

6aee0693ec67d5234ad6426a7f12a7e81dcb5aca

parent

fd1128f90a17151fd6e3a673332045cf534a3d21

2 files changed, 34 insertions(+), 0 deletions(-)

jump to
M src/debugger/parser.csrc/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.hsrc/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,