Operator Precedence MCQs: 10 Solved Grammar and Parse-Tree Questions

Solve 10 published Operator Precedence questions on grammar rules, precedence, associativity, parser facts, and expression trees, with fresh explanations.

KnowledgeGate Team

Exam prep & CS education

Updated 29 Aug 20267 min read

Operator Precedence questions switch without warning among grammar restrictions, precedence hierarchy, recursion direction, associativity, and expression-tree shape. Remembering only that higher precedence binds first still leaves you guessing when the grammar itself encodes the answer.

Start with the rule table, then attempt the 10 exam questions from GATE, ISRO, UPPSC Polytechnic Lecturer, Coal India and DSSSB. Choose an option first, and write the grouping or violated rule before reading each explanation. Continue with GATE CS Exam Preparation after the set if you want the wider syllabus route.

Operator precedence rules to apply before the MCQs

Idea

Rule

Operator grammar

No epsilon production and no adjacent non-terminals on a right-hand side

Precedence

An operator defined at a lower non-terminal level binds more tightly

Associativity

Left recursion gives left grouping, while right recursion gives right grouping

Expression tree

The lower-precedence operator sits nearer the root

Use E -> E + T | T, T -> T * F | F, and F -> id to calibrate them. For id + id * id, * appears at the lower T level, so it binds first:

  1. Find the tighter operation: id * id.

  2. Substitute that unit into the expression: id + (id * id).

  3. Both productions are left-recursive, so repetitions at either level group left.

Recursion direction is separate from precedence. P -> Q + P is right-recursive, so + becomes right-associative. If this parser's place inside bottom-up parsing is unclear, review Parsing in Compiler Design: Top-Down and Bottom-Up Explained.

Operator Precedence MCQs 1-2: associativity and expression trees

Question 1: infer associativity from recursive productions

GATE 2014, Computer Science, Set 2

Consider the grammar defined by the following production rules, with two operators * and +:
S -> T * P
T -> U | T * U
P -> Q + P | Q
Q -> Id
U -> Id

Which one of the following is TRUE?

A. + is left associative, while * is right associative
B. + is right associative, while * is left associative
C. Both + and * are right associative
D. Both + and * are left associative

Answer: B. Right-recursive P -> Q + P gives Id + (Id + Id). Left-recursive T -> T * U gives (Id * Id) * Id; S -> T * P changes neither rule.

Question 2: combine higher precedence with opposite associativity

GATE 2011, Computer Science

Consider two binary operators, ↑ and ↓. Operator ↓ has lower precedence than ↑. Operator ↑ is right-associative, while ↓ is left-associative. Which option represents the parse tree for this expression?

7 ↓ 3 ↑ 4 ↑ 3 ↓ 2

Option A

Candidate parse tree for option A of the down-arrow and up-arrow expression in Question 2.

Option B

Candidate parse tree for option B of the down-arrow and up-arrow expression in Question 2.

Option C

Candidate parse tree for option C of the down-arrow and up-arrow expression in Question 2.

Option D

Candidate parse tree for option D of the down-arrow and up-arrow expression in Question 2.

Answer: B. Higher precedence and right associativity give 3 ↑ (4 ↑ 3). Left-associative then gives ((7 ↓ (3 ↑ (4 ↑ 3))) ↓ 2), matching B: root , right child 2, and the nested chain in its left subtree.

Operator Precedence MCQs 3-5: operator-grammar restrictions

Question 3: identify adjacent non-terminals and epsilon

GATE 2004, Computer Science

Which of the following grammar rules violate the requirements of an operator grammar ? P, Q, R are nonterminals, and r, s, t are terminals.
1.    P → Q R
2.    P → Q s R
3.    P → ε
4.    P → Q t R r

A. 1 only
B. 1 and 3 only
C. 2 and 3 only
D. 3 and 4 only

Answer: B. Production 1 has adjacent non-terminals Q R, and 3 derives epsilon. Terminals separate the non-terminals in 2 and 4; trailing r is valid.

Question 4: read precedence from grammar levels

GATE 2000, Computer Science

Given the following expression grammar:
E -> E * F | F + E | F
F -> F - F | id  which of the following is true?
  • A. * has higher precedence than +

  • B. - has higher precedence than *

  • C. + and - have the same precedence

  • D. + has higher precedence than *

Answer: B. - appears inside F, below the E level. Thus id * id - id groups as id * (id - id), proving that - has higher precedence than *; no full ranking is needed.

Question 5: apply both operator-grammar bans together

Indian Space Research Organization 2015, Computer Science

Which grammar rules violate the requirement of the operator grammar? A, B, C are variables and a, b, c are terminals
1) A → BC
2) A → CcBb
3) A → BaC
4) A → ε

A. 1 only
B. 1 and 2 only
C. 1 and 3 only
D. 1 and 4 only

Answer: D. Rule 1 has adjacent variables B C, and rule 4 derives epsilon. Terminals c and a separate the variables in 2 and 3, so only 1 and 4 fail.

Operator Precedence MCQs 6-7: hierarchy and grammar classification

Question 6: combine precedence, associativity, and ambiguity

Indian Space Research Organization 2020, Computer Science

Given the grammar:
S → T * S | T
T → U + T | U
U → a | b

Which of the following statements is wrong?

A. The grammar is not ambiguous
B. Priority of + over * is ensured
C. Right-to-left evaluation of * and + happens
D. None of these

Answer: D. Lower-level + makes a * b + a group uniquely as a * (b + a). Both productions are right-recursive, so repetitions group right; A, B, and C are true, leaving D.

Question 7: test four grammars against the definition

UPPSC Polytechnic Lecturer 2022, Computer Science

Which of the following grammars are operator grammar?
 Where E, F, T are non-terminals and +, -, i, d, ε are terminal symbols.
 G₁: E → E+T | T
   T → T*F | F
   F → i | d
 G₂: E → E+T | T
   T → T*F | F
   F → i | d | ε
 G₃: E → E+T | T
   T → T*F | F | ε
   F → i | d
 G₄: E → E+T | T
   T → F
   F → i | d | F * i | ε

A. G₁, G₂
B. G₁, G₃, G₅
C. G₁, G₃, G₄
D. None of these

Answer: D. Only G₁ has neither epsilon nor adjacent non-terminals. G₂, G₃ and G₄ each contain epsilon, so none qualifies. Option B mentions G₅ even though the question defines only four grammars, but that printing defect does not alter the result: no option lists only G₁.

Operator Precedence MCQs 8-10: repeated rules, parser claims, and a final tree

Question 8: recognise the same restriction pattern in a second exam

Coal India 2020, Computer Science

Which grammar rules violate the requirement of the operator grammar? A, B and C are variables; a, b and c are terminals.
i. A → BC
ii. A → CcBb
iii. A → BaC
iv. A → ε

A. i only
B. i and ii
C. i and iii
D. i and iv

Answer: D. This Coal India item repeats the production pattern in Question 5 with Roman labels. Rule i contains adjacent variables B C, while iv derives epsilon; terminals separate the variables in ii and iii. The labels change, but the two disqualifying structures do not.

Question 9: separate parser facts from an invalid top-down claim

Coal India 2017, Computer Science

Which of the following is/are FALSE?
I) An operator-precedence parser works on ambiguous grammar
II) A top-down parser works on left-recursive, unambiguous and deterministic grammar
III) LL(1) is a non-recursive descent parser
IV) CLR(1) is the most powerful parser

A. Only II
B. I, II, III and IV
C. II and IV
D. I, III and IV

Answer: A. Statement II is false because direct left recursion makes a top-down parser recurse without consuming input. Statement I refers to expression grammars whose ambiguity is resolved by precedence relations; a table-driven LL(1) parser is non-recursive, and CLR(1) is the most powerful of the standard LR variants. Therefore only II is false.

Question 10: build the expression tree after precedence grouping

DSSSB 2021, Computer Science, TGT Shift 3

Assume two binary operators ‘^’ and ‘v’. ‘^’ has higher precedence than ‘v’. Operator ‘^’ is right associative while operator ‘v’ is left associative. Which of the following represents the expression tree for the given expression? (9 v 3 ^ 4 v 2)

Option A

Candidate expression tree for option A of 9 v 3 ^ 4 v 2 in Question 10.

Option B

Candidate expression tree for option B of 9 v 3 ^ 4 v 2 in Question 10.

Option C

Candidate expression tree for option C of 9 v 3 ^ 4 v 2 in Question 10.

Option D

Candidate expression tree for option D of 9 v 3 ^ 4 v 2 in Question 10.

Answer: B. Higher precedence gives 9 v (3 ^ 4) v 2, then left associativity gives (9 v (3 ^ 4)) v 2. Option B has the matching root v, right child 2, and left subtree containing 9 and 3 ^ 4.

How exams test Operator Precedence and where errors happen

Demand

Questions

One-line method

Grammar admissibility

3, 5, 7, 8

Reject epsilon and adjacent non-terminals

Precedence or associativity from productions

1, 4, 6

Read level, then recursion direction

Expression-tree construction

2, 10

Apply precedence, then associativity

Parser-family statements

9

Check parser restrictions

Check four common traps:

  • Distinguish terminals from non-terminals.

  • Read precedence from grammar levels, not production order.

  • Resolve higher precedence before associativity.

  • Put lower precedence at the tree root.

Next, connect this method to SLR vs CLR vs LALR Parsers for GATE: States and Conflicts.

Operator Precedence MCQs: the short version and next step

Recall five rules: reject epsilon and adjacent non-terminals; lower level means higher precedence; recursion sets associativity; lower precedence stays nearer the root.

Retry Questions 1, 2, 4, 6, 7, and 10 blind. Redraw both trees, then check B, B, B, D, D, B.

For structured learning, use GATE Guidance by Sanchit Sir. For timed practice, use the GATE Test Series. Solve blind, write the grouping or violated rule, then compare.