LLR nlysis Motivtion s eplined efore, in LR() prsers there re mny more sttes thn in the previous procedures, LR() nd LR(). This is ecuse there re sttes which contin the sme configurtions, ut with different look-hed symols. possile simplifiction of LR() prsers re LLR() prsers (Look- hed Left-to-Right prsers) They hve the sme numer of sttes s LR() nd LR() prsers. For illustrtion, lnguge like Pscl will hve few hundreds of sttes if constructed s LR(), ut it will hve thousnds if uilt s LR(). LLR nlysis LLR prsers: introductory emple We hve seen n LR() emple grmmr, which ws not LR(): () () (3) () (5) this grmmr generted the following lnguge: {} { n n n } We re going to uild LLR() prsers from LR() prsers 5 5 LLR nlysis LLR prsers: introductory emple Rememer the ugmented grmmr: LLR nlysis LLR prsers: introductory emple LR() Deterministic finite utomt with the trnsitions () () () (3) () (5) s s s s s 3 s 7 s s 8 s 5 s 6 5 53
LLR nlysis LLR prsers: introductory emple This ws the nlysis tle for the LR() grmmr, with the conflict LLR nlysis LLR prsers: introductory emple Deterministic Finite utomt with trnsitions for n LR() prser s {} s 3 {} s {} first()={} () () () (3) () (5) 3 5 6 7 8 s3 s3 s5 s8 /s6 ction cc r r 7 s s {} {} {} {} {} {} s {} {} {} s 5 {} {} {} {} 3 s 3 s 6 {} {} s s 7 s 8 {} {} {} {} 3 {} {} first()={} 3 first()={} first()={} {} s {} s 5 55 LLR nlysis LLR nlysis LLR() prsers: introductory emple LLR() s cn e seen, The sttes in n LR() prser re the sme s in n LR() prser, ut some of them pper severl times with different look-hed symols in the configurtions. The ide is to simplify the nlyser, y merging ll the sttes with the sme configurtions ut different look-hed symols. The resulting nlyser will contin the sme sttes thn the LR() prser. Hving less sttes, the resulting nlyser will e less powerful thn the originl LR() prser, nd there is higher proility of hving collisions (s hppened in LR() prsers) On the other hnd, there will e less collisions in LLR() prsers thn in LR() prsers, so there is gin in this process. 56 In the emple, s 5 nd s 7 contin the sme configurtions, ut with different look-hed symols. We cn merge them in the following stte: s = { {,} {} {} {}} s 3 nd s 8 cn lso e merged into the following stte: s = { {,}} s 6 nd s cn lso e merged into the following stte: s 6 = { {,}} s nd s cn lso e merged into the following stte: s = { {,}}
s s s LLR nlysis LLR() prsers: introductory emple Deterministic Finite utomt with trnsitions for n LLR prser {} {} {} {} {} {} {} s {} {} {} s s {,} {,} {} {} {} 3 s 3 {} {,} s 6 s {,} {} s LLR nlysis LLR() hifts in the tle: It is the sme s in LR() They cn e otined y following the trnsitions in the tle. If the utomt cn go from s i to s j y mens of symol X, then we shll dd the following ction: sj i X yntctic_tle[i,x]= j i X Reductions in the tle: In the cells for the sttes which contin reduction configurtions, of the form γ {σ,...,σ n } we hve to dd the reduction of the rule γ only in the columns for their look-hed non-terminl symols, i.e., {σ,...,σ n }. Therefore, this step is the sme s in LR(), once the digrm for LLR hs een uilt using the previous procedure. 58 5 LLR nlysis LLR nlysis LLR() LLR(): prsing emples ccepttion: It is the sme s in LR() nlysers If stte s i hs trnsition with the terminl symol to the finl stte with the configurtion iom iom, we hve to dd the ccept ction to yntctic_tle[i,]. Is it possile to find lterntive techniques for ccepttion in LR() prsers. rror: It is the sme s in LR() ll the empty cells hve ssocited the error ction. nlysis tle The following is n emple of nlysis with two strings: 6 3 s3 s s s cc r r 6 ction 6 6
LLR nlysis LLR nlysis {, n n n } {, n n n } s cc s cc r r 6 s3 s s 6 () () () (3) () (5) 6 s3 s s 6 () () () (3) () (5) 3 r 3 r ction ction 6 63 LLR nlysis LLR nlysis {, n n n } {, n n n } s cc s cc r r 6 s3 s s 6 () () () (3) () (5) 6 s3 s s 6 () () () (3) () (5) 3 r 3 r ction ction 6 65
LLR nlysis LLR nlysis {, n n n } {, n n n } s cc s cc 6 r r 6 s3 s s 6 () () () (3) () (5) 6 s3 s s 6 () () () (3) () (5) 3 r 3 r ction ction 66 67 LLR nlysis LLR nlysis {, n n n } {, n n n } s cc s cc 6 r r 6 s3 s s 6 () () () (3) () (5) 6 s3 s s 6 () () () (3) () (5) 3 r 3 r ction ction 68 6
LLR nlysis LLR nlysis {, n n n } {, n n n } s cc 6 s cc r r 6 s3 s s 6 () () () (3) () (5) 6 s3 s s 6 () () () (3) () (5) 3 r 3 r ction ction 7 7 LLR nlysis LLR nlysis {, n n n } {, n n n } s cc s cc r r 6 s3 s s 6 () () () (3) () (5) 6 s3 s s 6 () () () (3) () (5) 3 r 3 r ction ction 7 73
LLR nlysis LLR nlysis {, n n n } {, n n n } s cc s cc r r 6 s3 s s 6 () () () (3) () (5) 6 s3 s s 6 () () () (3) () (5) 3 r 3 r ction ction 7 75 LLR nlysis LLR nlysis {, n n n } {, n n n } s cc s cc r r 6 s3 s s 6 () () () (3) () (5) 6 s3 s s 6 () () () (3) () (5) 3 r 3 r ction ction 76 77
LLR nlysis vlution Power: LLR() is less powerful thn LR(), ut more so thn LR(). However, most structures found in progrmming lnguges re LLR(), so they cn e prsed with this procedure. fficiency: There re less sttes in n LLR() prser thn in n LR() prser. 78