Skip to content

Commit

Permalink
Allow hexadecimal literals to have no digits
Browse files Browse the repository at this point in the history
ACS allows this. In BCS, also allow it, for compatability reasons.
  • Loading branch information
positively-charged committed Feb 5, 2017
1 parent e59bead commit 987901d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion doc/grammar.txt
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ decimal-number:
[0-9]+([']?[0-9]+)*

hexadecimal-number:
0[xX][0-9a-fA-F]+([']?[0-9a-fA-F]+)*
0[xX]([']?[0-9a-fA-F])*

fixed-point-number:
[0-9]+([']?[0-9]+)*[.]([0-9]+([']?[0-9]+)*)?
Expand Down
26 changes: 13 additions & 13 deletions src/parse/token/source.c
Original file line number Diff line number Diff line change
Expand Up @@ -827,9 +827,9 @@ void read_token_acs( struct parse* parse, struct token* token ) {
struct pos pos;
t_init_pos( &pos, parse->source->file_entry_id,
parse->source->line, column );
p_diag( parse, DIAG_POS_ERR, &pos,
"no digits found in hexadecimal literal" );
p_bail( parse );
p_diag( parse, DIAG_POS | DIAG_WARN, &pos,
"hexadecimal literal has no digits, will interpret it as 0x0" );
append_ch( &parse->temp_text, '0' );
}
tk = TK_LIT_HEX;
text = parse->temp_text.value;
Expand Down Expand Up @@ -1516,9 +1516,9 @@ void read_token_acs95( struct parse* parse, struct token* token ) {
struct pos pos;
t_init_pos( &pos, parse->source->file_entry_id,
parse->source->line, column );
p_diag( parse, DIAG_POS_ERR, &pos,
"no digits found in hexadecimal literal" );
p_bail( parse );
p_diag( parse, DIAG_POS | DIAG_WARN, &pos,
"hexadecimal literal has no digits, will interpret it as 0x0" );
append_ch( &parse->temp_text, '0' );
}
tk = TK_LIT_HEX;
text = parse->temp_text.value;
Expand Down Expand Up @@ -2204,14 +2204,14 @@ void read_token( struct parse* parse, struct token* token ) {
"invalid digit in hexadecimal literal" );
p_bail( parse );
}
else if ( text->length == 0 ) {
struct pos pos = { parse->source->line, column,
parse->source->file_entry_id };
p_diag( parse, DIAG_POS_ERR, &pos,
"no digits found in hexadecimal literal" );
p_bail( parse );
}
else {
if ( text->length == 0 ) {
struct pos pos = { parse->source->line, column,
parse->source->file_entry_id };
p_diag( parse, DIAG_POS | DIAG_WARN, &pos,
"hexadecimal literal has no digits, will interpret it as 0x0" );
append_ch( text, '0' );
}
tk = TK_LIT_HEX;
goto state_finish;
}
Expand Down

0 comments on commit 987901d

Please sign in to comment.