img
Question:
Published on: 12 October, 2024

Explain left factoring with suitable example.

Answer:

Left factoring is removing the common left factor that appears in two productions of the same non-terminal. It is done to avoid back-tracing by the parser. Suppose the parser has a look-ahead ,consider this example-

               

Where A, B, C are non-terminals and q is a sentence. In this case, the parser will be confused as to which of the two productions to choose and it might have to back-trace. After left factoring, the grammar is converted to-

             

             

In this case, a parser with a look-ahead will always choose the right production.

Another Example:

           

If we remove the left lecturing, the result will be as follows:

           

Random questions