Add support for 0b-style literals

This commit is contained in:
Jeffrey Pfau 2014-10-10 02:38:05 -07:00
parent fd1128f90a
commit 6aee0693ec
2 changed files with 34 additions and 0 deletions

View File

@ -121,6 +121,33 @@ size_t lexExpression(struct LexVector* lv, const char* string, size_t length) {
break; break;
} }
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: case LEX_EXPECT_DECIMAL:
switch (token) { switch (token) {
case '0': case '0':
@ -217,6 +244,11 @@ size_t lexExpression(struct LexVector* lv, const char* string, size_t length) {
next = 0; next = 0;
state = LEX_EXPECT_HEX; state = LEX_EXPECT_HEX;
break; break;
case 'B':
case 'b':
next = 0;
state = LEX_EXPECT_BINARY;
break;
case '+': case '+':
case '-': case '-':
case '*': case '*':
@ -257,6 +289,7 @@ size_t lexExpression(struct LexVector* lv, const char* string, size_t length) {
} }
switch (state) { switch (state) {
case LEX_EXPECT_BINARY:
case LEX_EXPECT_DECIMAL: case LEX_EXPECT_DECIMAL:
case LEX_EXPECT_HEX: case LEX_EXPECT_HEX:
case LEX_EXPECT_PREFIX: case LEX_EXPECT_PREFIX:

View File

@ -8,6 +8,7 @@ enum LexState {
LEX_ERROR = -1, LEX_ERROR = -1,
LEX_ROOT = 0, LEX_ROOT = 0,
LEX_EXPECT_IDENTIFIER, LEX_EXPECT_IDENTIFIER,
LEX_EXPECT_BINARY,
LEX_EXPECT_DECIMAL, LEX_EXPECT_DECIMAL,
LEX_EXPECT_HEX, LEX_EXPECT_HEX,
LEX_EXPECT_PREFIX, LEX_EXPECT_PREFIX,