Download presentation
Presentation is loading. Please wait.
Published byJudith Palmer Modified over 9 years ago
1
March 1, 2009 Dr. Muhammed Al-Mulhem 1 ICS 482 Natural Language Processing LR Parsing Muhammed Al-Mulhem March 1, 2009
2
2Dr. Muhammed Al-Mulhem LR-parsing algorithm INPUT: An input string w and an LR-parsing table with functions ACTION and GOT0 for a grammar G. OUTPUT: If w is in L(G), the reduction steps of a bottom-up parse for w; otherwise, an error indication. METHOD: Initially, the parser has s 0 on its stack, where s 0 is the initial state, and w$ in the input buffer. The parser then executes the following steps:
3
March 1, 2009 3Dr. Muhammed Al-Mulhem LR-parsing algorithm let a be the first symbol of w$; while(1) { /* repeat forever */ let s be the state on top of the stack; if ( ACTION[s, a] = shift t ) { push a and t onto the stack; let a be the next input symbol; } else if ( ACTION[s, a] = reduce A → β ) { pop 2*I β I symbols off the stack; let state t now be on top of the stack; push A and GO TO[t, A] onto the stack; output the production A → β ; } else if ( ACTION[s, a] = accept ) break; /* parsing is done */ else call error-recovery routine; }
4
March 1, 2009 4Dr. Muhammed Al-Mulhem states()x,$SL 1s3s2g4 2r2r2r2r2r2 3s3s2g7g5 4a 5s6s8 6r1r1r1r1r1 7r3r3r3r3r3 8s3s2g9 9r4r4r4r4r4 1 ( x, x ) $ yet to read input: stack: 0. S’ ::= S $ 1. S ::= ( L ) 2. S ::= x 3. L ::= S 4. L ::= L, S
5
March 1, 2009 5Dr. Muhammed Al-Mulhem states()x,$SL 1s3s2g4 2r2r2r2r2r2 3s3s2g7g5 4a 5s6s8 6r1r1r1r1r1 7r3r3r3r3r3 8s3s2g9 9r4r4r4r4r4 ( x, x ) $ yet to read input: stack:1 ( 3 0. S’ ::= S $ 1. S ::= ( L ) 2. S ::= x 3. L ::= S 4. L ::= L, S GotoAction
6
March 1, 2009 6Dr. Muhammed Al-Mulhem states()x,$SL 1s3s2g4 2r2r2r2r2r2 3s3s2g7g5 4a 5s6s8 6r1r1r1r1r1 7r3r3r3r3r3 8s3s2g9 9r4r4r4r4r4 ( x, x ) $ yet to read input: stack:1 ( 3 x 2 0. S’ ::= S $ 1. S ::= ( L ) 2. S ::= x 3. L ::= S 4. L ::= L, S
7
March 1, 2009 7Dr. Muhammed Al-Mulhem states()x,$SL 1s3s2g4 2r2r2r2r2r2 3s3s2g7g5 4a 5s6s8 6r1r1r1r1r1 7r3r3r3r3r3 8s3s2g9 9r4r4r4r4r4 ( x, x ) $ yet to read input: stack:1 ( 3 S 0. S’ ::= S $ S ::= ( L ) S ::= x L ::= S L ::= L, S
8
March 1, 2009 8Dr. Muhammed Al-Mulhem states()x,$SL 1s3s2g4 2r2r2r2r2r2 3s3s2g7g5 4a 5s6s8 6r1r1r1r1r1 7r3r3r3r3r3 8s3s2g9 9r4r4r4r4r4 ( x, x ) $ yet to read input: stack:1 ( 3 S 7 0. S’ ::= S $ 1. S ::= ( L ) 2. S ::= x 3. L ::= S 4. L ::= L, S
9
March 1, 2009 9Dr. Muhammed Al-Mulhem states()x,$SL 1s3s2g4 2r2r2r2r2r2 3s3s2g7g5 4a 5s6s8 6r1r1r1r1r1 7r3r3r3r3r3 8s3s2g9 9r4r4r4r4r4 ( x, x ) $ yet to read input: stack:1 ( 3 L 0. S’ ::= S $ 1. S ::= ( L ) 2. S ::= x 3. L ::= S 4. L ::= L, S
10
March 1, 2009 10Dr. Muhammed Al-Mulhem states()x,$SL 1s3s2g4 2r2r2r2r2r2 3s3s2g7g5 4a 5s6s8 6r1r1r1r1r1 7r3r3r3r3r3 8s3s2g9 9r4r4r4r4r4 ( x, x ) $ yet to read input: stack:1 ( 3 L 5 0. S’ ::= S $ 1. S ::= ( L ) 2. S ::= x 3. L ::= S 4. L ::= L, S
11
March 1, 2009 11Dr. Muhammed Al-Mulhem states()x,$SL 1s3s2g4 2r2r2r2r2r2 3s3s2g7g5 4a 5s6s8 6r1r1r1r1r1 7r3r3r3r3r3 8s3s2g9 9r4r4r4r4r4 ( x, x ) $ yet to read input: stack:1 ( 3 L 5, 8 0. S’ ::= S $ 1. S ::= ( L ) 2. S ::= x 3. L ::= S 4. L ::= L, S
12
March 1, 2009 12Dr. Muhammed Al-Mulhem states()x,$SL 1s3s2g4 2r2r2r2r2r2 3s3s2g7g5 4a 5s6s8 6r1r1r1r1r1 7r3r3r3r3r3 8s3s2g9 9r4r4r4r4r4 ( x, x ) $ yet to read input: stack:1 ( 3 L 5, 8 x 2 0. S’ ::= S $ 1. S ::= ( L ) 2. S ::= x 3. L ::= S 4. L ::= L, S
13
March 1, 2009 13Dr. Muhammed Al-Mulhem states()x,$SL 1s3s2g4 2r2r2r2r2r2 3s3s2g7g5 4a 5s6s8 6r1r1r1r1r1 7r3r3r3r3r3 8s3s2g9 9r4r4r4r4r4 ( x, x ) $ yet to read input: stack:1 ( 3 L 5, 8 S 0. S’ ::= S $ 1. S ::= ( L ) 2. S ::= x 3. L ::= S 4. L ::= L, S
14
March 1, 2009 14Dr. Muhammed Al-Mulhem states()x,$SL 1s3s2g4 2r2r2r2r2r2 3s3s2g7g5 4a 5s6s8 6r1r1r1r1r1 7r3r3r3r3r3 8s3s2g9 9r4r4r4r4r4 ( x, x ) $ yet to read input: stack:1 ( 3 L 5, 8 S 9 0. S’ ::= S $ 1. S ::= ( L ) 2. S ::= x 3. L ::= S 4. L ::= L, S
15
March 1, 2009 15Dr. Muhammed Al-Mulhem states()x,$SL 1s3s2g4 2r2r2r2r2r2 3s3s2g7g5 4a 5s6s8 6r1r1r1r1r1 7r3r3r3r3r3 8s3s2g9 9r4r4r4r4r4 ( x, x ) $ yet to read input: stack:1 ( 3 L 0. S’ ::= S $ 1. S ::= ( L ) 2. S ::= x 3. L ::= S 4. L ::= L, S
16
March 1, 2009 16Dr. Muhammed Al-Mulhem states()x,$SL 1s3s2g4 2r2r2r2r2r2 3s3s2g7g5 4a 5s6s8 6r1r1r1r1r1 7r3r3r3r3r3 8s3s2g9 9r4r4r4r4r4 ( x, x ) $ yet to read input: stack:1 ( 3 L 5etc...... 0. S’ ::= S $ 1. S ::= ( L ) 2. S ::= x 3. L ::= S 4. L ::= L, S
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.