From: C. M. <pu...@38...> - 2018-12-04 12:02:45
|
On at 2018-12-03 16:29 -0800, H. Peter Anvin wrote: > Hi, > > Thank you for reporting so quickly. It pays off to browse the repo occasionally =) > This I guess negated my assumption that ? was only used in TASM mode. Yeah, and it was documented in the manual as well, at https://www.nasm.us/xdoc/2.14/html/nasmdoc3.html#section-3.1 : > Valid characters in labels are letters, numbers, _, $, #, @, ~, ., > and ?. The only characters which may be used as the first character > of an identifier are letters, . (with special meaning: see section > 3.9), _ and ?. > The ternary operator is *extremely* useful, in particular because of its > error-suppressing properties (which means that a lot of workarounds like > ((!!foo)*(bar))+(!foo)*(baz)) don't work the same. Oh yeah, you're right. Yes, it'd definitely be useful to support both the operator and question mark in identifiers. (Side question: Would it be possible to "evaluate" expressions with strings as result? Eg << db _FAT16 ? "FAT16" : "FAT12" >>. Currently I use << db "FAT1",'2'+4*!!_FAT16 >> https://bitbucket.org/ecm/ldosboot/src/b469e243526d4fbdfe79d6ef4ef677ff2372eb19/boot.asm#lines-490 , which only uses a string that fits as a numeric constant in a byte.) > I think we can make this work at the cost of complicating the lexical analysis > or require parentheses in certain ambiguous cases. The current NASM lexical > analyzer doesn't backtrack, and works one token at a time. However, there are > cases like: > > foo?bar?baz:quux > > ... where only at the end of the expression can you determine that either > foo?bar or bar?baz has to be an identifier, but not which one. And that still > requires a lexical analysis of the entire expression before it is possible to > make even that determination. > > Interestingly, disallowing '?' itself as an identifier makes it possible to > implement the MASM-like "db ?" syntax as equivalent to resb, and the "dup" > syntax really isn't that hard to do either. > > "%define ? 0" could still be made to work, since %define is followed by a > token, not an expression. It would, of course, replace *ALL* ? (except in > strings) with 0 (which would be a hack around your particular situation, but > wouldn't work for anyone who cares about the symbols in the output format. I don't think this actually works for my use case. If it would replace *all* question marks with zero, one of my labels like "?frame_bp" would look like "0frame_bp" to NASM, which is not a valid identifier. But I'm not sure you mean that? Regards, ecm |