How can I understand the parsing of expressions like
a = b+++++b---c--;
in C?
I just made up the expression above, and yes, I can check the results using any compiler, but what I want to know is the ground rule that I should know to understand the parsing of such expressions in C.
From the standard 6.2(4):
They even add the example:
So your statement:
Is equivalent to:
I do know know how much are you familiar with parsers, so just in case: http://en.wikipedia.org/wiki/LL_parser
If you need a formal grammar description, take a look at description for parser generator: https://javacc.dev.java.net/servlets/ProjectDocumentList?folderID=110
The operators involved are
++
,--
,+
and-
. Some parantheses and spaces will help here:I don't know how parsing works exactly, but there's
no ambiguity involved(OK, there is, see Dingo's answer), so I guess it could be done with some simple rules like:+
and-
combine two "expressions"++
and--
are a suffix to an "expression"To remove the ambiguity, you can give
++
and--
a higher priority than+
and-
.