The Gemara in Masechet Kiddushin (33) tells that Rabbi Ilai and Rabbi Yaakob Bar Zabda were once learning together when Rabbi Shimon Bar Abba walked by, and they stood in his honor. Rabbi Shimon then told them that they acted improperly by standing for him. For one thing, he noted, they themselves were scholars of greater stature, and therefore should not have stood to give him honor. But additionally, he claimed, one should not interrupt Torah learning to give honor to a Torah scholar. A person studying Torah has the status of a Torah scroll, and a Torah scroll certainly does not need to show honor to a scholar of Torah.
The Gemara notes that Rabbi Shimon here expresses the view taken by Rabbi Elazar, who stated, "A Torah scholar is not allowed to stand in his Rabbi’s presence as he [the student] involves himself in Torah."
However, as the Gemara proceeds to mention, this is not the accepted position. The Gemara reports that Abayeh would sharply condemn anyone who followed this ruling and did not interrupt his learning to stand for a Torah scholar. The purpose of learning is to teach a person how to properly conduct himself, and therefore failing to observe the Misva of honoring one’s Rabbi because he studies Torah undermines the validity of his learning. Thus, one is required to stand in the presence of his Rabbi even if this entails disrupting his Torah learning. This Halacha is codified in the Yore De’a section of the Shulhan Aruch (242:11), as well as in the Birkeh Yosef (244) and Ben Ish Hai (Parashat Ki Teseh).
The Ben Ish Hai adds that this Halacha applies even while one prays Pesukeh De’zimra or Shema; if his Rabbi or parent walks in at that point, he must stand, even though he is in the middle of praying. Likewise, the Hid"a (Rav Haim Yosef David Azulai, 1724-1806) rules that one must stand for his Rabbi or parent while reciting a Beracha Aharona after eating or drinking. Hacham Ovadia Yosef, in his Halichot Olam, extends this ruling to Birkat Ha’mazon: one whose Rabbi, father or mother enters the room as he recites Birkat Ha’mazon must stand to give honor to the Rabbi or parent.
Summary: A person must stand when his Rabbi or parent enters the room, even if he is in the middle of studying Torah or reciting Pesukeh De’zimra, Shema, Birkat Ha’mazon or a Beracha Aharona.