how to prove unambiguous ?

The Gateway to Computer Science Excellence

First time here? Checkout the FAQ!

x

+14 votes

Consider the following grammar for arithmetic expressions using binary operators $-$ and $/$ which are not associative

$E \rightarrow E -T\mid T$

$T \rightarrow T/F\mid F$

$F \rightarrow (E) \mid id$

($E$ is the start symbol)

Is the grammar unambiguous? Is so, what is the relative precedence between $-$ and $/$? If not, give an unambiguous grammar that gives $/$ precedence over $-$.

$E \rightarrow E -T\mid T$

$T \rightarrow T/F\mid F$

$F \rightarrow (E) \mid id$

($E$ is the start symbol)

Is the grammar unambiguous? Is so, what is the relative precedence between $-$ and $/$? If not, give an unambiguous grammar that gives $/$ precedence over $-$.

+2

@set2018 to prove if a grammar is unambiguous is undecidable. we can try to see if the given grammar is LL(k) or LR(k) since they are unambiguous. note that unambiguity does not imply the grammar is LL(k) or LR(k). The grammar in the question is not LR(1). so unambiguity should be concluded by careful observation.

+12 votes

Best answer

+3

Sunita.. We don't decide the precedence.. We can check this by seeing the grammar given above..

See the grammar is always written in such a way that the operator which have high precedence must lie in the lower part of grammar. As you can see in above grammar operator / lies below the operator - which means / has high precedence than -

Similarly you will always see Id comes in last because it is operand which has highest precedence above operators also..

See the grammar is always written in such a way that the operator which have high precedence must lie in the lower part of grammar. As you can see in above grammar operator / lies below the operator - which means / has high precedence than -

Similarly you will always see Id comes in last because it is operand which has highest precedence above operators also..

+1

It doesn't define precedence, bcoz of last production, (-) can go deeper than (/) in the parse tree.

0

Precedence of - and / are changing for different strings. e.g., For id-id/id, here if we draw a tree then we find '/' below '-', it means here '/' has higher precedence than '-'. But if we draw a tree for id/(id-id), in this case the precedence of '-' is higher than '/'.

So how we can say that the precedence of '/' is always higher than '-'?? Please explain.

So how we can say that the precedence of '/' is always higher than '-'?? Please explain.

- All categories
- General Aptitude 1.4k
- Engineering Mathematics 5.7k
- Digital Logic 2.2k
- Programming & DS 4.1k
- Algorithms 3.6k
- Theory of Computation 4.5k
- Compiler Design 1.7k
- Databases 3.2k
- CO & Architecture 2.8k
- Computer Networks 3.2k
- Non GATE 1.1k
- Others 1.5k
- Admissions 503
- Exam Queries 474
- Tier 1 Placement Questions 22
- Job Queries 61
- Projects 13

39,717 questions

46,751 answers

140,565 comments

58,410 users