Restore the ability to have ? in identifiers, except ? itself

? in identifiers turns out to be used in the field even in non-TASM
mode. Resolve this by allowing it in an identifier still, but treat
'?' by itself the same as we would a keyword, meaning that it needs to
be separated from other identifier characters.

In other words:

	a ? b : c	; conditional expression
	a?b:c		; seg:off expression seg = a?b, off = c

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
This commit is contained in:
H. Peter Anvin (Intel) 2018-12-14 00:50:34 -08:00
parent ce19a52a34
commit 9df075595e
6 changed files with 9 additions and 5 deletions

View File

@ -310,7 +310,7 @@ static expr *cexpr(void)
if (!e)
return NULL;
if (tt == '?') {
if (tt == TOKEN_QMARK) {
scan();
f = bexpr();
if (!f)

View File

@ -35,6 +35,9 @@
# Tokens other than instructions and registers
#
% TOKEN_QMARK, 0, 0, 0
?
% TOKEN_PREFIX, 0, 0, P_*
a16
a32

View File

@ -1,7 +1,7 @@
#!/usr/bin/perl
## --------------------------------------------------------------------------
##
## Copyright 1996-2014 The NASM Authors - All Rights Reserved
## Copyright 1996-2018 The NASM Authors - All Rights Reserved
## See the file AUTHORS included with the NASM distribution for
## the specific copyright holders.
##
@ -130,7 +130,7 @@ open(TD, '<', $tokens_dat) or die "$0: cannot open $tokens_dat: $!\n";
while (defined($line = <TD>)) {
if ($line =~ /^\%\s+(.*)$/) {
$pattern = $1;
} elsif ($line =~ /^([a-z0-9_-]+)/) {
} elsif ($line =~ /^([\?\@\.a-z0-9_-]+)/) {
$token = $1;
if (defined($tokens{$token})) {

View File

@ -153,6 +153,7 @@ typedef void (*ldfunc)(char *label, int32_t segment, int64_t offset,
enum token_type { /* token types, other than chars */
TOKEN_INVALID = -1, /* a placeholder value */
TOKEN_EOS = 0, /* end of string */
TOKEN_QMARK = '?',
TOKEN_EQ = '=',
TOKEN_GT = '>',
TOKEN_LT = '<', /* aliases */

View File

@ -119,10 +119,9 @@ static inline bool nasm_isquote(char x)
return nasm_ctype(x, NCT_QUOTE);
}
/* TASM-compatible mode requires ? to be an identifier character */
static inline void nasm_ctype_tasm_mode(void)
{
nasm_ctype_tab['?'] |= NCT_ID|NCT_IDSTART;
/* No differences at the present moment */
}
#endif /* NASM_NCTYPE_H */

View File

@ -101,6 +101,7 @@ static void ctype_tab_init(void)
nasm_ctype_tab['_'] |= NCT_UNDER|NCT_ID|NCT_IDSTART;
nasm_ctype_tab['.'] |= NCT_ID|NCT_IDSTART;
nasm_ctype_tab['@'] |= NCT_ID|NCT_IDSTART;
nasm_ctype_tab['?'] |= NCT_ID|NCT_IDSTART;
nasm_ctype_tab['#'] |= NCT_ID;
nasm_ctype_tab['~'] |= NCT_ID;
nasm_ctype_tab['\''] |= NCT_QUOTE;