6,630 views
20 votes
20 votes

Consider the grammar defined by the following production rules, with two operators $∗$ and $+$

  • $S\:\to\:T∗P$
  • $T\:\to\:U\mid T∗U$
  • $P\:\to\:Q+P\mid Q$
  • $Q\:\to Id$
  • $U\:\to Id$

Which one of the following is TRUE?

  1. $ +$ is left associative, while $∗$ is right associative
  2. $ +$ is right associative, while $∗$ is left associative
  3. Both $+$ and $∗$ are right associative
  4. Both $+$ and $∗$ are left associative

2 Answers

Best answer
42 votes
42 votes

$P \rightarrow Q+P$ here  $P$ is to right of $+$  

So, $+$ is right associative

Similarly, for  $T \rightarrow T *U$    $*$ is left associative as $T$ is to left of $*$

So, answer is B

edited by
6 votes
6 votes
Let us consider the 2nd production
T -> T * U
T is generating T*U recursively (left recursive) so * is 
left associative.

Similarly
P -> Q + P
Right recursion so + is right associative.
So option B is correct. 
Answer:

Related questions

44 votes
44 votes
7 answers
1
29 votes
29 votes
4 answers
3
go_editor asked Sep 28, 2014
9,178 views
Which one of the following is NOT performed during compilation?Dynamic memory allocationType checkingSymbol table managementInline expansion