5 ms·
1+2 is a valid expression consisting of 3 tokens, "1", "+", and "2". In most languages, numeric literals, identifiers, and keywords cannot be adjacent, but any
by _kst_ 5y ago
1+2 is a valid expression consisting of 3 tokens, "1", "+", and "2".
In most languages, numeric literals, identifiers, and keywords cannot be adjacent, but any of them can be adjacent to an operator. The odd thing here is "0xfor" being tokenized as "0xf" and "or". In C, for example, "0xfor" is an invalid token.
- toast0 5y ago> In most languages, numeric literals, identifiers, and keywords cannot be adjacent, but any of them can be adjacent to an operator. The odd thing here is "0xfor" being tokenized as "0xf" and "or" 0xf is a numeric literal, and or is an operator, so as you said, they can be adjacent. or isn't an operator in C. of course, if it were 0xfand ... you have a fun problem, because it could be 0xfa nd, but nd isn't an operator (that I know of), or 0xf and. Ideally, syntax shouldn't be ambiguous.
- _kst_ 5y agoI should have stated that more clearly. In Python, "or" is both an operator and a keyword. In most languages, numeric literals, identifiers, and keywords cannot be adjacent, but any of then can be adjacent to a token that consists of punctuation characters. (In some languages, most or all operators spelled using punctuation characters, which is what I had in mind when I wrote my previous comment.)
- fanf2 5y agoor is an operator in C++ and if you #include <iso646.h> in C
- _kst_ 5y ago> or is an operator in C++ Yes. > and if you #include <iso646.h> in C Sort of. As a preprocessor token, it's an identifier that happens to be the name of a macro. As a token (after preprocessing), it becomes the "||" operator.
- deleted 5y ago[deleted]
- deleted 5y ago[deleted]