lexer: Handle differentation between zero and prefix
Signed-off-by: Ian Moffett <ian@mirocom.org>
This commit is contained in:
26
core/lexer.c
26
core/lexer.c
@@ -26,6 +26,22 @@ lexer_is_ws(char c)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns true if the given character is apart of a numbering
|
||||||
|
* system prefix (e.g., '0x' or 'o0')
|
||||||
|
*/
|
||||||
|
static inline bool
|
||||||
|
lexer_is_num_prefix(char c)
|
||||||
|
{
|
||||||
|
switch (c) {
|
||||||
|
case 'o':
|
||||||
|
case 'x':
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Place a given character into the putback buffer
|
* Place a given character into the putback buffer
|
||||||
*
|
*
|
||||||
@@ -355,8 +371,8 @@ lexer_scan_num(struct rifle_state *state, int lc, struct token *tok)
|
|||||||
if (lc == '0') {
|
if (lc == '0') {
|
||||||
if ((prefix = lexer_nom(state, false)) == '\0')
|
if ((prefix = lexer_nom(state, false)) == '\0')
|
||||||
return -1;
|
return -1;
|
||||||
if ((lc = lexer_nom(state, false)) == '\0')
|
if (!lexer_is_num_prefix(prefix))
|
||||||
return -1;
|
lexer_putback(state, prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -367,9 +383,15 @@ lexer_scan_num(struct rifle_state *state, int lc, struct token *tok)
|
|||||||
*/
|
*/
|
||||||
switch (prefix) {
|
switch (prefix) {
|
||||||
case 'x':
|
case 'x':
|
||||||
|
if ((lc = lexer_nom(state, false)) == '\0')
|
||||||
|
return -1;
|
||||||
|
|
||||||
radix = 16;
|
radix = 16;
|
||||||
break;
|
break;
|
||||||
case 'o':
|
case 'o':
|
||||||
|
if ((lc = lexer_nom(state, false)) == '\0')
|
||||||
|
return -1;
|
||||||
|
|
||||||
radix = 8;
|
radix = 8;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|||||||
Reference in New Issue
Block a user