edited by
16,632 views
40 40 votes

Given the following expression grammar:

$$\begin{align}
E &\to E * F \mid F + E \mid F \\[1em]
F &\to F - F \mid id
\end{align}$$

Which of the following is true?

  1. $*$ has higher precedence than $+$
  2. $-$ has higher precedence than $*$
  3. $+$ and $-$ have same precedence
  4. $+$ has higher precedence than $*$

9 Answers

Best answer
42 42 votes

Correct Option: B

 operator which is at a lower level in the grammar is termed to have higher precedence.

edited by
14 14 votes
$F->F-E$

Operator at lower level in tree has higher precedence than operator at upper levels.

$-$ has higher precedence than  $+$ and $*$

$+$  and $*$ have equal precedence

Correct Answer : $B$
edited by
2 2 votes

Given Grammar is:

$E->E*F |F+E|F$
$F->F-|id$


The operators at the lower level has higher precedence than those at the higher levels.

Here, $*$ and $+$ has same precedence, as they are at the same level.
$-$ has higher precedence than $*$ and $+$ as it is in higher level.

So, $B$ is the correct option.

edited by
1 1 vote

Both B and D are true.  

Operator which is at lower level in the grammar have higher precedence.!!

1 flag:
✌ Low quality (Aman Shukla “Wrong”)
Answer:
Position:
Show:

Related questions

51 51 votes
8 answers 8 answers
17.2k
17.2k views
Kathleen asked Sep 14, 2014
17,155 views
A multiset is an unordered collection of elements where elements may repeat any number of times. The size of a multiset is the number of elements in it, counting repetiti...
58 58 votes
9 answers 9 answers
48.2k
48.2k views
Kathleen asked Sep 14, 2014
48,184 views
The number of tokens in the following C statement isprintf("i=%d, &i=%x", i, &i);$3$$26$$10$$21$
80 80 votes
4 answers 4 answers
31.6k
31.6k views
Kathleen asked Sep 14, 2014
31,580 views
Consider the following C declaration:struct { short x[5]; union { float y; long z; } u; )t;Assume that the objects of the type short, float and long occupy $2$ bytes, $4$...
30 30 votes
3 answers 3 answers
11.5k
11.5k views
go_editor asked Sep 28, 2014
11,513 views
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$Whi...