Anúncio
(i) Eliminate Left recursion from the following grammar- S-- (L)-a L--.docx
(i) Eliminate Left recursion from the following grammar- S-- (L)-a L--.docx
Próximos SlideShares
) The positively polarized carbon atom of a carbonyl group acts as A).docx) The positively polarized carbon atom of a carbonyl group acts as A).docx
Carregando em ... 3
1 de 2
Anúncio

Mais conteúdo relacionado

Mais de dorisc7(20)

Anúncio

(i) Eliminate Left recursion from the following grammar- S-- (L)-a L--.docx

  1. (i) Eliminate Left recursion from the following grammar. S-> (L)/a L->L,S/a (ii) Construct a predictive parser for given grammar in (i) Solution (i) S-> (L)/a L->L,S/a L-> S L' L' -> , S L' | e (ii) tok;Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â // current token match(x) {Â Â Â Â Â Â Â Â Â Â Â // matches token if (tok != x)Â Â Â Â Â Â // if wrong token error();Â Â Â Â Â Â Â Â // exit with error tok = getToken();Â Â // get new token } parser() { tok = getToken(); // initialize S( );Â Â Â Â Â Â Â Â Â Â Â Â Â // start symbol match("$");Â Â Â Â Â Â Â // match EOF } S( ) {
  2. if (tok == "(" )) {            // S -> (L ) match("("); L(); match(")"); } else if (tok == "a"))          // S -> a match("a"); else error(); } L ( ) { S(); L'();                   // L -> SL' } L' ( ) { if (tok == ",") {            // L' -> S L' match(","); S(); L'(); } else                         // L' -> e ; }
Anúncio