|
"Find the moron":
Yes, I mentioned it is not of practical use. But if you write a Parser/compliler you Need to decide how to handle it
modified 19-Jan-21 21:04pm.
|
|
|
|
|
As I see it, that shouldn't be a difficult thing for a compiler. Based on operator precedence rules, evaluate the expression. There isn't any real ambiguity that you'd have to worry about, if you follow the language spec.
If you were developing a style tool, on the other hand, the tool should write the coder's resignation letter for him and leave it at that.
Software Zen: delete this;
|
|
|
|
|
Thank you very much for your Response. "There isn't any real ambiguity...".
In C: "---", "- ", " -" is ok.
In c++?
It's only a doubt from my side, to decide which way to take
modified 19-Jan-21 21:04pm.
|
|
|
|
|
0x01AA wrote: if you write a Parser/compliler
then you can simply use 42 .
|
|
|
|
|
Sorry but you will be one of the first who compline if such an Expression can not be compiled correctly
modified 19-Jan-21 21:04pm.
|
|
|
|
|
I know how my compiler would handle this...
throw new EthicalException("The compiler refused to read this code, and suggested that the programmer be defenestrated.");
|
|
|
|
|
That sounds Logical, but sorry: If one states Operator precedence for a language and you do something like this....
modified 19-Jan-21 21:04pm.
|
|
|
|
|
It isn;t operator precedence that's the problem: it's that most languages specify the syntax, but don't specify when the operation should take place - in fact C# is the only language I know of that does: https://msdn.microsoft.com/en-us/library/aa691369(v=vs.71).aspx[^] As a result, using multiple pre- or post-fix operators in the same statement (or even expression) is effectively relying on side effects.
Which means that different compilers for the same language will produce different results (and in theory different version of the same compiler could!)
I have seen different results using different C compilers in the past, which is truly horrible. Defenestration is too good for 'em!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
As mentioned earlier, I am aware there is no practical significance. I simply asking me, how to solve that in my "own Parser".
modified 19-Jan-21 21:04pm.
|
|
|
|
|
Pick a set of rules, and be absolutely consistent. Document if expressions are evaluated right-to-left or left-to-right, and exactly when the various operations which make up pre- and post-fix operators are performed. It doesn't actually matter what rules you pick, as long as you define them and stick to them.
(Or better, ban the user from using more than one pre- or post-fix operator on the same variable in the same expression - create an error "ERR666: Cthulhu expressions are not permitted" )
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Thank you.
[Edit]
You are very right. The only Thing I feel uncomfortable is, before C++/C#, let us say at the time of "C" Whitespces" did not have such an affect (of course also that time whitespaces had some meaning). But nowadays one needs to pay more attention.
modified 19-Jan-21 21:04pm.
|
|
|
|
|
|
baked
modified 19-Jan-21 21:04pm.
|
|
|
|
|
I answered a very similar one a couple of days ago: How the expression works c= ++a + ++a;[^]
(I'm already working on an article / tip to cover this as it gets asked too often)
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Thank you very much for your reply. I'm looking Forward for your Article, please give me a hint when it is available.
I'm Aware it is not really from practical importance (swiss english ). But I think you know the feeling as a programmer to make something "correct until to the end"... and in this case, this is something for me which I struggle
Thanks again.
modified 19-Jan-21 21:04pm.
|
|
|
|
|
|
Great!
modified 19-Jan-21 21:04pm.
|
|
|
|
|
0x01AA wrote: what is the value of a=++a + ++a + ++a where a=5
Since this is undefined behavior (in C and C++), as others have said, global thermonuclear war would be as valid output as any other.
|
|
|
|
|
I am aware that this is a very theoretical matter. But programming is not based on assumptions but on definitions
modified 19-Jan-21 21:04pm.
|
|
|
|
|
OK, I just "upgraded" to Windows 10, and somehow now the E-mail associated with my E-mail account is now my account name! I really don't want to have this linkage, and I especially don't like the say that now every time I open up my computer wherever it is, someone can see my E-mail account.
Now, I have no problem with my Microsoft account that I use for my Xbox, or for other business with Microsoft.
|
|
|
|
|
|
I have not => WinX yet, but I notice that Sergey Tkachenko is doing a bang-up job on his blog of covering how to tweak/adjust/enable/disable/revert/delete everything in Win X: [^].
cheers, Bill
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
|
|
|
|
|
... when you notice you have instances of Visual Studio 2015, 2008, and 2003 open. All at the same time.
Software Zen: delete this;
|
|
|
|
|
When all you need is vi ...
|
|
|
|
|
Blech. I used vi once, a long time ago. Years of therapy helped dull the pain.
Software Zen: delete this;
|
|
|
|