The following lex rules are copied from int_literal in docs of rust nightly.
INTEGER_LITERAL ->
( DEC_LITERAL | BIN_LITERAL | OCT_LITERAL | HEX_LITERAL ) SUFFIX_NO_E?
DEC_LITERAL -> DEC_DIGIT (DEC_DIGIT|`_`)*
BIN_LITERAL -> `0b` (BIN_DIGIT|`_`)* BIN_DIGIT (BIN_DIGIT|`_`)*
OCT_LITERAL -> `0o` (OCT_DIGIT|`_`)* OCT_DIGIT (OCT_DIGIT|`_`)*
HEX_LITERAL -> `0x` (HEX_DIGIT|`_`)* HEX_DIGIT (HEX_DIGIT|`_`)*
BIN_DIGIT -> [`0`-`1`]
OCT_DIGIT -> [`0`-`7`]
DEC_DIGIT -> [`0`-`9`]
HEX_DIGIT -> [`0`-`9` `a`-`f` `A`-`F`]
SUFFIX -> IDENTIFIER_OR_KEYWORD
SUFFIX_NO_E -> SUFFIX _not beginning with `e` or `E`_
My problem is, how does Rust lexer handle integer literals like 0xabc?
If the lexer does not check whether the suffix is among those i32, u32, isize, usize, etc., how can it tell the difference between DEC_LITERAL + SUFFIX_NO_E and HEX_LITERAL?
For example, although 0xabc are commonly regarded as a hex literal, it can also be lexed into 0 + xabc with xabc a suffix and 0 a DEC_LITERAL.
I'm working as TA on a project, which require students to write a rust-like compiler in any language, with the target assembly language rv32i. But I have no idea how true rust compiler handles this situation.
1f32is classified as an int initially, and the fact that it's a float is determined later. That should help to answer your question about0xabc