Consider this code:
#include <iostream>
int main()
{
int iTemp = 0;
iTemp += 1; // Valid
iTemp + = 1; // This gives an error ( note the space between '+' and '=')
return 0;
}
Should the parser not automatically have consumed this space and checked for the presence of ‘=’ as ‘+=’ is also a valid token, rather than throwing an error ?
Similarly I get an error for doing < iostream >
Can someone please explain.
Doesn’t work.
The first step of C compilation is tokenization – breaking the sequence of characters to separate language elements. For example:
int x=333;becomes the listint,x,=,333and;‘.Once this is done, the compiler can figure out which token means what and how to combine them.
If tokenization sees the sequence
+=, it generates one token. If it sees a space, it generates two:+and=.