-
Notifications
You must be signed in to change notification settings - Fork 249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Arithmetic operation fails #319
Comments
According to https://github.com/hsutter/cppfront/wiki/Design-note%3A-Postfix-operators, it should work:
|
I think that's because the behaviour is changed after this commit. |
One way could be to completely rethink the operator symbols (it's a very small space) and come up with something unambigious. Something that'd solve both this issue and #304 . |
Using To solve this issue, if there is unary postfix operators side-by-side a binary operator, and if the last unary postfix operator's symbol is the same as the binary operator's symbol, then there should be a white-space between them, otherwise white-space is not necessary. Also this can be true for unary prefix operators, therefore imagine if C++2 had unary prefix
|
I was thinking using keywords like // unary operations except dereferencing
+a;
-a;
a++;
b++;
b~;
!a;
//arithmetic operations
a+b;
a-b;
a*b;
a/b;
a%b;
//bitwise operations
a and b;
a or b;
a xor b;
a shl b;
a shr b;
//logical operations
a&&b;
a||b;
!a;
//taking address
a.addr(); //similar to ssize()
//pointer deref
a^;
b^^;
c : ^_ = k.addr(); I don't really like spelling-out bitwise operators but that's one feasible approach. But I have a question, isn't this a problem with transpiler because other compilers can tell the difference somehow? Or is this because of context-free grammar? Edit: Added shift operators to example code //will only write things that change here
//bitwise operators
a&&b;
a||b;
a%%b; //this is xor
//logical operators
a and b;
b or a;
not a;
//how to write "not equal to" ?
//taking address
a.addr(); //similar to ssize()
//pointer deref
a^;
b^^;
c : ^_ = k.addr();
This approach throws familiarity out of window but solves #304 simultaneously Personally, I DON'T completely like any of these but maybe they'll inspire a better approach. But I think reserving a unique symbol for derefs would be the way (and if that symbol matches with any current one, then do something about it). |
Thanks! Finally fixed -- see longer note in #989. The example
obviously should just work, and now it Just Works again. |
It is the example code:
It should generate the following C++1 code:
But C++2 compiler outputs the following error message:
On the other hand,
2+2
works, also2 * 2
(with white-spaces around*
operator) works. The reason of this bug seems to be that*
operator can be both unary postfix and binary. I think it's related to this issue.The text was updated successfully, but these errors were encountered: