Science, asked by sarya2415, 1 year ago

Define ambiguous grammar in compiler design

Answers

Answered by vijil07
0

Library


What is an ambiguous grammar? Give an example.


In computer science, a context-free grammar is said to be an ambiguous grammar if there exists a string which can be generated by the grammar in more than one way (i.e., the string admits more than one parse tree or, equivalently, more than one leftmost derivation). A context-free language is inherently ambiguous if all context-free grammars generating that language are ambiguous.

Some programming languages have ambiguous grammars; in this case, semantic information is needed to select the intended parse tree of an ambiguous construct. For example, in C the following:

x * y ;

can be interpreted as either:

* the declaration of an identifier named y of type pointer-to-x, or
* an expression in which x is multiplied by y and then the result is discarded.

To correctly choose between the two possible interpretations, a compiler must consult its symbol table to find out whether x has been declared as a typedef name that is visible at this point.

Hope it's helpful

Have a nice day

Keep support and follow

#vijil07
Answered by Anonymous
0

Explanation:

Define ambiguous grammar in compiler design

A grammar is said to be ambiguous if there exists more than one leftmost derivation or more than one rightmost derivation or more than one parse tree for the given input string. If the grammar has ambiguity, then it is not good for compiler construction. .

Similar questions