in Compiler Design retagged by
10,652 views
27 votes
27 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 $*$
in Compiler Design retagged by
10.7k views

1 comment

the operator which is more far away from the starting symbol will always have higher precedence.
1
1

6 Answers

37 votes
37 votes
Best answer

Correct Option: B

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

edited by

4 Comments

any reference for the above topics, not understanding the solution
0
0
I think grammar is ambiguous as a-a-a can have 2 parse tree     (- has no associativity)
0
0

@Apoorva Jain you are right . The given grammar is ambigious...

0
0
8 votes
8 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
3 votes
3 votes

option b is right

2 votes
2 votes
Precedence of '*' = Precedence of '+' < precedence of '-' < Precedence of 'id'
Answer:

Related questions