1,914 views
2 votes
2 votes

Given the following expressions of a grammar

$E \rightarrow E * F / F + E / F$

$F \rightarrow F – F / id$

Which of the following is true?

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

5 Answers

Best answer
4 votes
4 votes

B.  - has the higher precedence than *

to check the precedence check the level in which the operator occurs.

lower the level higher the priority and vice versa

as - is lower than *,- has higher priority than *
selected by
3 votes
3 votes
* and + both have same precedence  .- has  greater precedence than + and *.

Option B is Correct.
1 votes
1 votes
Operator which is near the leaf gets the highest precedence .

Precedence in a grammar is enforced by making sure that a production rule with higher precedence operator will never produce an expression with operator with lower precedence.
In the given grammar ‘-’ has higher precedence than ‘*’
0 votes
0 votes

Here  '*'  and  '+' have same precedence and '-' has higher precedence than '*' and '+'.

Ans- B

Answer:

Related questions

1 votes
1 votes
2 answers
1
Arjun asked Jul 10, 2016
5,814 views
Which of the following is true while converting CFG to an LL(1) grammar?Removing left recursion aloneFactoring the grammar aloneRemoving left recursion and factoring the ...
1 votes
1 votes
3 answers
2
1 votes
1 votes
1 answer
3