Skip to content
GATEiit

GATE CSE 2018 Q48: Precedence and associativity of the dollar and hash operators from a parse tree

Syllabus topic: Lexical analysis, parsing and syntax-directed translation

Question

Consider the following parse tree for the expression a#b$c$d#e#f, involving two binary operators $ and #.

Parse tree. Root is # with left child a and right child #. That # has left child dollar-operator node and right child #. The dollar node has left child another dollar node (whose children are b and c) and right child d. The right # has children e and f. So the tree groups the expression as a # (((b dollar c) dollar d) # (e # f)).
Tap the figure to enlarge

Which one of the following is correct for the given parse tree?

Try it: multiple choice: exactly one correct option

Select one option
Wrong answer costs 2/3 mark in GATE.
Show answer and explanation

Answer: A (official GATE 2018 final answer key)

Concept used: Operators lower in a parse tree bind tighter (higher precedence); a left-leaning chain of the same operator means left associativity, a right-leaning chain means right associativity.

Concept notes

Loading notes…

First step: Read the grouping off the tree: see whether the $ nodes sit below the # nodes, and in which direction chains of $ and of # nest.

Full step-by-step solution

Loading…

Answer from the official final answer key. Found a mistake? Use Report issue and we will fix it.

More questions on Lexical analysis, parsing and syntax-directed translation

Every PYQ on this topic →

Share this question

WhatsAppDownload image

Source: official GATE 2018 CS question paper and final answer key, organised by IIT Guwahati. Question paper · Answer key