Would a pupil say: "I'm afraid of getting bad marks." or "I'm afraid to get bad marks."? What is the nuance introduced by OF and TO?
"I'm afraid to" implies volition. As in, "I want to do this, but I'm fearful of trying it."
"I'm afraid of" implies lack of volition. As in, "I'm afraid this will happen to me and I won't be able to avoid it."
Therefore, "I'm afraid of getting bad marks" sounds more natural to me.
There is another way to differentiate.
Afraid Of + ing is used when you generically or generally fear that thing. Well, afraid + to INF is used when you fear what would happen for this particular time.
You’re not usually afraid of speaking in public, so don’t be afraid to speak this time.
In your example, "I'm afraid of getting bad marks," means generally you fear to get bad marks, while "I'm afraid to get bad marks," means you fear to get bad marks from the coming exams.