Read this article httpsenwikipediaorgwikiLeftrecursion Apply

Read this article:  https://en.wikipedia.org/wiki/Left_recursion

Apply the algorithm for eliminating direct left recursion to the following grammar.

Term -> Var | Term Term | \'\\\' Var \'->\' Term | \'(\' Term \')\'

Var -> AlphaNum | Var AlphaNum

AlphaNum -> \'0\' | ... | \'9\' | \'a\' | ... | \'z\' | \'A\' | ... | \'Z\'

Does the algorithm introduce indirect left recursion into the resulting grammar? Why or why not?

Solution

T-->V | T T

can be transformed to

T --> VT1

T1--> T T1 | Epsilon

similarly the second production:

V---> A |   V A

can be transformed to

V---> AV1

V1----> V V1 | epsilon

This transformations does not introduce indirect left recursion, because V doesnot directly derives empty string to make T as first symbol.

similarly the non terminal A does not derive empty string which makes V as left symbol.

Thus there is no indirect left recursion.

Read this article: https://en.wikipedia.org/wiki/Left_recursion Apply the algorithm for eliminating direct left recursion to the following grammar. Term -> V

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site