What do you mean by a Handle? Give example. When a grammar is called ambiguous? Is there any technique to remove ambiguity? Explain with an example. What is the reduce-reduce conflict in LR parser? What are various data structures used for symbol table construction?
A left-recursion production of the form A → Aα | β could be replaced by the non-left-recursive productions as follows:
Without changing the set of strings derivable from A.
The basic idea is that when it is not clear which of two alternative productions to use to expand a non-terminal A, then rewrite the A-productions to defer the decision until the input to make the right choice.
In general, a production is of the form A → αβ1 | αβ2 then it is left factored as:
One problem may generate in case of producing Canonical collections for LR (0) parsing table. Assume that there is a state like as follows:
I5
A→α.
B→β
So the transition table will be:
|
Action |
|
|
a |
b |
I5 |
r1/r2 |
r1/r2 |
|
… |
… |
We can notice that there are 2 final states, so two reduce functions in each action. It is called reduce-reduce conflict. In SLR (1), it will conflict only when FOLLOW(α)∩FOLLOW(β)≠Ø.
Among all, symbol tables are mostly implemented as hash tables, where the source code symbol itself is treated as a key for the hash function and the return value is the information about the symbol.
Explain different stages of compiler with a suitable example. What is token, Patterns and Lexeme?
Draw the syntax tree and DAG from the following expression.
if x>0 then x=3*(y+1) else y=y+1
Write a C program to print the fibonacci series.
Write a C program to convert any name in short name.