Question 1 |
Given the following expression grammar:
E→ E*F | F+E | F
F→ F-F | id
Which of the following is true?
E→ E*F | F+E | F
F→ F-F | id
Which of the following is true?
* has higher precedence than + | |
– has higher precedence than * | |
+ and – have same precedence | |
+ has higher precedence than * |
Question 1 Explanation:
Operator which is at lower level in the grammar is termed to have higher precedence.
As we can see that first ‘- ‘ will be evaluated then ‘ * ‘ is evaluated
Thus, ‘ – ‘ has higher precedence then *.
So correct answer is option(B)
- * and + have least priority because are present at the top most level .
- * and + have equal precedence because they are same level .
- '-' have higher precedence than '+' and '*' because is present at the bottom most level
E / | \ E * F | / | \ F F - F | | | id(6) id(7) id(8)
As we can see that first ‘- ‘ will be evaluated then ‘ * ‘ is evaluated
Thus, ‘ – ‘ has higher precedence then *.
So correct answer is option(B)
There is 1 question to complete.