Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is the expression x---y parsed? Is it a legal expression?

Tags:

c++

syntax

How is the expression x---y parsed? Is it a legal expression?

like image 795
Kennedy Bakasa Avatar asked Apr 13 '11 12:04

Kennedy Bakasa


1 Answers

It's legal and parsed as x-- - y.

I believe the first two minus signs are interpreted as a post-decrement operator because it's the longest token following x that is legal to appear. This leaves the third minus to play the role of subtraction. This is in accordance with the Maximal Much Rule[1]

[1]. http://en.wikipedia.org/wiki/Maximal_munch

like image 195
Jon Avatar answered Oct 13 '22 11:10

Jon