jeudi 26 mars 2015

How compiler translate postfix/prefix operators?


in c/c++



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 1st expression but it's wrong .



...
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/c++ .




Aucun commentaire:

Enregistrer un commentaire