0% found this document useful (0 votes)
27 views29 pages

UNIT-2 Protected

U2 cloud

Uploaded by

neeraj petel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
27 views29 pages

UNIT-2 Protected

U2 cloud

Uploaded by

neeraj petel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 29
UNIT- 2: Top down Parsing Parsing: The process of transforming the data from one format to another is called Parsing. This process can be accomplished by the parser. The parser is a component of the translator that helps to organise linear text structure following the set of defined rules which is known as grammar. The parser is that phase of the compiler which takes a token string as input and with the help of existing grammar, converts it into the corresponding Intermediate Representation (IR). The parser is also known as Syntax Analyzer. Cee eg Creed pea parser Types of Parser: The parser is mainly classified into two categories, i.e, Top-down Parser, and Bottom-up Parser. These are explained below: Top-Down Parser: The top-down parser is the parser that generates parse for the given input string with the help of grammar productions by expanding the non-terminals ie. it starts from the start symbol and ends on the terminals. It uses left most derivation. Further Top-down parser is classified into 2 types: A recursive descent parser, and Non- recursive descent parser. 1. Recursive descent parser is also known as the Brute force parser or the backtracking parser. It basically generates the parse tree by using brute force and backtracking. 2. Non-recursive descent parser is also known as LL(1) parser or predictive parser or without backtracking parser or dynamic parser. It uses a parsing table to generate the parse tree instead of backtracking. Bottom-up Parser: Bottom-up Parser is the parser that generates the parse tree for the given input string with the help of grammar productions by compressing the non-terminals i.e. it starts from non-terminals and ends on the start symbol. It uses the reverse of the rightmost derivation, Further Bottom-up parser is classified into wo types: LR parser, and Operator precedence parser. Example: Input string :a +b * © Production rules: SOE ESE+T ESE*T EoT Toid Let us start bottom-up parsing atb*e Read the input and check if any production matches with the input: atb*e THb*e E+b*e E+T*e Ete E*T E 8 f + LR parser is the bottom-up parser that generates the parse tree for the given string by using unambiguous grammar. It follows the reverse of the rightmost derivation, LR parser is of four types: aa (a)LR(O) OS (b)SLR(1) (c)LALR(1) (@CLRC) ft + Operator precedence parser generates the parse tree from given grammar and string but the only condition is two consecutive non-terminals and epsilon never appears on the right- hand side of any production. + The operator precedence parsing techniques can be applied to Operator grammars. © Operator grammar: A grammar is said to be operator grammar if there does not exist any production rule on the right-hand side. “UL. as e(Epsilon) 2. Two non-terminals appear consecutively, that is, without any terminal between. them operator precedence parsing is not a simple technique to apply to most the language constructs, but it evolves into an easy technique to implement where a suitable grammar may be produced. Recursive Descent Parsing Recursive descent is a top-down parsing technique that constructs the parse tree from the top and the input is read from left to right. It uses procedures for every terminal and non-terminal entity. This parsing technique recursively parses the input to make a parse tree, which may or may not require back-tracking, But the grammar associated with it (if not left factored) cannot avoid back-tracking. A form of recursive-descent parsing that does not require any back-tracking is known as predictive parsing. This parsing technique is regarded recursive as it uses context-free grammar which is recursive in nature. Back-tracking ‘Top- down parsers start from the root node (start symbol) and match the input string against the production rules to replace them (if matched). To understand this, take the following example of CFG: S—rXd |rZd X—oa|ea Z— ai A) For an input string: read, a top-down parser, will behave like this: It will start with S from the production rules and will match its yi I er of the input, i.e. ‘1°. The very production of S (S — rXd) matches 0 the mn parser advances to the next input letter (i.e. e”). The parser tries to al “R* and checks its production from the left (X — 0a). It does not symbol. So the top- down parser backtracks to obtain the next produc ‘Now the parser matehes all the input letters in an ord The string is accepted. - @ Sa RI RBA | A /I\ oe’ @ aN =O “al | 2’ @ “a # Od 7 RN JX Nl] o a ea back-tracking next-production fh ONS S cursive descent parser, which has the capability to predict which product to replace the input string. The predictive parser does not suffer from To accomplish its tasks, the predictive parser uses a look-ahead pointer, which points to the next input symbols, To make the parser back-tracking free, the predictive parser puts some constraints on the grammar and accepts only a class of grammar known as LL(k) grammar. Input t oo a x ‘—— Parser ————> Output sie] + Stack + Parsing Table ACTION | |GOTO Predictive parsing uses a stack and a parsing table to parse the int a arse tree. Both the stack and the input contains an end symbol $ to denote yy and the input is consumed, The parser refers to the parsing table to tak@any detision on the input and stack element combination, Difference between top down and bottom up pai ‘Top-Down Parsing Bottom-Up Parsing It is a parsing strategy that first looks at the highest level of the parse tree and works down the parse tree by using the rules of grammar. It is a parsing strategy that first looks at the lowest level of the parse tree and works up the parse tree by using the rules of grammar. Top-down parsing attempts to find the left most derivations for an input string. Bottom-up parsing can be defined as an attempt to reduce the input string to the start symbol of a grammar. In this parsing technique we start parsing from the top (start symbol of parse tree) t0 down (the leaf node of parse tree) in a top- down manner. In this parsing technique we start parsing from the bottom (leaf node of the parse tree) to up (the start symbol of the parse tree) in a bottom-up manner. This parsing technique uses Left Most Derivation. This parsing technique uses Right Most Deri’ ‘The main leftmost decision is to select what production rule to use in order to construct the string, The main decision is to select when to use a production rule to reduce the string to get the starting symbol. Example: Recursive Descent parser. Example: Its Shift Reduce parser. Drawback of Top-Down Parsing Top-down parsing tries to identify the left-most derivation for an input string ® which is similar to generating a parse tree for the input string @ that starts from the root and produce the nodes in a pre-defined order. © The reason that top-down parsing follow the left-most derivation for an input string @ and not the right-most derivation is that the input string « is scanned by the parser from left to right, one symbol/token at a time. The left-most derivation generates the leaves of the parse tree in the left to right order, which connect the input scan order. + In the top-down parsing, each terminal symbol produces by multiple production of the grammar (which is predicted) is connected with the input string symbol pointed by the string marker. If the mateh is successful, the parser can sustain, If the mismatch occurs, then predictions have gone wrong. * At this phase it is essential to reject previous predictions. Ts \e pred mismatching terminal symbol is rejected and the string Sion eset to its previous position when the rejected production was made. This is known as backtracking. « Backtracking was the major drawback of top-down parsins Ambiguous Grammar Depending on the Number of Derivation trees, CF 3s are sub-divided into 2 types: + Ambiguous grammars + Unambiguous grammars Ambiguous grammar: A CFG is said to be ambiguous if there exists more than one derivation tee for the given input string ie., more than one Left Most Derivation Tree (LMDT) or RightMost Derivation Tree (RMDT). Definition: G = (V,T,P,S) is a CFG that is said to be ambiguous if and only if there exists a string in T* that has more than one parse tree. where V is a finite set of variables. T is a finite set of terminals. P is a finite set of productions, of the form, A > a, where A is a variable and a € (V U T)* S is a designated variable called the start symbol. Depending on the Number of Derivation trees, CFGs are sub-divided into 2 types: + Ambiguous grammars + Unambiguous grammars Ambiguous grammar: A CFG is said to be ambiguous if there exists more than one derivation tree for the given input string i.e., more than one LeftMost Derivation Tree (LMDT) or RightMost Derivation Tree (RMDT). Definition: G = (V,T,PS) is a CFG that is said to be ambiguous if and only if there exists a string in T* that has more than one parse tree. where V isa finite set of variables. T is a finite set of terminals. P is a finite set of productions of the form, A -> a, where A is a variable and a € (V U T)* S is a designated variable called the start symbol. Example Let us consider this grammar: E -> E+E|id We can ercate a 2 parse tree from this grammar to obtain a string id-+id+id, The following are the 2 parse trees generated by left-most derivation: ifs Both the above parse trees are derived from the same grammar rules but both parse trees are different. Hence the grammar is ambiguous. aer avn A grammar can be unambiguous if the grammar does not contain ambiguity that means if it does not contain more than one lefimost derivation or more than one rightmost derivation or more than one parse tree for the given input string. Unambiguous Grammar To convert ambiguous grammar to unambiguous grammar, we will apply the following rules: 1. If the left associative operators (+, -, *, /) are used in the production rule, then apply left recursion in the production rule, Left recursion means that the leftmost symbol on the right side is the same as the non-terminal on the left side. For example, X— Xa ‘Ne If the right associative operates(*) is used in the production rule then apply right recursion in the production rule. Right recursion means that the rightmost symbol on the left side is the same as the non-terminal on the right side. For example, X aX WANN Example 1: Consider a grammar G is given as follows: SAB AsalAa Bob Determine whether the grammar G is ambiguous or not. If G is ambiguous, construct an unambiguous grammar equivalent to G. Solution: Let us derive the string "ab" a JN aN | — a oc 7 Parse tree 1 Parse tree 2 ‘As there are two different parse tree for deriving the same string, the given grammar is ambiguous. Unambiguous grammar will be: soa WS) oe o@ Example 2: Show that the given grammar is ambiguous. Also, find an equivalent unambiguous grammar. S— ABA A-aAle oe LS Solution: The given grammar is ambiguous because we can derive two different parse tree for string aa. 8 a | ; | | | Parse tree 2 The unambiguous grammar is: S$ aXY |bYZ| Z-aZla Xs aXY |ale Y= bYZ|ble Example 3: Show that the given grammar is ambiguous. Also, find an equivalent unambiguous grammar. E>E*E Eid ~ Solution: Let us derive the string "id + id * id” i) ©O® 2 © ©O®© © & Parse tree 1 Parse tree 2 am» ~*~ As there are two different parse tree for deriving the same string, the given grammar is ambiguous. Unambiguous grammar will be: ESE+T EoT ToTer TOF Foid Example 4: Check that the given grammar is ambiguous or not, Also, find an equivalent unambiguous grammar. SoS+S S>S*S S>S*s Soa ~ Solution: The given grammar is ambiguous because the derivation of string ab can be represented by the following string: Cc NO s NN a J! PAN es Parse tree | Parse tree 2 “~arX% ae Unambiguous grammar will be: SoS+A| z ASA*B Left Recursi ‘A Grammar G (V, T, P, S) is left recursive if it has a production in the form, A> Aalp. The above Grammar is left recursive because the left of production is occurring at a first position on the right side of production. It can eliminate left recursion by replacing a pair of production with A= BA’ As adie Elimination of Left Recursion Left Recursion can be eliminated by introducing new non-terminal A such that. cfemouloltetiReanion,| A= BA A+ Aaip Y= aa'|e Left Recursive Grammar Removal of Left Recursion ‘This type of recursion is also called Immediate Left Recursion, In Left Recursive Grammar, expansion of A will generate Aa, Aud, Aaao at cach step, causing itto enter into an infinite loop mn) The general form for left recursion is A AailAon| ... . Adm|BilBel .-. - - Bn can be replaced by A BIA'BoA 0. |e. BoA AS aAl@A'.. . laA'e Example1 ~ Consider the Left Recursion from the Grammar. EOE+TT ToT*FE F>(@)lid Eliminate immediate left recursion from the Grammar. Solution Comparing E— E+ T|T with A AaB =E,a=4T,B=T +A Aa [Bis changed to A + BA’and A’ >a Ale + A= BA’ means E> TE’ A‘ aA’ means E’ > +TE'e Comparing T+ T + F|F with A > Aalp T = T F I F N A = A a | B It T.a="F, =F +A BA’ means T+ FT’ As aAlemeans T >* FTc Production F — (E)jid does not have any left recursion + Combining productions 1, 2, 3, 4, 5, we get - ESTE’ 7 NON ToFT To ETc \ Fo (Bid ~ Example2 ~ Eliminate the left recursion for the following Grammar. S—al\(T) TT,SS Solution We have immediate left recursion in T-productions. Comparing T + T, SIS With A> A a| B where A =T, a=, S and B=S aes A> Aap | Removal of ton Recursion, A ane ronsie — |itamevatotiennesiton | 7ST ‘Complete Grammar will be S— alA(T) T>sT" Tost |e Example3 — Eliminate the left recursion from the grammar ESE+TT TOT*RE F > (@)jid Solution The production after removing the left recursion will be ESTE ~ ONS / > +TEE TFT De FTIE 2; > F= (lid Example 4 ~ Remove the left recursion from the grammar ES ETT TTF Foid Solution Eliminating immediate left-recursion among all Aa productions, we obtain ESTE E> (NE e TFT Te Foid -_ Left Factorins + to make it useful for Top down parsers, In left factoring, ‘* We make one production for each common pr ‘© The common prefix may be a terminal or a non-terminal or a combination of both, ‘© Rest of the derivation is added by new productions. The grammar obtained after the process of left factoring is called as Left Factored Grammar. Example- Left Factoring : A— aa’ = eee eaeeeeeeeeeeeeeaee A= aat /aa2/ acd Al at/a2/a3 Grammar with Left Factored Grammar common prefixes Problem-01: Do left factoring in the following grammar S > iEtS /iEtSeS /a Eb Solution- The left factored grammar is- S—iBtSS' /a S'eS/e E>b Problem-02: Do left factoring in the following grammar- A aAB /aBe/aAc Solution- Step-O1: AnaA’ A’ = AB/Be/ Ac Again, this is a grammar with common prefixes. Step-02: Awad’ A’ AD/Be D-Bile This is a left factored grammar. Problem-03: Do left factoring in the following grammar- S — bSSaa$ / bSSaSb / bSb/a Solution- S>bSS'/a S? — SaaS / SaSb /b Again, this is @ grammar with common prefixes. Step-02: S>bSS’/a S? > SaA/b A aS/Sb This is a left factored grammar. Problem-04: Do left factoring in the following grammar- S — aSSbS / aSaSb / abb / b Solution- ‘Step-01: S—aS'/b S? + SSbS / SaSb / bb Again, this is a grammar with common prefixes. Step-0: SaS'/b S? > SA/bb A SbS /aSb This is a left factored grammar. Problem-05: Do left factoring in the following grammar- S—a/ab / abe /abed Solution- Sas’ S' b/be/ bed /€ Again, this is a grammar with common prefixes. Step: Sas? S's bA/E Avc/ed/é is is a grammar with common prefixes. Sas’ S'+bA/E A> cB/E Bodie This is a left factored grammar. Problem-06: Do left factoring in the following grammar- S—aAd/aB Asa/lab Breed / dde ‘The left factored grammar is- Sas’ Ss’ Ad/B Awad’ AN ob/e Bced/ dde First and Follow- First and Follow sets are needed so that the parser can properly apply the needed production rule at the correct position. First Function- First(a) is set of terminal symbols that begin in strings derived from a. Example- Consider the production rule~ Am abe / def/ ghi Then, we have- First(A) = (a,d.g} Rules For Calculating First Function Rule-O1 For a production rule X + €, First(X) = ( € } Rule-02: For any terminal symbol ‘a’, First(a) = {a} Rule-03: For a production rule X > YiY2¥3, Calculating Firsi(X) amir © Ife ¢ Firsi(¥})), then First(X) = Firsi(¥) + IF€ € Firsi(¥1), then First(X) = { First(Ys) ~ € } U First(Y¥2Y3) Calculating First(¥s¥s wT x uv + If€ € First(Y2), then First(Y2Y) = First(Y2) + If € First(Y2), then First(Y2Y3) = { First(Y2) — € } U First(Ys) Similarly, we ean make expansion for any production rule X — YiY2¥3.. Follow Function- Follow(q) is a set of terminal symbols that appear immediately to the right of a. Rules For Calculating Follow Fun¢ Rule-O1 For the start symbol S, place $ in Follow(S). Rule-02: For any production rule A —> aB, Follow(B) = Follow(A) Rule-03: For any production rule A — aBB, «x 4x 2 + Ife ¢ First(B), then Follow(B) + IFE € Firsi(B), then Follow(B: First(B) { First(B) — € } U Follow(A) Important Notes Note-O1 ~_EW + € may appear in the first function of a non-terminal. + will never appear in the follow funetion of a non-terminal Note-02 ~% hd + Before calculating the first and follow functions, eliminate Left Recursion from the grammar, if present. Note-03, + We calculate the follow function of a non-terminal by looking where it is present on the RHS ofa production rule, Problem-01: Calculate the first and follow functions for the given grammar- S— aBDh Boe ca0c/e DEF Esg/eé Fofe Solution- ‘The first and follow functions are as follows- First Functions- v~ wT + First($)= {a} + First(B)= fe } + First(C)={b,€} © First(D) = { First(E) — € } U Firs(F)= (gf, €} © First(E)={g.€} + First(F)={f,€} Follow Functions- ~ az + Follow(S)= {3} + Follow(B) = { Firs(D) ~ € } U First(h)= {g, fh} © Follow(C) = Follow(B)= { g, fh} + Follow(D) th) = Eh} + Follow(E) = { First(F) — € } U Follow(D) = { fh} + Follow(F) = Follow(D) = {h} Problem-02: Calculate the first and follow functions for the given grammar- SoA A—aB/Ad Bob Coe Solution- We have- 2 uw + The given grammar is left recursive. + So, we first remove left recursion from the given grammar. After eliminating left recursion, we get the following grammar- SoA A= aBA’ Ade Bob Coe Now, the first and follow functions are as follows- First Functions- + First(S) = First(A) = {a} * Firs(A)= {a} © Firs(A’)={d,€} + First(B)= {bj * Firs(C)= {2} Follow Funetions- + Follow(S)= {$} + Follow(A) = Follow(S) = { $} + Follow(A’) = Follow(A) = {8 } ‘+ Follow(B) = { First(A’)~€ } U Follow(A)= {d,$} © Follow(C)=NA Problem-0: Caleulate the first and follow functions for the given grammar- So (M)/a Los’ Lo sive Solution- The first and follow functions are as follows- First Functions- a © First(S)={(,a} ° First(L) = First(S) = { (, a} + First(L) =f.) Follow Funeti + Follow(S) = {$ } U { First(L’)— € } U Follow(L) U Follow(L") = {$,,,) } + Follow(L)={)} + Follow(L’) = Follow(L) = {) } Problem-0: Calculate the first and follow functions for the given grammar- S— AaAb/ BbBa Ave BoE Solution- The first and follow functions are as follows- First Functior am Le © First(S) = { First(A) — € } U First(a) U { First(B) —€ } U First(b) = {a,b} + First(A)={€} + First(B)={€} Follow Functions- oo + Follow(S)= {$} * Follow(A) = First(a) U First(b) = {a,b} + Follow(B)= First(b) U First(a)= {a,b} Problem-05: Calculate the first and follow functions for the given grammar- EOE+T/T TOTxF/F F(E)/id + The given grammar is left recursive. + So, we first remove left recursion from the given grammar. After eliminating left recursion, we get the following grammar- ESTE’ EB) ++TE/e€ ieee T >xFT'/e PF (b)/id ‘Now, the first and follow functions are as follows- First Funetions- a w + First(E) = First(T) = First(F) = { (, id } © Firs(E’)= (+, €} © First(T) = First(F) = { (, id } © First()={x,€} + First(F)= {(, id} Follow Functions- ser rx + Follow(E) + Follow(E” ={8,)} + Follow(T) = { First(E")—€ } U Follow(E) U Follow(E") = {+,$,) } + Follow(T") = Follow(T) = {+,$,)} + Follow(F) = { First(T’) ~ € } U Follow(T) U Follow(T”) = {x,+,8,) } Problem-06: Calculate the first and follow functions for the given grammar- S— ACB/CbB/Ba A da/BC Bogie cohle Solution- The first and follow functions are as follows- First Funetios a.m © First(S) = { First(A)—€ } U { First(C) — € } U First(B) U First(b) U { First(B) —€ } U First(a)={d,g,h,€,b,a} © First(A) = First(d) U { First(B) — € } U First(C)= {d,g,h,€} + Firs(B)= {.€} + First(C)={h,€} Follow Functions- earriw r + Follow(S)= {5} + Follow(A) = { First(C)— € } U { First(B) ~ € } U Follow(S) = {h, 2,3} + Follow(B) = Follow(S) U First(a) U { First(C) ~ € } U Follow(A)= {S,a,h,g} + Follow(C) = { First(B) ~ € } U Follow(S) U First(b) U Follow(A) = {g,$,b,h} LL() Parsing LL(1) Parsing: Here the Ist L represents that the scanning of the Input will be done from Left to Right manner and the second L shows that in this parsing technique we are going to use Left most Derivation Tree. And finally, the 1 represents the number of look-ahead, which means how many symbols are you going to see when you want to make a decision. Essential conditions to check first are as follows: 1. The grammar is free from left recursion. 2. The grammar should not be ambiguous. 3. The grammar has to be left factored in so that the grammar is deterministic grammar. These conditions are necessary but not sufficient for proving a LL(1) parser. Algorithm to construct LL(1) Parsing Table: Step 1: First check all the essential conditions mentioned above and go to step 2. Step 2: Calculate First() and Follow() for all non-terminals 1. First(: If there is a variable, and from that variable, if we try to drive all the strings then the beginning Terminal Symbol is called the First. 2. Follow(: What is the Terminal Symbol which follows a variable in the process of derivation. Step 3: For each production A —> a. (A tends to alpha) 1. Find First(a) and for each terminal in First(a), make entry A —> a in the table, 2. If First(a) contains « (epsilon) as terminal, then find the Follow(A) and for each terminal in Follow(A), make entry A —> ¢ in the table. 3. If the First(«) contains e and Follow(A) contains § as terminal, then make entry A —> ¢ in the table for the $. To construct the parsing table, we have two functions: In the table, rows will contain the Non-Terminals and the column will contain the Terminal Symbols. All the Null Productions of the Grammars will go under the Follow elements and the remaining productions will lie under the elements of the First set. Consider the Grammar: TET Je > F->id|(B) YS *e denotes epsilon £ Step] — The grammar satisfies all properties in step 1 Step 2 — calculating first() and follow() Find their First and Follow sets: = rst | Follow tid) | ES.) > +TE%e| {+2} | 1S,)} QO Torr | tid, T >Re] (6) FidiE) | (id.(} | 1% +.$,)} + $)3 Step 3 ~ making parser table Now, the LL(1) Parsing Table is: id + * ( ) s EB) E>TE E> TE id + * ( ) $s gE E’—>+TE’ E>e|E>e T | TFT TFT’ T Te —>*FT” T>e|T>e F | F>id F>(€) WEN Example-2: Consider the Grammar a -o? Step] — The grammar does not satisfy all properties in step 1, as the grammar is ambiguous. Still, let’s try to make the parser table and see what happens Step 2 — calculating first() and follow() Find their First and Follow sets: Step 3 — making parser table Parsing Table: CD Feeat S| S>AS>a Al A>a Here, we can see that there are two productions in the same cell. Hence, this grammar is not feasible for LL(1) Parser. Trick — Above grammar is ambiguous grammar. So the grammar does not satisfy the essential conditions. So we can say that this grammar is not feasible for LL(1) Parser even without making the parse table. Example 3: Consider the Grammar s>() la Ls L'>)SL'|e Step1 — The grammar satisfies all properties in step 1 Step 2 calculating first() and follow() aN Se ie First | Follow S | {Ga} | {S)} Li} tGab} oy Ly) teh] OF ‘Step 3 — making parser table Parsing Table: ( dia s |s>a) L | L>sv L Here, we can see that there are two productions in the same cell. Hence, this grammar is not feasible for LL(1) Parser. Although the grammar satisfies all the essential conditions in step 1, it is still not feasible for LL(1) Parser. We saw in example 2 that we must have these essential conditions and in example 3 we saw that those conditions are insufficient to be a LL(1) parser. Example of LL(1) Parser S > aABb Ar>c|l€ BoOd|€ Step: 1: No left recursion in the grammar, hence no modificationrequired, Step 2: Calculation of First Set t(S) = {a} irst(A) = {c, €} First(B) = {d, €} Step 3: Calculation of Follow Set Follow(S) = {$} Follow(A) = First(Bb) = First(B) = {d, €) Since it contains €, continue FIRST rule.First(Bb) = First(B) - € U First (b) = {d, b} Follow(A) = {d,b} Follow(B)={b} Step 4: Parsing Table Grammar is LL(1) Example String: acdb$ Lf. | ADE Ad ADE | B | Bx Bd | S > AaAb | BbBa ADE BOE \ Step: 1:No left recursion in the ae 10 modification required, Step 2: Calculation of Firs First(S)=First(AaAb go irSW(AaAb) = First(A) = € Since it contains le First (AaAb) = First(A) - € U First(aAb) = {a} Similarly: First( = {8} Similarly Follow(B) = {a,b} Step 4: s SPAaAb S>BbBa ADE ADE B BIE BOE Difference between Recursive Predictive Descent Parser and Non-Recursive Predi Descent Parser: Recursive Predictive Descent Parser Non-Recursive Predicti ceneParser (backtracking) ef It is a technique which may or may not | It is a technique any kind require backtracking process. of backtracking. It uses procedures for every non-terminal entity to parse strings. to use by replacing input Itis a type of top-down parsing built from a set of mutually recursive procedures w] each procedure implements one\of terminal s of grammar. e is a type of top-down approach, which is also a tYpe of recursive parsing that does not uses mnique of backtracking. The predictive parser uses a look ahead pointer which points to next input symbols to make it parser back tracking free, predictive parser puts some constraints on grammar. It contains several sms ct for each non- terminals ami 8. Itaccepts all so It accepts only a class of grammar known as LL(k) grammar,

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy