4 ms·
Though you don't want to throw a syntax error on "1+2"
by pdw 5y ago
Though you don't want to throw a syntax error on "1+2"
- mixmastamyk 5y agoYes, the difference between a letter character and punctuation/operator character. There's an argument to be made that disallowing it could help in the long run as well, but Python has never been so strict. So I'd stop short of recommending it here. Perhaps in a bondage and discipline language. :-D
- _kst_ 5y ago1+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]
- xapata 5y agoMy preference would be that the syntax requires spaces in that case. Oh well, I've always got the option of writing my own programming language.