In C++ programming language
int a=2;
a++=5;
++a=6;
From above expressions Only 2nd expression is valid . How compiler translate these expressions , so that it's able to find error: lvalue required as left operand of assignment
.
I have tried following translation scheme for these expressions but it's wrong .
...
unary-expression:
postfix-expression{
$<info.place>$ = $<info.place>1;
}
|PLUSPLUS unary-expression{
$<info.place>$ = $<info.place>2;
char *temp =newTemp();
genCode(temp,$<info.place>2,"+","1");
genCode($<info.place>2,temp);
}
...
postfix-expression:
primary-expression{
$<info.place>$ = $<info.place>1;
}
|postfix-expression PLUSPLUS{
$<info.place>$ = newTemp(); //Generate temporary var
genCode($<info.place>$,$<info.place>1); //Assign temp with a
genCode($<info.place>1,$<info.place>$,"+","1");//Increment a by 1
}
...
When i use a++=5
then it generates
0000 : T0 = a
0001 : a = T0 + 1
0002 : T1 = 5
0003 : T0 = T1
What are the changes have to be made in action so that it works like C++ .