stack of states and grammar symbols Stack-Bottom marker C. Kessler, IDA, Linköpings universitet. 1. <list> -> <list>, <element> 2.
|
|
- Gertrude Bailey
- 6 years ago
- Views:
Transcription
1 TDDB9 Compilers nd Interpreters TDDB44 Compiler Construction LR Prsing Updted/New slide mteril 007: Pushdown Automton for LR-Prsing Finite-stte pushdown utomton contins lterntingly sttes nd symols in NUΣ (w.l.o.g.) input tpe strem of tokens := + c red-only hed OF token 0 LR prsing concept Prser tle construction Conflict hndling Using prser genertor Prse Tree Genertion Christoph Kessler, IDA, Linköpings universitet, 007. current stte stck of sttes nd grmmr symols s 3 X s 3 -Bottom mrker push pop current stte finite s 0 control s 4 s3 s s Trnsition tle δ sorts of trnsitions: Actions (shift, reduce, ccept, error) Goto s (ε-trnsitions to find new stte fter reductions) TDDB9/44 Compiler Construction, 007 Configurtions of the LR-Prser 0 xmple: A SLR() Grmmr Configurtion = ( stck contents, remining input ) = (s 0 X s X m- s m- X m s m i i+ n ) Shift: red current input symol i nd push it with new stte s: = (s 0 X s X m- s m- X m s m i s i+ n ) Reduce: red ε, pop r stck symols for hndle X m-r+ X m, push LHS nonterminl + new stte (see elow) Invrints: Nonterminls on stck + remining input (X X m- X m i i+ n ) is rightmost-derived sententil form of G. Stte on top of stck represents vile prefix of G Needs to e reconstructed fter reduce, using the GOTO tle current stte (ToS) 3 TDDB9/44 Compiler Construction, 007 Terminls:, Nonterminls: <list> (or L) (is lso the strt symol) <element> (or ) Productions:. <list> -> <list>, <element>. <element> 3. <element> -> 4 TDDB9/44 Compiler Construction, 007 xmple (cont.): xtend Grmmr with new strt symol Terminls: (end-of-input symol), Nonterminls: <SYS> (or S ) (new strt symol) <list> (or L) <element> (or ) Productions: 0. <SYS> -> <list>. <list> -> <list>, <element>. <element> 3. <element> -> 5 TDDB9/44 Compiler Construction, 007, ACTION[ 0, ] = S4 S = Shift 4 = successor stte 0 6 * * 6 TDDB9/44 Compiler Construction, 007
2 4, ACTION[ 0, ] = S4, ACTION[ 4,, ] = R3 ( -> ) R = Reduce 3 = production rule (comment) 0 6 * * 7 TDDB9/44 Compiler Construction, 007 4, ACTION[ 0, ] = S4, ACTION[ 4,, ] = R3 ( -> ), GOTO[ 0, ] = 6 Reconstruct successor stte fter Reduce from top stck items vi the GOTO tle 0 6 * * 8 TDDB9/44 Compiler Construction, nd so on, ACTION[ 0, ] = S4, ACTION[ 4,, ] = R3 ( -> ), GOTO[ 0, ] = 6, ACTION[ 6,, ] = R (L -> ) 0 6 * * 9 TDDB9/44 Compiler Construction, 007, ACTION[ 0, ] = S4 4, ACTION[ 4,, ] = R3 ( -> ), GOTO[ 0, ] = 6 3 6, ACTION[ 6,, ] = R (L -> ) L, GOTO[ 0, L ] = 4 L, ACTION[,, ] = S 5 L, ACTION[, ] = S5 6 L,5 ACTION[ 5, ] = R4 ( -> ) 0 6 L, GOTO[, ] = 3 * * 7 L,3 ACTION[ 3, ] = R (L ->L,) L GOTO[ 0, L ] = 8 -- ACTION[, ] = A (ccept) 0 TDDB9/44 Compiler Construction, 007 Hndle, Vile Prefix 7 Recognizing Hndles 7 Consider rightmost derivtion S => * rm βxu => rm βαu for context-free grmmr G. α is clled hndle of the right sententil form βαu ch prefix of βα is clled vile prefix of G. xmple: Grmmr G with productions { S -> S c } Right sententil forms: e.g. c, c, S, S,.. For c: Hndle: c Vile prefixes: ε, c For c: c ε,, c For S: S ε,, S, S For S: S ε,,, S, S How to recognize if hndle ppers s the top elements on the stck? Nive pproch: xmine the entire stck (e.g. from top to ottom, or vice vers) t every step Leds to unnecessrily long worst-cse prsing time Need to ctully store grmmr symols on stck Ide: Incrementl hndle recognition Keep informtion out prtilly recognized hndles (= vile prefixes) on top of stck, encoded in stte > Chrcteristic utomton (NFA) to recognize vile pr. > DFA y suset construction with ε-closure > Prser tles (ACTION / GOTO) TDDB9/44 Compiler Construction, 007 TDDB9/44 Compiler Construction, 007
3 A NFA Recognizing Vile Prefixes 8 Computing the Closure 8 A.k.. the chrcteristic finite utomton for grmmr G Sttes: LR(0) items (= context-free items) of ext. grmmr Input strem: The grmmr symols on the stck Strt stte: [S ->.S ] Trnsitions: Finl stte: [S -> S.] move dot cross symol if symol found next on stck: A->α.Bγ to A->αB.γ A->α.γ to A->α.γ ε-trnsitions to LR(0)-items for nonterminl productions from items where the dot precedes tht nonterminl: A->α.Bγ to B->.β (xmple: see whiteord) 3 TDDB9/44 Compiler Construction, 007 For set I of LR(0) items compute Closure(I):. Closure(I) := I. If [A->α.Bβ] in Closure(I) nd production B->γ then dd [B->.γ] to Closure(I) (if not lredy there) 3. Repet until no more items cn e dded to Closure(I). Remrks: For s=[a->α.bγ], Closure(s) contins ll NFA sttes rechle from s vi ε-trnsitions, i.e., strting from which ny sustring derivle from Bβ could e recognized. A.k.. ε-closure(s). Then pply the well-known suset construction to trnsform Closure-NFA -> DFA. DFA sttes will e sets unioning closures of NFA sttes 4 TDDB9/44 Compiler Construction, 007 Representing Sets of Items 8c GOTO Function nd DFA Sttes 0 Any item [A->α.β] cn e represented y integers: production numer position of the dot within the RHS of tht production Given: Set I of items, grmmr symol X GOTO( I, X ) := U [A->α.Xβ] in I Closure ( { [A->αX.β] } ) To ecome the stte trnsitions in the DFA The resulting sets often contin closure items (where the dot is t the eginning of the RHS). Cn esily e reconstructed (on demnd) from other ( kernel ) items Kernel items: strt stte [S ->.S], plus ll items where the dot is not t the left end. Store only kernel items explicitly, to sve spce 5 TDDB9/44 Compiler Construction, 007 Now do the suset construction to otin the DFA sttes: C := Closure( { [S ->.S] } ) // C: Set of sets of NFA sttes repet for ech set of items I of C: for ech grmmr symol X if (GOTO(I,X) is not empty nd not in C) dd GOTO(I,X) to C until no new sttes re dded to C on round. 6 TDDB9/44 Compiler Construction, 007 Resulting DFA 0 From DFA to prser tles: ACTION (xmple: see whiteord) All sttes correspond to some vile prefix Finl sttes: contin t lest one item with dot to the right recognized some hndle -> reduce my (must) follow Other sttes: hndle recognition incomplete -> shift will follow The DFA is lso clled the GOTO grph. This utomton is deterministic s FA (i.e., selecting trnsitions considering only input symol consumption) ut cn still e nondeterministic s pushdown utomton (e.g., in stte I ove: to reduce or not to reduce?) 7 TDDB9/44 Compiler Construction, 007. For ech DFA trnsition I i I j reding terminl in Σ (thus, I i contins items of kind [X α.β]) enter S j (shift, new stte I j ) in ACTION[ i, ]. For ech DFA finl stte I i (contining complete item [X α.]) enter R x 4 R3 R (reduce, x = prod. rule numer for X α) 5 R4 R in ACTION[ i, t ] LR(0) prser: for ll t in Σ (ll entries in row i) SLR() prser: for ll t in LA SLR (i,[x α.]) = FOLLOW (X) LALR() prser: for ll t in LA LALR (i,[x α.]) (see lter) Collision with n lredy existing S or R entry? Conflict!! 3. For ech DFA stte contining [S S.] enter A in ACTION[ i, ] (ccept). NB - Conflict? (s in.) 8 TDDB9/44 Compiler Construction, 007 3
4 From DFA to prser tles: GOTO. For ech DFA trnsition I i I j reding nonterminl A (i.e., I i contins n item [X α.aβ]) enter GOTO[ i, A ] = j 0 6 * * 9 TDDB9/44 Compiler Construction, 007 Conflicts in LR Grmmrs Oserve conflicts in DFA (GOTO grph) kernels or t the ltest when filling the ACTION tle. Shift-Reduce conflict A DFA ccepting stte hs n outgoing trnsition, i.e. contins items [X α.] nd [Y β.zγ] for some Z in NUΣ Reduce-Reduce conflict A DFA ccepting stte cn reduce for multiple nonterminls, i.e. contins t lest items [X α.] nd [Y β.], X!= Y (Shift/Reduce-Accept conflict) A DFA ccepting stte contining [S S.] contins nother item [X αs.] or [X αs.β] Only for LR(0) grmmrs there re no conflicts. 0 TDDB9/44 Compiler Construction, 007 Conflict exmples Shift Reduce conflict: id + id Reduce Reduce conflict: id Pcll id (Shift Accept conflict) S L L L, TDDB9/44 Compiler Construction, 007 Hndling Conflicts in LR Grmmrs (Overview): Use lookhed if lucky, the LR(0) sttes + few fixed lookhed sets re sufficient to eliminte ll conflicts in the LR(0)-DFA SLR(), LALR() otherwise, use LR() items [X α.β, ] to uild new, lrger NFA/DFA expensive (mny items/sttes very lrge tles) if still conflicts, my try gin with k> even lrger tles Rewrite the grmmr (fctoring / expnsion) nd retry If nothing helps, re-design your lnguge syntx Some grmmrs re not LR(k) for ny constnt k nd cnnot e mde LR(k) y rewriting either TDDB9/44 Compiler Construction, 007 Lookhed Sets For LR(0) item [X->α.β] in DFA-stte I i, define lookhed set LA( I i, [X->α.β] ) ( suset of Σ) For SLR(), LALR() etc., the LA sets only differ for reduce items: For SLR(): LA SLR ( I i, [X->α.] ) = { in Σ: S => * βxγ } = FOLLOW ( X ) for ll I i with [X->α.] in I i depends on nonterminl X only, not on stte I i For LALR(): LA LALR ( I i, [X->α.] ) = { in Σ: S => * βxw nd the LR(0)-DFA strted in I 0 reches I i fter reding βα } usully suset of FOLLOW ( X ), i.e. of SLR LA set depends on stte I i (Shift-Accept: similr to Shift-Reduce) 4 TDDB9/44 Compiler Construction, TDDB9/44 Compiler Construction, 007 Mde it simple: Is my grmmr SLR()? Construct the (LR(0)-item) chrcteristic NFA nd its equivlent DFA (= GOTO grph) s ove. Consider ll conflicts in the DFA sttes: Shift-Reduce: [X α.] [Y β.γ] Consider ll pirs of conflicting items [X α.], [Y β.γ]: If in FOLLOW (X) for ny of these not SLR(). Reduce-Reduce: Consider ll pirs of conflicting items [X α.], [Y β.]: If FOLLOW (X) intersects with FOLLOW (Y) not SLR(). [X α.] [Y β.] 4
5 xmple: L-Vlues in C Prt of C grmmr:. S -> S. S -> L = R 3. R 4. L -> *R 5. id 6. R -> L Avoids tht R (for R-vlues) ppers s LHS of ssignments But *R = is ok. This grmmr is LALR() ut not SLR(): 5 TDDB9/44 Compiler Construction, 007 xmple (cont.) LR(0) prser hs shift-reduce conflict in kernel of stte I : I 0 = { [S ->.S], [S->.L=R], [S->.R], [L->.*R], [L->.id], R->.L] } I = { [S ->S.] } I = { [S->L.=R], [R->L.] } Shift = or reduce to R? I 3 = { [S->R.] } I 4 = { [L->*.R], [R->.L], [L->.*R], [L->.id] } I 5 = { [L->id.] } I 6 = { [S->L=.R], [R->.L], [L->.*R], L->.id] } I 7 = { [L->*R.] } I 8 = { [R->L.] } I 9 = { [S->L=R.] } FOLLOW (R) = {, = } SLR() still shift-reduce conflict in I s = does not dismigute 6 TDDB9/44 Compiler Construction, 007 xmple (cont.) I 0 = { [S ->.S], [S->.L=R], [S->.R], [L->.*R], [L->.id], R->.L] } I = { [S ->S.] } I = { [S->L.=R], [R->L.] } I 3 = { [S->R.] } I 4 = { [L->*.R], [R->.L], [L->.*R], [L->.id] } I 5 = { [L->id.] } I 6 = { [S->L=.R], [R->.L], [L->.*R], L->.id] } I 7 = { [L->*R.] } I 8 = { [R->L.] } I 9 = { [S->L=R.] } LA LALR ( I, [R->L.] ) = { } LALR() prser is conflict-free s computtion pth I 0 I does not relly llow = following R. = cn only occur fter R if *R ws encountered efore. 7 TDDB9/44 Compiler Construction, 007 LALR() Prser Construction Method : (simple ut not prcticl). Construct the LR() items (see lter). (If there is lredy conflict, stop.). Look for sets of LR() items tht hve the sme kernel, nd merge them. 3. Construct the ACTION tle s for LR(). If conflict is detected, the grmmr is not LALR(). 4. Construct the GOTO function: For ech merged J = I U I U U I r, the kernels of GOTO(I,X),, GOTO(I r,x) re identicl ecuse the kernels of I,,I r re identicl. Set GOTO( J, X ) := U { I: I hs the sme kernel s GOTO(I,X) } Method : (detils see textook). Strt from LR(0) items nd construct kernels of DFA sttes I 0, I,. Compute lookhed sets y propgtion long the GOTO(I j,x) edges (fixed point itertion). 8 TDDB9/44 Compiler Construction, 007 Solve Conflicts y Rewriting the Grmmr LR(k) Grmmr - Forml Definition p.6 liminte Reduce-Reduce Conflict: Fctoring S ( A ) ( B ) A chr integer ident B flot doule ident [A ident. ] [B ident. ] fctor ident S ( A ) ( B ) ( C ) A chr integer B flot doule C ident liminte Shift-Reduce Conflict: (one token lookhed: ( ) Inline-xpnsion S ( A ) OptY ( B ) OptY Y ε [S. ( A ) ] [S. OptY ( B) ] S ( A ) ( B ) Y ( B ) [OptY.Y ] expnd Y [OptY.ε ] OptY Y A A [OptY ε. ] B B [Y ] 9 TDDB9/44 Compiler Construction, 007 Let G e the ugmented grmmr for G (i.e., extended y new strt symol S nd production rule S > S ) G is clled LR(k) grmmr if S rm =>* αxw rm => αβw nd S rm=>* γyx rm => αβy nd w[:k] = y[:k] imply tht α = γ nd X = Y nd x = y = w. i.e., considering t most k symols fter the hndle, in ech rightmost derivtion the hndle cn e loclized nd the production to e pplied cn e determined. Remrk: w, x, y in Σ* α, β, γ in (N U Σ)* X, Y in N xmple: see whiteord 30 TDDB9/44 Compiler Construction, 007 5
6 Some grmmrs re not LR(k) for ny fixed k xmple: S B c B B descries lnguge { N+ c : N >= 0 } This grmmr is not LR(k) for ny fixed k. No miguous grmmr is LR(k) for ny fixed k S if then S if then S else S other sttements is miguous the following sttement hs prse trees: if then if then S else S Proof: As k is fixed (constnt), consider for ny n > k: S =>* n B n c => n n c S =>* n+ B n+ c => n+ n+ c By the LR(k) definition, The hndle cnnot e α = n β = w = n c loclized with only limited lookhed size k γ = n+ β = y = n+ c Although w[:k] = y[:k], we hve α!= γ grmmr is not LR(k). 3 TDDB9/44 Compiler Construction, 007 S if then S if then S else S S S S if then S else S S if then S S 3 TDDB9/44 Compiler Construction, 007 (cont.) Consider sitution (configurtion of shift-reduce prser) -- if then S else Not cler whether to shift else (following production, i.e. if then S is not hndle), or reduce hndle if then S to S (following production ) Any fixed-size lookhed (else nd eyond) does not help! Suggestion: Rewrite grmmr to mke it unmiguous 33 TDDB9/44 Compiler Construction, 007 Rewriting the grmmr S MtchedS OpenS MtchedS if then MtchedS else MtchedS other sttements OpenS if then S if then MtchedS else OpenS is no longer miguous if then S OpenS S if thenmt-s else Mt-S MtchedS S S Impossile now to derive ny sententil form contining n OpenS nonterminl from MtchedS 34 TDDB9/44 Compiler Construction, 007 Some grmmrs re not LR(k) for ny fixed k Grmmr with productions S S ε is unmiguous ut not LR(k) for ny fixed k. (Why?) An equivlent LR grmmr for the sme lnguge is S S ε 35 TDDB9/44 Compiler Construction, 007 LR() Items nd LR(k) Items LR(k) prser: Construction similr to LR(0) / SLR() prser, ut pln for distinguishing etween sttes for k>0 tokens lookhed lredy from the eginning Sttes in the LR(0) GOTO grph my e split up LR() items: [ A->α.β, ] for ll productions A->αβ nd ll in Σ Cn e comined for lookhed symols with equl ehvior: [ A->α.β, ] or [ A->α.β, L ] for suset L of Σ Generlized to k>: [ A->α.β, k ] Interprettion of [ A->α.β, ] in stte: If β not ε, ignore second component (s in LR(0)) If β=ε, i.e. [ A->α., ], reduce only if next input symol =. 36 TDDB9/44 Compiler Construction, 007 6
7 LR() Prser NFA strt stte is [ S ->.S, ] Modify computtion of Closure(I), GOTO(I,X) nd the suset computtion for LR() items Detils see [ASU86, p.3] or [ALSU06, p.6] Cn hve mny more sttes thn LR(0) prser Whichmyhelpto resolvesomeconflicts Interesting to know For ech LR(k) grmmr with some constnt k> there exists n equivlent* grmmr G tht is LR(). For ny LL(k) grmmr there exists n equivlent LR(k) grmmr (ut not vice vers!) e.g., lnguge { n n : n>0 } U { n c n : n > 0 } hs LR(0) grmmr ut no LL(k) grmmr for ny constnt k. Some grmmrs re LR(0) ut not LL(k) for ny k e.g., S A A A (left recursion, could e rewritten) * Two grmmrs re equivlent if they descrie the sme lnguge. 37 TDDB9/44 Compiler Construction, TDDB9/44 Compiler Construction, 007 TDDB9 Compilers nd Interpreters TDDB44 Compiler Construction Using Prser Genertor xmple: UNIX Ycc, GNU Bison for LALR() grmmrs Using Prser Genertor ycc mygrmmr.y Report y.output Ycc Grmmr mygrmmr.y Prser source code y.t.c Grmmr specifiction (terminls, nonterminls, productions with inline-c for semntic ctions) + Additionl C code for uxiliry functions, e.g. scnner, error hndler gcc ly y.t.c other source files nd lirries for the compiler Christoph Kessler, IDA, Linköpings universitet, 007..out < input stdin Prser xecutle.out stdout stderr 40 TDDB9/44 Compiler Construction, 007 xmple Grmmr for Ycc %{ #include <ctype.h> #include <stdio.h> #define YYSTYP chr /* chr type for Ycc stck */ %} %token ',' %token '' %token '' xtr dt field for ech stck entry. Cn e used to store vlues (e.g. in n interpreter, s here) or pointers to tree nodes to construct n explicit tree representtion (see Slides 4+5). %% list : list ',' element { printf( /%c", $3); } element { printf("%c", $); } ; element : '' { $$ = 'A'; } '' { $$ = 'B'; } ; %% yylex() { /* hnd-crfted scnner for toy exmple */ chr c; while () switch (c = getchr()) { cse ',': cse '': cse '': return c; cse '\n': cse OF: return OF; defult: continue; /* et whitespce */ } C. Kessler, } IDA, Linköpings universitet. 4 TDDB9/44 Compiler Construction, 007 Semntic ctions: C code to e psted into the prser nd executed when reducing for production. Cn ccess the extr dt field of the production s stcked grmmr symols y $$, $, $, xmple (cont.) Ycc Report stte 0 $ccept : _list $end shift 3 stte 5 shift 4 list : list,_element. error shift 3 list goto shift 4 element goto. error stte element goto 6 $ccept : list_$end list : list_, element stte 6 list : list, element_ () $end ccept, shift 5. reduce. error stte 5/7 terminls, /600 nonterminls list : element_ () 5/300 grmmr rules, 7/000 sttes 0 shift/reduce, 0 reduce/reduce conflicts reported. reduce 5/60 working sets used memory: sttes,etc. 8/000, prser /4000 stte 3 3/300 distinct lookhed sets element : _ (3) 0 extr closures. reduce 3 5 shift entries, exceptions 3 goto entries stte 4 0 entries sved y goto defult element : _ (4) Optimizer spce used: input 6/000, output 0/ tle entries, 4 zero. reduce 4 mximum spred: 98, mximum offset: 97 4 TDDB9/44 Compiler Construction, 007 7
8 TDDB9 Compilers nd Interpreters TDDB44 Compiler Construction Prse Tree Construction -- 0 L, 3 L, in LR-Prser using the Semntic Semntic stck now stores pointers to prse tree nodes Christoph Kessler, IDA, Linköpings universitet, 007. Prse Tree Construction 4, ACTION[ 0, ] = S4, ACTION[ 4,, ] = R3 ( -> ) Shift: Crete one-node tree contining the shifted symol. 0 6 * * 44 TDDB9/44 Compiler Construction, 007 4, ACTION[ 0, ] = S4, ACTION[ 4,, ] = R3 ( -> ), GOTO[ 0, ] = 6 Reduce [X α.]: Crete new tree node for X whose children re those former root nodes pointed to from the hndle elements semntic stck fields (in Ycc: $, $, ) L L, L,5 L, L,3 L, Input, Tle entries ACTION[,, ] = S ACTION[, ] = S5 ACTION[ 5, ] = R4 ( -> ) GOTO[, ] = 3 ACTION[ 3, ] = R (L ->L,) During prsing: Forest of sutrees, roots pointed from the semntic stck 45 TDDB9/44 Compiler Construction, TDDB9/44 Compiler Construction, L,3 L L Input Tle entries GOTO[ 0, L ] = ACTION[ 3, ] = R (L ->L,) L, At ccept [S S.]: mit the prse tree computed for S. 47 TDDB9/44 Compiler Construction, 007 8
12 <= rm <digit> 2 <= rm <no> 2 <= rm <no> <digit> <= rm <no> <= rm <number>
DDD16 Compilers nd Interpreters DDB44 Compiler Construction R Prsing Prt 1 R prsing concept Using prser genertor Prse ree Genertion Wht is R-prsing? eft-to-right scnning R Rigthmost derivtion in reverse
More informationLR Parsing, Part 2. Constructing Parse Tables. Need to Automatically Construct LR Parse Tables: Action and GOTO Table
TDDD55 Compilers nd Interpreters TDDB44 Compiler Construction LR Prsing, Prt 2 Constructing Prse Tles Prse tle construction Grmmr conflict hndling Ctegories of LR Grmmrs nd Prsers Peter Fritzson, Christoph
More informationLR Parsing, Part 2. Constructing Parse Tables. An NFA Recognizing Viable Prefixes. Computing the Closure. GOTO Function and DFA States
TDDD16 Compilers and Interpreters TDDB44 Compiler Construction LR Parsing, Part 2 Constructing Parse Tables Parse table construction Grammar conflict handling Categories of LR Grammars and Parsers An NFA
More informationthis grammar generates the following language: Because this symbol will also be used in a later step, it receives the
LR() nlysis Drwcks of LR(). Look-hed symols s eplined efore, concerning LR(), it is possile to consult the net set to determine, in the reduction sttes, for which symols it would e possile to perform reductions.
More informationCS 430 Spring Mike Lam, Professor. Parsing
CS 430 Spring 2015 Mike Lm, Professor Prsing Syntx Anlysis We cn now formlly descrie lnguge's syntx Using regulr expressions nd BNF grmmrs How does tht help us? Syntx Anlysis We cn now formlly descrie
More informationCS 321 Programming Languages and Compilers. Bottom Up Parsing
CS 321 Progrmming nguges nd Compilers Bottom Up Prsing Bottom-up Prsing: Shift-reduce prsing Grmmr H: fi ; fi b Input: ;;b hs prse tree ; ; b 2 Dt for Shift-reduce Prser Input string: sequence of tokens
More informationFig.25: the Role of LEX
The Lnguge for Specifying Lexicl Anlyzer We shll now study how to uild lexicl nlyzer from specifiction of tokens in the form of list of regulr expressions The discussion centers round the design of n existing
More informationIn the last lecture, we discussed how valid tokens may be specified by regular expressions.
LECTURE 5 Scnning SYNTAX ANALYSIS We know from our previous lectures tht the process of verifying the syntx of the progrm is performed in two stges: Scnning: Identifying nd verifying tokens in progrm.
More informationCSCE 531, Spring 2017, Midterm Exam Answer Key
CCE 531, pring 2017, Midterm Exm Answer Key 1. (15 points) Using the method descried in the ook or in clss, convert the following regulr expression into n equivlent (nondeterministic) finite utomton: (
More informationCS321 Languages and Compiler Design I. Winter 2012 Lecture 5
CS321 Lnguges nd Compiler Design I Winter 2012 Lecture 5 1 FINITE AUTOMATA A non-deterministic finite utomton (NFA) consists of: An input lphet Σ, e.g. Σ =,. A set of sttes S, e.g. S = {1, 3, 5, 7, 11,
More informationTop-down vs Bottom-up. Bottom up parsing. Sentential form. Handles. Handles in expression example
Bottom up prsing Generl e LR0) LR LR1) LLR o est exploit JvCUP, should understnd the theoreticl sis LR prsing); op-down vs Bottom-up Bottom-up more powerful thn top-down; Cn process more powerful grmmr
More informationCompilers Spring 2013 PRACTICE Midterm Exam
Compilers Spring 2013 PRACTICE Midterm Exm This is full length prctice midterm exm. If you wnt to tke it t exm pce, give yourself 7 minutes to tke the entire test. Just like the rel exm, ech question hs
More informationLexical analysis, scanners. Construction of a scanner
Lexicl nlysis scnners (NB. Pges 4-5 re for those who need to refresh their knowledge of DFAs nd NFAs. These re not presented during the lectures) Construction of scnner Tools: stte utomt nd trnsition digrms.
More informationLanguages. L((a (b)(c))*) = { ε,a,bc,aa,abc,bca,... } εw = wε = w. εabba = abbaε = abba. (a (b)(c)) *
Pln for Tody nd Beginning Next week Interpreter nd Compiler Structure, or Softwre Architecture Overview of Progrmming Assignments The MeggyJv compiler we will e uilding. Regulr Expressions Finite Stte
More informationFinite Automata. Lecture 4 Sections Robb T. Koether. Hampden-Sydney College. Wed, Jan 21, 2015
Finite Automt Lecture 4 Sections 3.6-3.7 Ro T. Koether Hmpden-Sydney College Wed, Jn 21, 2015 Ro T. Koether (Hmpden-Sydney College) Finite Automt Wed, Jn 21, 2015 1 / 23 1 Nondeterministic Finite Automt
More informationCSCI 3130: Formal Languages and Automata Theory Lecture 12 The Chinese University of Hong Kong, Fall 2011
CSCI 3130: Forml Lnguges nd utomt Theory Lecture 12 The Chinese University of Hong Kong, Fll 2011 ndrej Bogdnov In progrmming lnguges, uilding prse trees is significnt tsk ecuse prse trees tell us the
More informationDr. D.M. Akbar Hussain
Dr. D.M. Akr Hussin Lexicl Anlysis. Bsic Ide: Red the source code nd generte tokens, it is similr wht humns will do to red in; just tking on the input nd reking it down in pieces. Ech token is sequence
More informationCS412/413. Introduction to Compilers Tim Teitelbaum. Lecture 4: Lexical Analyzers 28 Jan 08
CS412/413 Introduction to Compilers Tim Teitelum Lecture 4: Lexicl Anlyzers 28 Jn 08 Outline DFA stte minimiztion Lexicl nlyzers Automting lexicl nlysis Jlex lexicl nlyzer genertor CS 412/413 Spring 2008
More informationLexical Analysis: Constructing a Scanner from Regular Expressions
Lexicl Anlysis: Constructing Scnner from Regulr Expressions Gol Show how to construct FA to recognize ny RE This Lecture Convert RE to n nondeterministic finite utomton (NFA) Use Thompson s construction
More informationTopic 2: Lexing and Flexing
Topic 2: Lexing nd Flexing COS 320 Compiling Techniques Princeton University Spring 2016 Lennrt Beringer 1 2 The Compiler Lexicl Anlysis Gol: rek strem of ASCII chrcters (source/input) into sequence of
More informationProblem Set 2 Fall 16 Due: Wednesday, September 21th, in class, before class begins.
Problem Set 2 Fll 16 Due: Wednesdy, September 21th, in clss, before clss begins. 1. LL Prsing For the following sub-problems, consider the following context-free grmmr: S T$ (1) T A (2) T bbb (3) A T (4)
More informationCS 432 Fall Mike Lam, Professor a (bc)* Regular Expressions and Finite Automata
CS 432 Fll 2017 Mike Lm, Professor (c)* Regulr Expressions nd Finite Automt Compiltion Current focus "Bck end" Source code Tokens Syntx tree Mchine code chr dt[20]; int min() { flot x = 42.0; return 7;
More informationDefinition of Regular Expression
Definition of Regulr Expression After the definition of the string nd lnguges, we re redy to descrie regulr expressions, the nottion we shll use to define the clss of lnguges known s regulr sets. Recll
More informationΕΠΛ323 - Θεωρία και Πρακτική Μεταγλωττιστών
ΕΠΛ323 - Θωρία και Πρακτική Μταγλωττιστών Lecture 3 Lexicl Anlysis Elis Athnsopoulos elisthn@cs.ucy.c.cy Recognition of Tokens if expressions nd reltionl opertors if è if then è then else è else relop
More information10/12/17. Motivating Example. Lexical and Syntax Analysis (2) Recursive-Descent Parsing. Recursive-Descent Parsing. Recursive-Descent Parsing
Motivting Exmple Lexicl nd yntx Anlysis (2) In Text: Chpter 4 Consider the grmmr -> cad A -> b Input string: w = cd How to build prse tree top-down? 2 Initilly crete tree contining single node (the strt
More informationECE 468/573 Midterm 1 September 28, 2012
ECE 468/573 Midterm 1 September 28, 2012 Nme:! Purdue emil:! Plese sign the following: I ffirm tht the nswers given on this test re mine nd mine lone. I did not receive help from ny person or mteril (other
More informationDeterministic. Finite Automata. And Regular Languages. Fall 2018 Costas Busch - RPI 1
Deterministic Finite Automt And Regulr Lnguges Fll 2018 Costs Busch - RPI 1 Deterministic Finite Automton (DFA) Input Tpe String Finite Automton Output Accept or Reject Fll 2018 Costs Busch - RPI 2 Trnsition
More informationReducing a DFA to a Minimal DFA
Lexicl Anlysis - Prt 4 Reducing DFA to Miniml DFA Input: DFA IN Assume DFA IN never gets stuck (dd ded stte if necessry) Output: DFA MIN An equivlent DFA with the minimum numer of sttes. Hrry H. Porter,
More informationCSc 453. Compilers and Systems Software. 4 : Lexical Analysis II. Department of Computer Science University of Arizona
CSc 453 Compilers nd Systems Softwre 4 : Lexicl Anlysis II Deprtment of Computer Science University of Arizon collerg@gmil.com Copyright c 2009 Christin Collerg Implementing Automt NFAs nd DFAs cn e hrd-coded
More informationCSE 401 Midterm Exam 11/5/10 Sample Solution
Question 1. egulr expressions (20 points) In the Ad Progrmming lnguge n integer constnt contins one or more digits, but it my lso contin embedded underscores. Any underscores must be preceded nd followed
More informationCS 340, Fall 2014 Dec 11 th /13 th Final Exam Note: in all questions, the special symbol ɛ (epsilon) is used to indicate the empty string.
CS 340, Fll 2014 Dec 11 th /13 th Finl Exm Nme: Note: in ll questions, the specil symol ɛ (epsilon) is used to indicte the empty string. Question 1. [5 points] Consider the following regulr expression;
More informationMidterm I Solutions CS164, Spring 2006
Midterm I Solutions CS164, Spring 2006 Februry 23, 2006 Plese red ll instructions (including these) crefully. Write your nme, login, SID, nd circle the section time. There re 8 pges in this exm nd 4 questions,
More informationAlgorithm Design (5) Text Search
Algorithm Design (5) Text Serch Tkshi Chikym School of Engineering The University of Tokyo Text Serch Find sustring tht mtches the given key string in text dt of lrge mount Key string: chr x[m] Text Dt:
More informationCMPSC 470: Compiler Construction
CMPSC 47: Compiler Construction Plese complete the following: Midterm (Type A) Nme Instruction: Mke sure you hve ll pges including this cover nd lnk pge t the end. Answer ech question in the spce provided.
More informationImplementing Automata. CSc 453. Compilers and Systems Software. 4 : Lexical Analysis II. Department of Computer Science University of Arizona
Implementing utomt Sc 5 ompilers nd Systems Softwre : Lexicl nlysis II Deprtment of omputer Science University of rizon collerg@gmil.com opyright c 009 hristin ollerg NFs nd DFs cn e hrd-coded using this
More informationSome Thoughts on Grad School. Undergraduate Compilers Review and Intro to MJC. Structure of a Typical Compiler. Lexing and Parsing
Undergrdute Compilers Review nd Intro to MJC Announcements Miling list is in full swing Tody Some thoughts on grd school Finish prsing Semntic nlysis Visitor pttern for bstrct syntx trees Some Thoughts
More informationEliminating left recursion grammar transformation. The transformed expression grammar
Eliminting left recursion grmmr trnsformtion Originl! rnsformed! 0 0! 0 α β α α α α α α α α β he two grmmrs generte the sme lnguge, but the one on the right genertes the rst, nd then string of s, using
More informationCOMP 423 lecture 11 Jan. 28, 2008
COMP 423 lecture 11 Jn. 28, 2008 Up to now, we hve looked t how some symols in n lphet occur more frequently thn others nd how we cn sve its y using code such tht the codewords for more frequently occuring
More informationCS143 Handout 07 Summer 2011 June 24 th, 2011 Written Set 1: Lexical Analysis
CS143 Hndout 07 Summer 2011 June 24 th, 2011 Written Set 1: Lexicl Anlysis In this first written ssignment, you'll get the chnce to ply round with the vrious constructions tht come up when doing lexicl
More informationLexical Analysis. Amitabha Sanyal. (www.cse.iitb.ac.in/ as) Department of Computer Science and Engineering, Indian Institute of Technology, Bombay
Lexicl Anlysis Amith Snyl (www.cse.iit.c.in/ s) Deprtment of Computer Science nd Engineering, Indin Institute of Technology, Bomy Septemer 27 College of Engineering, Pune Lexicl Anlysis: 2/6 Recp The input
More informationIf you are at the university, either physically or via the VPN, you can download the chapters of this book as PDFs.
Lecture 5 Wlks, Trils, Pths nd Connectedness Reding: Some of the mteril in this lecture comes from Section 1.2 of Dieter Jungnickel (2008), Grphs, Networks nd Algorithms, 3rd edition, which is ville online
More informationΕΠΛ323 - Θεωρία και Πρακτική Μεταγλωττιστών. Lecture 3b Lexical Analysis Elias Athanasopoulos
ΕΠΛ323 - Θωρία και Πρακτική Μταγλωττιστών Lecture 3 Lexicl Anlysis Elis Athnsopoulos elisthn@cs.ucy.c.cy RecogniNon of Tokens if expressions nd relnonl opertors if è if then è then else è else relop è
More informationHomework. Context Free Languages III. Languages. Plan for today. Context Free Languages. CFLs and Regular Languages. Homework #5 (due 10/22)
Homework Context Free Lnguges III Prse Trees nd Homework #5 (due 10/22) From textbook 6.4,b 6.5b 6.9b,c 6.13 6.22 Pln for tody Context Free Lnguges Next clss of lnguges in our quest! Lnguges Recll. Wht
More informationLexical Analysis and Lexical Analyzer Generators
1 Lexicl Anlysis nd Lexicl Anlyzer Genertors Chpter 3 COP5621 Compiler Construction Copyright Roert vn Engelen, Florid Stte University, 2007-2009 2 The Reson Why Lexicl Anlysis is Seprte Phse Simplifies
More information2 Computing all Intersections of a Set of Segments Line Segment Intersection
15-451/651: Design & Anlysis of Algorithms Novemer 14, 2016 Lecture #21 Sweep-Line nd Segment Intersection lst chnged: Novemer 8, 2017 1 Preliminries The sweep-line prdigm is very powerful lgorithmic design
More informationCS 340, Fall 2016 Sep 29th Exam 1 Note: in all questions, the special symbol ɛ (epsilon) is used to indicate the empty string.
CS 340, Fll 2016 Sep 29th Exm 1 Nme: Note: in ll questions, the speil symol ɛ (epsilon) is used to indite the empty string. Question 1. [10 points] Speify regulr expression tht genertes the lnguge over
More informationWhat are suffix trees?
Suffix Trees 1 Wht re suffix trees? Allow lgorithm designers to store very lrge mount of informtion out strings while still keeping within liner spce Allow users to serch for new strings in the originl
More informationOperator Precedence. Java CUP. E E + T T T * P P P id id id. Does a+b*c mean (a+b)*c or
Opertor Precedence Most progrmming lnguges hve opertor precedence rules tht stte the order in which opertors re pplied (in the sence of explicit prentheses). Thus in C nd Jv nd CSX, +*c mens compute *c,
More informationPrinciples of Programming Languages
Principles of Progrmming Lnguges h"p://www.di.unipi.it/~ndre/did2c/plp- 14/ Prof. Andre Corrdini Deprtment of Computer Science, Pis Lesson 5! Gener;on of Lexicl Anlyzers Creting Lexicl Anlyzer with Lex
More informationASTs, Regex, Parsing, and Pretty Printing
ASTs, Regex, Prsing, nd Pretty Printing CS 2112 Fll 2016 1 Algeric Expressions To strt, consider integer rithmetic. Suppose we hve the following 1. The lphet we will use is the digits {0, 1, 2, 3, 4, 5,
More informationScanner Termination. Multi Character Lookahead. to its physical end. Most parsers require an end of file token. Lex and Jlex automatically create an
Scnner Termintion A scnner reds input chrcters nd prtitions them into tokens. Wht hppens when the end of the input file is reched? It my be useful to crete n Eof pseudo-chrcter when this occurs. In Jv,
More informationCS 241. Fall 2017 Midterm Review Solutions. October 24, Bits and Bytes 1. 3 MIPS Assembler 6. 4 Regular Languages 7.
CS 241 Fll 2017 Midterm Review Solutions Octoer 24, 2017 Contents 1 Bits nd Bytes 1 2 MIPS Assemly Lnguge Progrmming 2 3 MIPS Assemler 6 4 Regulr Lnguges 7 5 Scnning 9 1 Bits nd Bytes 1. Give two s complement
More informationCS201 Discussion 10 DRAWTREE + TRIES
CS201 Discussion 10 DRAWTREE + TRIES DrwTree First instinct: recursion As very generic structure, we could tckle this problem s follows: drw(): Find the root drw(root) drw(root): Write the line for the
More informationFrom Dependencies to Evaluation Strategies
From Dependencies to Evlution Strtegies Possile strtegies: 1 let the user define the evlution order 2 utomtic strtegy sed on the dependencies: use locl dependencies to determine which ttriutes to compute
More informationBottom Up Parsing. Shift and Reduce. Sentential Form. Handle. Parse Tree. Bottom Up Parsing 9/26/2012. Also known as Shift-Reduce parsing
Also known as Shift-Reduce parsing More powerful than top down Don t need left factored grammars Can handle left recursion Attempt to construct parse tree from an input string eginning at leaves and working
More informationCompilation
Compiltion 0368-3133 Lecture 2: Lexicl Anlysis Nom Rinetzky 1 2 Lexicl Anlysis Modern Compiler Design: Chpter 2.1 3 Conceptul Structure of Compiler Compiler Source text txt Frontend Semntic Representtion
More informationJava CUP. Java CUP Specifications. User Code Additions. Package and Import Specifications
Jv CUP Jv CUP is prser-genertion tool, similr to Ycc. CUP uilds Jv prser for LALR(1) grmmrs from production rules nd ssocited Jv code frgments. When prticulr production is recognized, its ssocited code
More informationCompiler Design 1. Bottom-UP Parsing. Goutam Biswas. Lect 6
Compiler Design 1 Bottom-UP Parsing Compiler Design 2 The Process The parse tree is built starting from the leaf nodes labeled by the terminals (tokens). The parser tries to discover appropriate reductions,
More informationCS311H: Discrete Mathematics. Graph Theory IV. A Non-planar Graph. Regions of a Planar Graph. Euler s Formula. Instructor: Işıl Dillig
CS311H: Discrete Mthemtics Grph Theory IV Instructor: Işıl Dillig Instructor: Işıl Dillig, CS311H: Discrete Mthemtics Grph Theory IV 1/25 A Non-plnr Grph Regions of Plnr Grph The plnr representtion of
More informationScanner Termination. Multi Character Lookahead
If d.doublevlue() represents vlid integer, (int) d.doublevlue() will crete the pproprite integer vlue. If string representtion of n integer begins with ~ we cn strip the ~, convert to double nd then negte
More informationCS 236 Language and Computation. Alphabet. Definition. I.2.1. Formal Languages (10.1)
C 236 Lnguge nd Computtion Course Notes Prt I: Grmmrs for Defining yntx (II) Chpter I.2: yntx nd Grmmrs (10, 12.1) Anton etzer (Bsed on ook drft y J. V. Tucker nd K. tephenson) Dept. of Computer cience,
More informationCMSC 331 First Midterm Exam
0 00/ 1 20/ 2 05/ 3 15/ 4 15/ 5 15/ 6 20/ 7 30/ 8 30/ 150/ 331 First Midterm Exm 7 October 2003 CMC 331 First Midterm Exm Nme: mple Answers tudent ID#: You will hve seventy-five (75) minutes to complete
More informationLING/C SC/PSYC 438/538. Lecture 21 Sandiway Fong
LING/C SC/PSYC 438/538 Lecture 21 Sndiwy Fong Tody's Topics Homework 8 Review Optionl Homework 9 (mke up on Homework 7) Homework 8 Review Question1: write Prolog regulr grmmr for the following lnguge:
More informationCS 241 Week 4 Tutorial Solutions
CS 4 Week 4 Tutoril Solutions Writing n Assemler, Prt & Regulr Lnguges Prt Winter 8 Assemling instrutions utomtilly. slt $d, $s, $t. Solution: $d, $s, nd $t ll fit in -it signed integers sine they re 5-it
More informationCSEP 573 Artificial Intelligence Winter 2016
CSEP 573 Artificil Intelligence Winter 2016 Luke Zettlemoyer Problem Spces nd Serch slides from Dn Klein, Sturt Russell, Andrew Moore, Dn Weld, Pieter Abbeel, Ali Frhdi Outline Agents tht Pln Ahed Serch
More informationExample: Source Code. Lexical Analysis. The Lexical Structure. Tokens. What do we really care here? A Sample Toy Program:
Lexicl Anlysis Red source progrm nd produce list of tokens ( liner nlysis) source progrm The lexicl structure is specified using regulr expressions Other secondry tsks: (1) get rid of white spces (e.g.,
More informationToday. Search Problems. Uninformed Search Methods. Depth-First Search Breadth-First Search Uniform-Cost Search
Uninformed Serch [These slides were creted by Dn Klein nd Pieter Abbeel for CS188 Intro to AI t UC Berkeley. All CS188 mterils re vilble t http://i.berkeley.edu.] Tody Serch Problems Uninformed Serch Methods
More informationContext-Free Grammars
Context-Free Grmmrs Descriing Lnguges We've seen two models for the regulr lnguges: Finite utomt ccept precisely the strings in the lnguge. Regulr expressions descrie precisely the strings in the lnguge.
More informationCompiler Construction D7011E
Compiler Construction D7011E Lecture 3: Lexer genertors Viktor Leijon Slides lrgely y John Nordlnder with mteril generously provided y Mrk P. Jones. 1 Recp: Hndwritten Lexers: Don t require sophisticted
More informationSolving Problems by Searching. CS 486/686: Introduction to Artificial Intelligence Winter 2016
Solving Prolems y Serching CS 486/686: Introduction to Artificil Intelligence Winter 2016 1 Introduction Serch ws one of the first topics studied in AI - Newell nd Simon (1961) Generl Prolem Solver Centrl
More informationP(r)dr = probability of generating a random number in the interval dr near r. For this probability idea to make sense we must have
Rndom Numers nd Monte Crlo Methods Rndom Numer Methods The integrtion methods discussed so fr ll re sed upon mking polynomil pproximtions to the integrnd. Another clss of numericl methods relies upon using
More informationMIT Parse Table Construction. Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology
MIT 6.035 Parse Table Construction Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology Parse Tables (Review) ACTION Goto State ( ) $ X s0 shift to s2 error error goto s1
More informationContext-free grammars
Context-free grammars Section 4.2 Formal way of specifying rules about the structure/syntax of a program terminals - tokens non-terminals - represent higher-level structures of a program start symbol,
More informationContext-Free Grammars
Context-Free Grmmrs Descriing Lnguges We've seen two models for the regulr lnguges: Finite utomt ccept precisely the strings in the lnguge. Regulr expressions descrie precisely the strings in the lnguge.
More informationCSc 453 Compilers and Systems Software. 6 : Top-Down Parsing I
C 45 Compilers n ystems oftwre 6 : op-down Prsing I Christin Collberg Deprtment of Computer iene University of rizon ollberg@gmil.om Copyright 2009 Christin Collberg eptember 14, 2009 1 Overview 2 Compiler
More informationCSCI 446: Artificial Intelligence
CSCI 446: Artificil Intelligence Serch Instructor: Michele Vn Dyne [These slides were creted by Dn Klein nd Pieter Abbeel for CS188 Intro to AI t UC Berkeley. All CS188 mterils re vilble t http://i.berkeley.edu.]
More information10.5 Graphing Quadratic Functions
0.5 Grphing Qudrtic Functions Now tht we cn solve qudrtic equtions, we wnt to lern how to grph the function ssocited with the qudrtic eqution. We cll this the qudrtic function. Grphs of Qudrtic Functions
More informationA Tautology Checker loosely related to Stålmarck s Algorithm by Martin Richards
A Tutology Checker loosely relted to Stålmrck s Algorithm y Mrtin Richrds mr@cl.cm.c.uk http://www.cl.cm.c.uk/users/mr/ University Computer Lortory New Museum Site Pemroke Street Cmridge, CB2 3QG Mrtin
More informationCompiler Construction: Parsing
Compiler Construction: Parsing Mandar Mitra Indian Statistical Institute M. Mitra (ISI) Parsing 1 / 33 Context-free grammars. Reference: Section 4.2 Formal way of specifying rules about the structure/syntax
More informationBottom-Up Parsing. Lecture 11-12
Bottom-Up Parsing Lecture 11-12 (From slides by G. Necula & R. Bodik) 9/22/06 Prof. Hilfinger CS164 Lecture 11 1 Bottom-Up Parsing Bottom-up parsing is more general than topdown parsing And just as efficient
More informationSuffix trees, suffix arrays, BWT
ALGORITHMES POUR LA BIO-INFORMATIQUE ET LA VISUALISATION COURS 3 Rluc Uricru Suffix trees, suffix rrys, BWT Bsed on: Suffix trees nd suffix rrys presenttion y Him Kpln Suffix trees course y Pco Gomez Liner-Time
More informationCMPT 379 Compilers. Lexical Analysis
CMPT 379 Compilers Anoop Srkr http://www.cs.sfu.c/~noop 9//7 Lexicl Anlysis Also clled scnning, tke input progrm string nd convert into tokens Exmple: T_DOUBLE ( doule ) T_IDENT ( f ) T_OP ( = ) doule
More informationacronyms possibly used in this test: CFG :acontext free grammar CFSM :acharacteristic finite state machine DFA :adeterministic finite automata
EE573 Fll 2002, Exm open book, if question seems mbiguous, sk me to clrify the question. If my nswer doesn t stisfy you, plese stte your ssumptions. cronyms possibly used in this test: CFG :context free
More informationAI Adjacent Fields. This slide deck courtesy of Dan Klein at UC Berkeley
AI Adjcent Fields Philosophy: Logic, methods of resoning Mind s physicl system Foundtions of lerning, lnguge, rtionlity Mthemtics Forml representtion nd proof Algorithms, computtion, (un)decidility, (in)trctility
More informationToday. CS 188: Artificial Intelligence Fall Recap: Search. Example: Pancake Problem. Example: Pancake Problem. General Tree Search.
CS 88: Artificil Intelligence Fll 00 Lecture : A* Serch 9//00 A* Serch rph Serch Tody Heuristic Design Dn Klein UC Berkeley Multiple slides from Sturt Russell or Andrew Moore Recp: Serch Exmple: Pncke
More informationTheory of Computation CSE 105
$ $ $ Theory of Computtion CSE 105 Regulr Lnguges Study Guide nd Homework I Homework I: Solutions to the following problems should be turned in clss on July 1, 1999. Instructions: Write your nswers clerly
More informationA left-sentential form is a sentential form that occurs in the leftmost derivation of some sentence.
Bottom-up parsing Recall For a grammar G, with start symbol S, any string α such that S α is a sentential form If α V t, then α is a sentence in L(G) A left-sentential form is a sentential form that occurs
More informationSuffix Tries. Slides adapted from the course by Ben Langmead
Suffix Tries Slides dpted from the course y Ben Lngmed en.lngmed@gmil.com Indexing with suffixes Until now, our indexes hve een sed on extrcting sustrings from T A very different pproch is to extrct suffixes
More informationSolving Problems by Searching. CS 486/686: Introduction to Artificial Intelligence
Solving Prolems y Serching CS 486/686: Introduction to Artificil Intelligence 1 Introduction Serch ws one of the first topics studied in AI - Newell nd Simon (1961) Generl Prolem Solver Centrl component
More informationCompiler Construction 2016/2017 Syntax Analysis
Compiler Construction 2016/2017 Syntax Analysis Peter Thiemann November 2, 2016 Outline 1 Syntax Analysis Recursive top-down parsing Nonrecursive top-down parsing Bottom-up parsing Syntax Analysis tokens
More informationApplied Databases. Sebastian Maneth. Lecture 13 Online Pattern Matching on Strings. University of Edinburgh - February 29th, 2016
Applied Dtses Lecture 13 Online Pttern Mtching on Strings Sestin Mneth University of Edinurgh - Ferury 29th, 2016 2 Outline 1. Nive Method 2. Automton Method 3. Knuth-Morris-Prtt Algorithm 4. Boyer-Moore
More informationS Y N T A X A N A L Y S I S LR
LR parsing There are three commonly used algorithms to build tables for an LR parser: 1. SLR(1) = LR(0) plus use of FOLLOW set to select between actions smallest class of grammars smallest tables (number
More informationFall Compiler Principles Lecture 1: Lexical Analysis. Roman Manevich Ben-Gurion University of the Negev
Fll 2016-2017 Compiler Principles Lecture 1: Lexicl Anlysis Romn Mnevich Ben-Gurion University of the Negev Agend Understnd role of lexicl nlysis in compiler Regulr lnguges reminder Lexicl nlysis lgorithms
More informationBottom up parsing. The sentential forms happen to be a right most derivation in the reverse order. S a A B e a A d e. a A d e a A B e S.
Bottom up parsing Construct a parse tree for an input string beginning at leaves and going towards root OR Reduce a string w of input to start symbol of grammar Consider a grammar S aabe A Abc b B d And
More informationIntermediate Information Structures
CPSC 335 Intermedite Informtion Structures LECTURE 13 Suffix Trees Jon Rokne Computer Science University of Clgry Cnd Modified from CMSC 423 - Todd Trengen UMD upd Preprocessing Strings We will look t
More informationTries. Yufei Tao KAIST. April 9, Y. Tao, April 9, 2013 Tries
Tries Yufei To KAIST April 9, 2013 Y. To, April 9, 2013 Tries In this lecture, we will discuss the following exct mtching prolem on strings. Prolem Let S e set of strings, ech of which hs unique integer
More informationIn One Slide. Outline. LR Parsing. Table Construction
LR Parsing Table Construction #1 In One Slide An LR(1) parsing table can be constructed automatically from a CFG. An LR(1) item is a pair made up of a production and a lookahead token; it represents a
More informationMa/CS 6b Class 1: Graph Recap
M/CS 6 Clss 1: Grph Recp By Adm Sheffer Course Detils Adm Sheffer. Office hour: Tuesdys 4pm. dmsh@cltech.edu TA: Victor Kstkin. Office hour: Tuesdys 7pm. 1:00 Mondy, Wednesdy, nd Fridy. http://www.mth.cltech.edu/~2014-15/2term/m006/
More informationBottom-up parsing. Bottom-Up Parsing. Recall. Goal: For a grammar G, withstartsymbols, any string α such that S α is called a sentential form
Bottom-up parsing Bottom-up parsing Recall Goal: For a grammar G, withstartsymbols, any string α such that S α is called a sentential form If α V t,thenα is called a sentence in L(G) Otherwise it is just
More informationShould be done. Do Soon. Structure of a Typical Compiler. Plan for Today. Lab hours and Office hours. Quiz 1 is due tonight, was posted Tuesday night
Should e done L hours nd Office hours Sign up for the miling list t, strting to send importnt info to list http://groups.google.com/group/cs453-spring-2011 Red Ch 1 nd skim Ch 2 through 2.6, red 3.3 nd
More information