Skip to content

Commit

Permalink
Merge pull request #61 from DevManu-de/master
Browse files Browse the repository at this point in the history
Implementation of x as hex notation #60
  • Loading branch information
alt-romes authored Mar 23, 2021
2 parents 0cdc927 + b735071 commit 70f1bd5
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,15 +310,29 @@ static exprtree parse_number(parser_t parser) {
assert(parser->pos < parser->ntokens);

int numbertype = DEC_TYPE;
if (parser->tokens[parser->pos] == '0' && parser->pos+1 < parser->ntokens) {
if (parser->tokens[parser->pos+1] == 'x') {
numbertype = HEX_TYPE;
parser->pos += 2;
}
else if (parser->tokens[parser->pos+1] == 'b') {
numbertype = BIN_TYPE;
parser->pos += 2;
if (parser->pos+1 < parser->ntokens) {
switch (parser->tokens[parser->pos]) {
case '0':
if (parser->tokens[parser->pos+1] == 'b') {
// Enter if number is binary
numbertype = BIN_TYPE;
parser->pos += 2;
break;
} else if (parser->tokens[parser->pos+1] == 'x'){
// Enter is number is hex
goto hex;
} else {
// Enter if number is decimal
break;
}
case 'x':
hex:
numbertype = HEX_TYPE;
// If x was 1st character add 1 otherwise add 2 to parser->pos
parser->pos += (parser->tokens[parser->pos] == 'x') ? 1 : 2;

}

}

char numberfound[MAX_TOKENS + 1];
Expand Down Expand Up @@ -347,7 +361,6 @@ static exprtree parse_number(parser_t parser) {
return create_exprtree(DEC_TYPE, &zerov, NULL, NULL);
}


// Else, create the expression from the found number
int numberbase = 0;
switch (numbertype) {
Expand Down

0 comments on commit 70f1bd5

Please sign in to comment.