In a bottom-up parser (such as shift-reduce parser), the semantic action associated with a production rule is executed when that production is reduced.
Given the input string aab:
Shift the first a onto the stack.
Shift the second a onto the stack.
Reduce the second a using S⟶a. The semantic action { print 2 } executes, printing 2. The stack now contains a S.
Shiftb onto the stack. The stack now contains a S b.
ReduceS b using A⟶Sb. The semantic action { print 3 } executes, printing 3. The stack now contains a A.
Reducea A using S⟶aA. The semantic action { print 1 } executes, printing 1. The stack now contains S (the start symbol).
Parsing completes successfully. Combining the printed outputs in order gives 2 3 1, which corresponds to option (C).