The attributes of three arithmetic operators in some programming language are given below. The value of the expression 2 - 5 + 1 - 7 * 3 in this language is …
Topic-wise GATE CS PYQs with verified steps
GATE CSE 2016 Set 1 · Q45
Time

Your answerNumerical answer
Solution
Official answer: 9 (±0)
ParsingFrom the given operator attribute table:
+: Precedence = High, Associativity = Left
-: Precedence = Medium, Associativity = Right
*: Precedence = Low, Associativity = Left
Expression to evaluate: 2 - 5 + 1 - 7 * 3
Step 1: The operator + has the highest precedence.
Evaluate 5 + 1 = .
Expression becomes: 2 - 6 - 7 * 3
Step 2: The operator - has the next highest precedence (Medium) and is Right-associative.
In 2 - 6 - 7, we group from the right: 2 - (6 - 7).
Evaluate inner expression 6 - 7 = .
Evaluate 2 - (-1) = .
Expression becomes: 3 * 3
Step 3: The operator * has the lowest precedence (Low).
Evaluate 3 * 3 = .
Thus, the value of the expression is 9.
Try the question first, then check your work.
Examiner trap
Apply operators in order of precedence: first +, then - (remembering it is right-associative), and finally *.
This Parsing previous year question is Q45 of the GATE CSE 2016 Set 1 paper. Find more GATE CSE PYQs on Parsing in Compiler Design, or browse all GATE CSE PYQs.
Free diagnostic
Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Parsing PYQs now with no account.
An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.
Parsing has 23 GATE CSE PYQs across 16 papers from 2012 to 2026. 3 of them are 2-mark NAT questions like this one, and it is the only one in GATE CSE 2016 Set 1.
How GATE tests ParsingIndependent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.