Table-driven using an explicit stack (no recursion!). Stack can be viewed as containing both terminals and non-terminals.

Size: px
Start display at page:

Download "Table-driven using an explicit stack (no recursion!). Stack can be viewed as containing both terminals and non-terminals."

Transcription

1 Bottom-up Parsing: Table-driven using an explicit stack (no recursion!). Stack can be viewed as containing both terminals and non-terminals. Basic operation is to shift terminals from the input to the stack until the right-hand side of an appropriate grammar rule is seen, and then to reduce the stuff on the stack that matches the right-hand side to the single non-terminal of the rule. Hence, bottom-up parsers are often called shift-reduce parsers. 1 Example Grammar: E E + n n Input: 2 + 3, or n + n Parse: ($ is EOF input, also bottom of stack) Parsing stack Input Action 1 $ n + n $ shift 2 $ n + n $ reduce E n 3 $ E + n $ shift 4 $ E + n $ shift 5 $ E + n $ reduce E E + n 6 $ E $ accept 2 Compiler Construction F6S 1

2 Notes: Left recursion is not a problem in bottom-up parsing. Indeed, as we shall see, look-ahead is not as serious an issue. Keeping track of what is on the stack, however, is an issue (note the difference in the grammar rule reductions at lines 2 and 5 of the previous example). See later discussion on stack state. Right recursion is actually a bit of a problem, because it makes the stack grow large (see next example). 3 Example Grammar: E n + E n Input: 2 + 3, or n + n Parse: Parsing stack Input Action 1 $ n + n $ shift 2 $ n + n $ shift 3 $ n + n $ shift 4 $ n + n $ reduce E n 5 $ n + E $ reduce E n + E 6 $ E $ accept 4 Compiler Construction F6S 2

3 Decision Problems in Bottom-up Parsing (parsing conflicts): Shift-reduce conflicts: Almost always come from ambiguities, and almost always the right disambiguating rule is to shift (dangling-else). Reduce-reduce conflicts: More difficult, bottom-up parsers try to resolve them using Follow contexts. There are no shift-shift conflicts. 5 Dangling-else Example: Grammar: S I o I i S i S e S Input: i i o e o Parse: Parsing stack Input Action 1 $ i i o e o $ shift 2 $ i i o e o $ shift 3 $ i i o e o $ shift 4 $ i i o e o $ reduce S o 5 $ i i S e o $ shift/reduce (shift) 6 $ i i S e o $ shift 7 $ i i S e o $ reduce S o 8 $ i i S e S $ reduce I i S e S 9 $ i I $ reduce S I 10 $ i S $ reduce I i S 11 $ I $ reduce S I 12 $ S $ accept 6 Compiler Construction F6S 3

4 Reduce-reduce Example Grammar: S AB A x B x Input: x x Parse: (Follow(A) = {x}, Follow(B) = {$}) Parsing stack Input Action 1 $ x x $ shift 2 $ x x $ reduce A x (reduce B x) 3 $ A x $ shift 4 $ A x $ reduce B x 5 $ A B $ reduce S A B 6 $ S $ accept 7 Shift-reduce parsers differ in their use of Follow information: LR(0) parsers never consult the look-ahead at all. SLR(1) parsers use the Follow sets as previously constructed. LR(1) parsers use context to split the Follow sets into subsets for different parsing paths (huge, inefficient parsers). LALR(1) parsers: like LR(1) but coarser subsets are used (achieves most of the benefit, but much smaller and faster). 8 Compiler Construction F6S 4

5 Technical Addendum Shift-reduce parsers have trouble figuring out when to accept, so acceptance is turned into a reduction by a new rule S S with a new start symbol S. Adding this rule is called augmenting the grammar: Parsing stack Input Action <previous example> $ A B $ reduce S A B 6 $ S $ reduce S' S 7 $ S' $ accept 9 Format of a Yacc/Bison definition file {definitions} %% {rules} %% {auxiliary C functions} Typical file extensions:.y.yacc.bison 10 Compiler Construction F6S 5

6 Stack States: the DFA of sets of LR(0) items An item is a grammar rule option with a distinguished position (indicated by a period or other symbol): A α. β The position in an item indicates that a parse has reached that position in recognizing that rule. α is then on the stack, and a β may be coming in the input (the α is called a viable prefix). A stack state consists of the set of items which have compatible viable prefixes. 11 Computing the DFA of sets of LR(0) items Add the augmentation item S. S to the start state of the DFA. Then add all the initial items for S to the state: S. α. Continue by adding all the initial items for those nonterminals which appear right after the dot in any previous item (this is called the closure of the set of items). Every symbol that comes immediately after the dot gives rise to a transition to a state generated by adding closure items to the item with the dot moved past that symbol. 12 Compiler Construction F6S 6

7 Example: S A B, A x, B x The DFA of sets of items: S' S A x. S. A B. x 0 S A S' S. 5 A x. 1 B S A. B S A B. B. x 4 2 x B x Parsing Table from the DFA (1) S AB, (2) A x, (3) B x State Input Goto x other $ S A B 0 s r2 r2 r2 2 s3 4 3 r3 r3 r3 4 r1 r1 r1 5 accept Note that this table is LR(0), since each state is either a shift state or a reduce state by a single rule. Thus, no look-ahead needs to be consulted. 14 Compiler Construction F6S 7

8 Example of a parse by the table Parsing stack Input Action 1 $0 x x $ s1 2 $ 0 x 1 x $ r2 (A x) 3 $ 0 A 2 x $ s3 4 $ 0 A 2 x 3 $ r3 (B x) 5 $ 0 A 2 B 4 $ r1 (S A B) 6 $ 0 S 5 $ accept Note that, with the state numbers on the stack, the symbols themselves need not be put on the stack, and we will delete them occasionally from future examples. 15 Bison table is essentially the same: state 0 'x' shift, and go to state 1 S go to state 5 A go to state 2 state 1 A -> 'x'.(rule 2) $default reduce using rule 2 (A) state 2 S -> A. B (rule 1) 'x' shift, and go to state 3 B go to state 4 state 3 B -> 'x'. (rule 3) $default reduce using rule 3 (B) state 4 S -> A B. (rule 1) $default reduce using rule 1 (S) state 5 $ go to state 6 state 6 $ go to state 7 state 7 $default accept 16 Compiler Construction F6S 8

9 Example: E E + n n The DFA of sets of items: E'. E E. E + n E. n 0 n E E' E. E E. + n 1 + E n. E E +. n n E E + n Parsing Table (not( LR(0)!): ): State Input Goto n + $ E 0 s2 1 1 s3 accept 2 r (E n) r (E n) 3 s4 4 r (E E + n) r (E E + n) This table uses the SLR(1) rule: consult the Follow sets to decide between a shift and a reduce, or between two reduces: Follow(E) = { + $ }, Follow(E ) = {$} (Note the clear need for augmentation in this case) 18 Compiler Construction F6S 9

10 Sample Parse: Parsing stack Input Action 1 $ 0 n + n + n $ shift 2 2 $ 0 n 2 + n + n $ reduce E n 3 $ 0 E 1 + n + n $ shift 3 4 $ 0 E n + n $ shift 4 5 $ 0 E n 4 + n $ reduce E E + n 6 $ 0 E 1 + n $ shift 3 7 $ 0 E n $ shift 4 8 $ 0 E n 4 $ reduce E E + n 9 $ 0 E 1 $ accept 19 Example with ε (Bison table): S A B, A x, A ε, B x state 0 'x' shift, and go to state 1 'x' [reduce using rule 3 (A)] $default reduce using rule 3 (A) S go to state 5 A go to state 2 state 1 A -> 'x'. (rule 2) $default reduce using rule 2 (A) state 2 etc Compiler Construction F6S 10

11 Remarks on Example with ε This grammar is unambiguous, but cannot be parsed with one symbol of look-ahead The default disambiguation rule in Bison means it will never accept the string x, only the string x x Thus, even bottom-up parsers have their power limited by look-ahead 21 A Contrasting Example with ε: S A B, A x, B x, B ε state 0 'x' shift, and go to state 1 S go to state 5 A go to state 2 state 1 A -> 'x'. (rule 2) $default reduce using rule 2 (A) state 2 S -> A. B (rule 1) 'x' shift, and go to state 3 $default reduce using rule 4 (B) B go to state 4 22 Compiler Construction F6S 11

12 Contrasting Example with ε (continued) : state 3 B -> 'x'. (rule 3) $default reduce using rule 3 (B) state 4 S -> A B. (rule 1) $default reduce using rule 1 (S) state 5 $ go to state 6 state 6 $ go to state 7 state 7 $default accept 23 Example: E n + E n state 0 'n' shift, and go to state 1 E go to state 4 state 1 E -> 'n'. '+' E (rule 1) E -> 'n'. (rule 2) '+' shift, and go to state 2 $default reduce using rule 2 (E) state 2 E -> 'n' '+'. E (rule 1) 'n' shift, and go to state 1 E go to state 3 state 3 E -> 'n' '+' E. (rule 1) $default reduce using rule 1 (E) state 4 $... accept 24 Compiler Construction F6S 12

13 Dangling-else: Grammar: (1) S I (2) S other (3) I if S (4) I if S else S DFA of LR(0) items on next slide 25 S'. S S. I S S' S. 1 S. other I. if S I S I. I. if S else S 2 0 other if I I S other. 3 other if I if. S I if. S else S S. I S. other I. if S I. if S else S 4 if I if S else. S S. I S. other I. if S I. if S else S 6 else S I if S. I if S. else S 5 other S I if S else S Compiler Construction F6S 13

14 The parsing table (with conflict): State Input Goto if else other $ S I 0 s4 s accept 2 r1 r1 3 r2 r2 4 s4 s s6/r3 r3 6 s4 s r4 r4 27 When Follow Sets Fail: S id V = E V id E V n But Yacc/Bison has no trouble with this grammar! state 0 id shift, and go to state 1 S go to state 8 V go to state 2 state 1 S -> id. (rule 1) V -> id. (rule 3) '=' reduce using rule 3 (V) $default reduce using rule 1 (S) Compiler Construction F6S 14

15 Notes on this example Legal strings are: { id, id=id, id=n } First(S) = First(V) = {id}, First(E) = {id, n} Follow(S) = Follow(E) = {$} Follow(V) = {$, id, =} There is a reduce-reduce SLR(1) conflict on $ in state 1 (Follow(S) and Follow(V) both contain $) 29 LALR(1) parsers add lookahead An LR(1) item has a look-ahead component: [ S.S, $] Begin with the above item, propagate look-ahead to closure items as follows: given item [ A α.bγ,a], add closure item [B.β, b] for all b in First(γa). 30 Compiler Construction F6S 15

16 The DFA for the example is then: [ S'. S, $ ] [ S.id, $ ] [ S. V = E, $ ] [ V.id, = ] V 0 S id [ S' S., $ ] 8 [ S id., $ ] [ V id., = ] 1 [ S V. = E, $ ] [ S V = E.,$ ] 2 := E [ S V =. E, $ ] [ E. V, $ ] [ E.n, $ ] [ V.id, $ ] 3 7 V n id [ E V., $ ] [ E n., $ ] [ V id., $ ] Definition of First Sets for Symbols (and ε): If X is a terminal or ε, then First(X) = {X}. If X is a non-terminal, then for each production choice X X 1 X 2...X n, First(X) contains First(X 1 ) {ε}. If also for some i < n, all of the sets First(X 1 ),..., First (X i ) contain ε, then First(X) contains First(X i+1 ) {ε}. If all of the sets First(X 1 ),..., First (X n ) contain ε then First(X) also contains ε. 32 Compiler Construction F6S 16

17 Definition of First Sets for Strings of Symbols: First (α) for any string α = X 1 X 2...X n (a string of terminals and non-terminals) is as follows. First(α) contains First(X 1 ) {ε}. For each i = 2,..., n, if First (X k ) contains ε for all k = 1,..., i 1, then First(α) contains First (X i ) {ε}. Finally, if for all i = 1,..., n, First (X i ) contains ε, then First(α) contains ε. 33 Example S A B z, A x ε, B y ε First(A) = { x, ε } First(B) = { y, ε } First(S) = { x, y, z, ε } First(ASw) = { x, y, z, w } 34 Compiler Construction F6S 17

18 Algorithm for Computing First Sets for Non-terminals: For all non-terminals A do First(A) := {}; while there are changes to any First(A) do for each production choice A X 1 X 2...X n do k := 1 ; Continue := true ; while Continue = true and k <= n do add First (X k ) {ε} to First(A); if ε is not in First (X k ) then Continue := false ; k := k + 1 ; if Continue = true then add ε to First(A) ; 35 Example of Algorithm Grammar Rule Pass 1 Pass 2 statement if-stmt First(statement) = {if, other} statement other First(statement) = {other} if-stmt if ( exp) statement else-part First(if-stmt) = {if} else-part else statement First(else-part) = {else} else-part ε First(else-part) = {else, ε} exp 0 First(exp) = {0} exp 1 First(exp) = {0, 1} 36 Compiler Construction F6S 18

19 Definition of Follow Sets for Non-terminals: Given a non-terminal A, the set Follow(A), consisting of terminals, and possibly $, is defined as follows. 1. If A is the start symbol, then $ is in Follow(A). 2. If there is a production B αa γ, then First(γ) {ε} is in Follow(A). 3. If there is a production B αa γ such that ε is in First(γ), then Follow(A) contains Follow(B). 37 Algorithm for Computing Follow Sets for Non-terminals: Follow (start-symbol) := {$} ; for all non-terminals A start-symbol do Follow (A) := {} ; while there are changes to any Follow sets do for each production A X 1 X 2... X n do for each X i that is a non-terminal do add First(X i+1 X i+2... X n ) {ε} to Follow (X i ) (* Note: if i=n, then X i+1 X i+2... X n = ε *) if ε is in First(X i+1 X i+2... X n ) then add Follow(A) to Follow (X i ) 38 Compiler Construction F6S 19

20 Example S A B z, A x ε, B y ε First(A) = { x, ε } First(B) = { y, ε } First(S) = { x, y, z, ε } First(ASw) = { x, y, z, w } Follow(S) = { $ } Follow(A) = { y, $ } Follow(B) = { $ } 39 A Second Example statement if-stmt other if-stmt if ( exp )statement else-part else-part else statement ε exp 0 First(statement) = {if, other} First(if-stmt) = {if} First(else-part) = {else, ε} First(exp) = {0, 1} Follow(statement) = {$,else} Follow(if-stmt) = {$,else} Follow(else-part) = {$,else} Follow(exp) = {)} 40 Compiler Construction F6S 20

S Y N T A X A N A L Y S I S LR

S 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 information

Principles of Programming Languages

Principles of Programming Languages Principles of Programming Languages h"p://www.di.unipi.it/~andrea/dida2ca/plp- 14/ Prof. Andrea Corradini Department of Computer Science, Pisa Lesson 8! Bo;om- Up Parsing Shi?- Reduce LR(0) automata and

More information

Monday, September 13, Parsers

Monday, September 13, Parsers Parsers Agenda Terminology LL(1) Parsers Overview of LR Parsing Terminology Grammar G = (Vt, Vn, S, P) Vt is the set of terminals Vn is the set of non-terminals S is the start symbol P is the set of productions

More information

Note that for recursive descent to work, if A ::= B1 B2 is a grammar rule we need First k (B1) disjoint from First k (B2).

Note that for recursive descent to work, if A ::= B1 B2 is a grammar rule we need First k (B1) disjoint from First k (B2). LL(k) Grammars We need a bunch of terminology. For any terminal string a we write First k (a) is the prefix of a of length k (or all of a if its length is less than k) For any string g of terminal and

More information

Parsing. Handle, viable prefix, items, closures, goto s LR(k): SLR(1), LR(1), LALR(1)

Parsing. Handle, viable prefix, items, closures, goto s LR(k): SLR(1), LR(1), LALR(1) TD parsing - LL(1) Parsing First and Follow sets Parse table construction BU Parsing Handle, viable prefix, items, closures, goto s LR(k): SLR(1), LR(1), LALR(1) Problems with SLR Aho, Sethi, Ullman, Compilers

More information

MIT Parse Table Construction. Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology

MIT 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 information

More Bottom-Up Parsing

More Bottom-Up Parsing More Bottom-Up Parsing Lecture 7 Dr. Sean Peisert ECS 142 Spring 2009 1 Status Project 1 Back By Wednesday (ish) savior lexer in ~cs142/s09/bin Project 2 Due Friday, Apr. 24, 11:55pm My office hours 3pm

More information

CSE302: Compiler Design

CSE302: Compiler Design CSE302: Compiler Design Instructor: Dr. Liang Cheng Department of Computer Science and Engineering P.C. Rossin College of Engineering & Applied Science Lehigh University March 20, 2007 Outline Recap LR(0)

More information

SYNTAX ANALYSIS 1. Define parser. Hierarchical analysis is one in which the tokens are grouped hierarchically into nested collections with collective meaning. Also termed as Parsing. 2. Mention the basic

More information

Let us construct the LR(1) items for the grammar given below to construct the LALR parsing table.

Let us construct the LR(1) items for the grammar given below to construct the LALR parsing table. MODULE 18 LALR parsing After understanding the most powerful CALR parser, in this module we will learn to construct the LALR parser. The CALR parser has a large set of items and hence the LALR parser is

More information

Bottom-Up Parsing. Lecture 11-12

Bottom-Up Parsing. Lecture 11-12 Bottom-Up Parsing Lecture 11-12 (From slides by G. Necula & R. Bodik) 2/20/08 Prof. Hilfinger CS164 Lecture 11 1 Administrivia Test I during class on 10 March. 2/20/08 Prof. Hilfinger CS164 Lecture 11

More information

Context-free grammars

Context-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 information

Parsers. Xiaokang Qiu Purdue University. August 31, 2018 ECE 468

Parsers. Xiaokang Qiu Purdue University. August 31, 2018 ECE 468 Parsers Xiaokang Qiu Purdue University ECE 468 August 31, 2018 What is a parser A parser has two jobs: 1) Determine whether a string (program) is valid (think: grammatically correct) 2) Determine the structure

More information

Conflicts in LR Parsing and More LR Parsing Types

Conflicts in LR Parsing and More LR Parsing Types Conflicts in LR Parsing and More LR Parsing Types Lecture 10 Dr. Sean Peisert ECS 142 Spring 2009 1 Status Project 2 Due Friday, Apr. 24, 11:55pm The usual lecture time is being replaced by a discussion

More information

Compiler Construction: Parsing

Compiler 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 information

Bottom 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. 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 information

Wednesday, September 9, 15. Parsers

Wednesday, September 9, 15. Parsers Parsers What is a parser A parser has two jobs: 1) Determine whether a string (program) is valid (think: grammatically correct) 2) Determine the structure of a program (think: diagramming a sentence) Agenda

More information

Parsers. What is a parser. Languages. Agenda. Terminology. Languages. A parser has two jobs:

Parsers. What is a parser. Languages. Agenda. Terminology. Languages. A parser has two jobs: What is a parser Parsers A parser has two jobs: 1) Determine whether a string (program) is valid (think: grammatically correct) 2) Determine the structure of a program (think: diagramming a sentence) Agenda

More information

Bottom-Up Parsing. Lecture 11-12

Bottom-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 information

UNIT III & IV. Bottom up parsing

UNIT III & IV. Bottom up parsing UNIT III & IV Bottom up parsing 5.0 Introduction Given a grammar and a sentence belonging to that grammar, if we have to show that the given sentence belongs to the given grammar, there are two methods.

More information

Wednesday, August 31, Parsers

Wednesday, August 31, Parsers Parsers How do we combine tokens? Combine tokens ( words in a language) to form programs ( sentences in a language) Not all combinations of tokens are correct programs (not all sentences are grammatically

More information

Example CFG. Lectures 16 & 17 Bottom-Up Parsing. LL(1) Predictor Table Review. Stacks in LR Parsing 1. Sʹ " S. 2. S " AyB. 3. A " ab. 4.

Example CFG. Lectures 16 & 17 Bottom-Up Parsing. LL(1) Predictor Table Review. Stacks in LR Parsing 1. Sʹ  S. 2. S  AyB. 3. A  ab. 4. Example CFG Lectures 16 & 17 Bottom-Up Parsing CS 241: Foundations of Sequential Programs Fall 2016 1. Sʹ " S 2. S " AyB 3. A " ab 4. A " cd Matt Crane University of Waterloo 5. B " z 6. B " wz 2 LL(1)

More information

Formal Languages and Compilers Lecture VII Part 4: Syntactic A

Formal Languages and Compilers Lecture VII Part 4: Syntactic A Formal Languages and Compilers Lecture VII Part 4: Syntactic Analysis Free University of Bozen-Bolzano Faculty of Computer Science POS Building, Room: 2.03 artale@inf.unibz.it http://www.inf.unibz.it/

More information

Parser Generation. Bottom-Up Parsing. Constructing LR Parser. LR Parsing. Construct parse tree bottom-up --- from leaves to the root

Parser Generation. Bottom-Up Parsing. Constructing LR Parser. LR Parsing. Construct parse tree bottom-up --- from leaves to the root Parser Generation Main Problem: given a grammar G, how to build a top-down parser or a bottom-up parser for it? parser : a program that, given a sentence, reconstructs a derivation for that sentence ----

More information

Formal Languages and Compilers Lecture VII Part 3: Syntactic A

Formal Languages and Compilers Lecture VII Part 3: Syntactic A Formal Languages and Compilers Lecture VII Part 3: Syntactic Analysis Free University of Bozen-Bolzano Faculty of Computer Science POS Building, Room: 2.03 artale@inf.unibz.it http://www.inf.unibz.it/

More information

Lecture 7: Deterministic Bottom-Up Parsing

Lecture 7: Deterministic Bottom-Up Parsing Lecture 7: Deterministic Bottom-Up Parsing (From slides by G. Necula & R. Bodik) Last modified: Tue Sep 20 12:50:42 2011 CS164: Lecture #7 1 Avoiding nondeterministic choice: LR We ve been looking at general

More information

shift-reduce parsing

shift-reduce parsing Parsing #2 Bottom-up Parsing Rightmost derivations; use of rules from right to left Uses a stack to push symbols the concatenation of the stack symbols with the rest of the input forms a valid bottom-up

More information

Bottom-Up Parsing LR Parsing

Bottom-Up Parsing LR Parsing Bottom-Up Parsing LR Parsing Maryam Siahbani 2/19/2016 1 What we need for LR parsing LR0) states: Describe all possible states in which parser can be Parsing table ransition between LR0) states Actions

More information

LR(0) Parsing Summary. LR(0) Parsing Table. LR(0) Limitations. A Non-LR(0) Grammar. LR(0) Parsing Table CS412/CS413

LR(0) Parsing Summary. LR(0) Parsing Table. LR(0) Limitations. A Non-LR(0) Grammar. LR(0) Parsing Table CS412/CS413 LR(0) Parsing ummary C412/C41 Introduction to Compilers Tim Teitelbaum Lecture 10: LR Parsing February 12, 2007 LR(0) item = a production with a dot in RH LR(0) state = set of LR(0) items valid for viable

More information

Parsing. Roadmap. > Context-free grammars > Derivations and precedence > Top-down parsing > Left-recursion > Look-ahead > Table-driven parsing

Parsing. Roadmap. > Context-free grammars > Derivations and precedence > Top-down parsing > Left-recursion > Look-ahead > Table-driven parsing Roadmap > Context-free grammars > Derivations and precedence > Top-down parsing > Left-recursion > Look-ahead > Table-driven parsing The role of the parser > performs context-free syntax analysis > guides

More information

Lecture 8: Deterministic Bottom-Up Parsing

Lecture 8: Deterministic Bottom-Up Parsing Lecture 8: Deterministic Bottom-Up Parsing (From slides by G. Necula & R. Bodik) Last modified: Fri Feb 12 13:02:57 2010 CS164: Lecture #8 1 Avoiding nondeterministic choice: LR We ve been looking at general

More information

Parsing. Lecture 11: Parsing. Recursive Descent Parser. Arithmetic grammar. - drops irrelevant details from parse tree

Parsing. Lecture 11: Parsing. Recursive Descent Parser. Arithmetic grammar. - drops irrelevant details from parse tree Parsing Lecture 11: Parsing CSC 131 Fall, 2014 Kim Bruce Build parse tree from an expression Interested in abstract syntax tree - drops irrelevant details from parse tree Arithmetic grammar ::=

More information

CS1622. Today. A Recursive Descent Parser. Preliminaries. Lecture 9 Parsing (4)

CS1622. Today. A Recursive Descent Parser. Preliminaries. Lecture 9 Parsing (4) CS1622 Lecture 9 Parsing (4) CS 1622 Lecture 9 1 Today Example of a recursive descent parser Predictive & LL(1) parsers Building parse tables CS 1622 Lecture 9 2 A Recursive Descent Parser. Preliminaries

More information

In One Slide. Outline. LR Parsing. Table Construction

In 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 information

CS 2210 Sample Midterm. 1. Determine if each of the following claims is true (T) or false (F).

CS 2210 Sample Midterm. 1. Determine if each of the following claims is true (T) or false (F). CS 2210 Sample Midterm 1. Determine if each of the following claims is true (T) or false (F). F A language consists of a set of strings, its grammar structure, and a set of operations. (Note: a language

More information

LR Parsing, Part 2. Constructing Parse Tables. An NFA Recognizing Viable Prefixes. Computing the Closure. GOTO Function and DFA States

LR 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 information

LR Parsing LALR Parser Generators

LR Parsing LALR Parser Generators LR Parsing LALR Parser Generators Outline Review of bottom-up parsing Computing the parsing DFA Using parser generators 2 Bottom-up Parsing (Review) A bottom-up parser rewrites the input string to the

More information

Lexical and Syntax Analysis. Bottom-Up Parsing

Lexical and Syntax Analysis. Bottom-Up Parsing Lexical and Syntax Analysis Bottom-Up Parsing Parsing There are two ways to construct derivation of a grammar. Top-Down: begin with start symbol; repeatedly replace an instance of a production s LHS with

More information

SLR parsers. LR(0) items

SLR parsers. LR(0) items SLR parsers LR(0) items As we have seen, in order to make shift-reduce parsing practical, we need a reasonable way to identify viable prefixes (and so, possible handles). Up to now, it has not been clear

More information

Parsing Wrapup. Roadmap (Where are we?) Last lecture Shift-reduce parser LR(1) parsing. This lecture LR(1) parsing

Parsing Wrapup. Roadmap (Where are we?) Last lecture Shift-reduce parser LR(1) parsing. This lecture LR(1) parsing Parsing Wrapup Roadmap (Where are we?) Last lecture Shift-reduce parser LR(1) parsing LR(1) items Computing closure Computing goto LR(1) canonical collection This lecture LR(1) parsing Building ACTION

More information

Principle of Compilers Lecture IV Part 4: Syntactic Analysis. Alessandro Artale

Principle of Compilers Lecture IV Part 4: Syntactic Analysis. Alessandro Artale Free University of Bolzano Principles of Compilers Lecture IV Part 4, 2003/2004 AArtale (1) Principle of Compilers Lecture IV Part 4: Syntactic Analysis Alessandro Artale Faculty of Computer Science Free

More information

Compilers. Bottom-up Parsing. (original slides by Sam

Compilers. Bottom-up Parsing. (original slides by Sam Compilers Bottom-up Parsing Yannis Smaragdakis U Athens Yannis Smaragdakis, U. Athens (original slides by Sam Guyer@Tufts) Bottom-Up Parsing More general than top-down parsing And just as efficient Builds

More information

LR Parsing LALR Parser Generators

LR Parsing LALR Parser Generators Outline LR Parsing LALR Parser Generators Review of bottom-up parsing Computing the parsing DFA Using parser generators 2 Bottom-up Parsing (Review) A bottom-up parser rewrites the input string to the

More information

Lecture Bottom-Up Parsing

Lecture Bottom-Up Parsing Lecture 14+15 Bottom-Up Parsing CS 241: Foundations of Sequential Programs Winter 2018 Troy Vasiga et al University of Waterloo 1 Example CFG 1. S S 2. S AyB 3. A ab 4. A cd 5. B z 6. B wz 2 Stacks in

More information

Lecture 14: Parser Conflicts, Using Ambiguity, Error Recovery. Last modified: Mon Feb 23 10:05: CS164: Lecture #14 1

Lecture 14: Parser Conflicts, Using Ambiguity, Error Recovery. Last modified: Mon Feb 23 10:05: CS164: Lecture #14 1 Lecture 14: Parser Conflicts, Using Ambiguity, Error Recovery Last modified: Mon Feb 23 10:05:56 2015 CS164: Lecture #14 1 Shift/Reduce Conflicts If a DFA state contains both [X: α aβ, b] and [Y: γ, a],

More information

3. Parsing. Oscar Nierstrasz

3. Parsing. Oscar Nierstrasz 3. Parsing Oscar Nierstrasz Thanks to Jens Palsberg and Tony Hosking for their kind permission to reuse and adapt the CS132 and CS502 lecture notes. http://www.cs.ucla.edu/~palsberg/ http://www.cs.purdue.edu/homes/hosking/

More information

CS502: Compilers & Programming Systems

CS502: Compilers & Programming Systems CS502: Compilers & Programming Systems Top-down Parsing Zhiyuan Li Department of Computer Science Purdue University, USA There exist two well-known schemes to construct deterministic top-down parsers:

More information

Top down vs. bottom up parsing

Top down vs. bottom up parsing Parsing A grammar describes the strings that are syntactically legal A recogniser simply accepts or rejects strings A generator produces sentences in the language described by the grammar A parser constructs

More information

Section A. A grammar that produces more than one parse tree for some sentences is said to be ambiguous.

Section A. A grammar that produces more than one parse tree for some sentences is said to be ambiguous. Section A 1. What do you meant by parser and its types? A parser for grammar G is a program that takes as input a string w and produces as output either a parse tree for w, if w is a sentence of G, or

More information

Syntactic Analysis. Chapter 4. Compiler Construction Syntactic Analysis 1

Syntactic Analysis. Chapter 4. Compiler Construction Syntactic Analysis 1 Syntactic Analysis Chapter 4 Compiler Construction Syntactic Analysis 1 Context-free Grammars The syntax of programming language constructs can be described by context-free grammars (CFGs) Relatively simple

More information

MODULE 14 SLR PARSER LR(0) ITEMS

MODULE 14 SLR PARSER LR(0) ITEMS MODULE 14 SLR PARSER LR(0) ITEMS In this module we shall discuss one of the LR type parser namely SLR parser. The various steps involved in the SLR parser will be discussed with a focus on the construction

More information

CS 4120 Introduction to Compilers

CS 4120 Introduction to Compilers CS 4120 Introduction to Compilers Andrew Myers Cornell University Lecture 6: Bottom-Up Parsing 9/9/09 Bottom-up parsing A more powerful parsing technology LR grammars -- more expressive than LL can handle

More information

PART 3 - SYNTAX ANALYSIS. F. Wotawa TU Graz) Compiler Construction Summer term / 309

PART 3 - SYNTAX ANALYSIS. F. Wotawa TU Graz) Compiler Construction Summer term / 309 PART 3 - SYNTAX ANALYSIS F. Wotawa (IST @ TU Graz) Compiler Construction Summer term 2016 64 / 309 Goals Definition of the syntax of a programming language using context free grammars Methods for parsing

More information

Syntax Analysis. Amitabha Sanyal. (www.cse.iitb.ac.in/ as) Department of Computer Science and Engineering, Indian Institute of Technology, Bombay

Syntax Analysis. Amitabha Sanyal. (www.cse.iitb.ac.in/ as) Department of Computer Science and Engineering, Indian Institute of Technology, Bombay Syntax Analysis (www.cse.iitb.ac.in/ as) Department of Computer Science and Engineering, Indian Institute of Technology, Bombay September 2007 College of Engineering, Pune Syntax Analysis: 2/124 Syntax

More information

CSC 4181 Compiler Construction. Parsing. Outline. Introduction

CSC 4181 Compiler Construction. Parsing. Outline. Introduction CC 4181 Compiler Construction Parsing 1 Outline Top-down v.s. Bottom-up Top-down parsing Recursive-descent parsing LL1) parsing LL1) parsing algorithm First and follow sets Constructing LL1) parsing table

More information

Compiler Design 1. Bottom-UP Parsing. Goutam Biswas. Lect 6

Compiler 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 information

Types of parsing. CMSC 430 Lecture 4, Page 1

Types of parsing. CMSC 430 Lecture 4, Page 1 Types of parsing Top-down parsers start at the root of derivation tree and fill in picks a production and tries to match the input may require backtracking some grammars are backtrack-free (predictive)

More information

Table-Driven Parsing

Table-Driven Parsing Table-Driven Parsing It is possible to build a non-recursive predictive parser by maintaining a stack explicitly, rather than implicitly via recursive calls [1] The non-recursive parser looks up the production

More information

3. Syntax Analysis. Andrea Polini. Formal Languages and Compilers Master in Computer Science University of Camerino

3. Syntax Analysis. Andrea Polini. Formal Languages and Compilers Master in Computer Science University of Camerino 3. Syntax Analysis Andrea Polini Formal Languages and Compilers Master in Computer Science University of Camerino (Formal Languages and Compilers) 3. Syntax Analysis CS@UNICAM 1 / 54 Syntax Analysis: the

More information

EDAN65: Compilers, Lecture 06 A LR parsing. Görel Hedin Revised:

EDAN65: Compilers, Lecture 06 A LR parsing. Görel Hedin Revised: EDAN65: Compilers, Lecture 06 A LR parsing Görel Hedin Revised: 2017-09-11 This lecture Regular expressions Context-free grammar Attribute grammar Lexical analyzer (scanner) Syntactic analyzer (parser)

More information

ECE 468/573 Midterm 1 October 1, 2014

ECE 468/573 Midterm 1 October 1, 2014 ECE 468/573 Midterm 1 October 1, 2014 Name: Purdue email: Please sign the following: I affirm that the answers given on this test are mine and mine alone. I did not receive help from any person or material

More information

Parser. Larissa von Witte. 11. Januar Institut für Softwaretechnik und Programmiersprachen. L. v. Witte 11. Januar /23

Parser. Larissa von Witte. 11. Januar Institut für Softwaretechnik und Programmiersprachen. L. v. Witte 11. Januar /23 Parser Larissa von Witte Institut für oftwaretechnik und Programmiersprachen 11. Januar 2016 L. v. Witte 11. Januar 2016 1/23 Contents Introduction Taxonomy Recursive Descent Parser hift Reduce Parser

More information

LALR Parsing. What Yacc and most compilers employ.

LALR Parsing. What Yacc and most compilers employ. LALR Parsing Canonical sets of LR(1) items Number of states much larger than in the SLR construction LR(1) = Order of thousands for a standard prog. Lang. SLR(1) = order of hundreds for a standard prog.

More information

Syntactic Analysis. Top-Down Parsing

Syntactic Analysis. Top-Down Parsing Syntactic Analysis Top-Down Parsing Copyright 2017, Pedro C. Diniz, all rights reserved. Students enrolled in Compilers class at University of Southern California (USC) have explicit permission to make

More information

Concepts Introduced in Chapter 4

Concepts Introduced in Chapter 4 Concepts Introduced in Chapter 4 Grammars Context-Free Grammars Derivations and Parse Trees Ambiguity, Precedence, and Associativity Top Down Parsing Recursive Descent, LL Bottom Up Parsing SLR, LR, LALR

More information

Acknowledgements. The slides for this lecture are a modified versions of the offering by Prof. Sanjeev K Aggarwal

Acknowledgements. The slides for this lecture are a modified versions of the offering by Prof. Sanjeev K Aggarwal Acknowledgements The slides for this lecture are a modified versions of the offering by Prof. Sanjeev K Aggarwal Syntax Analysis Check syntax and construct abstract syntax tree if == = ; b 0 a b Error

More information

UNIT-III BOTTOM-UP PARSING

UNIT-III BOTTOM-UP PARSING UNIT-III BOTTOM-UP PARSING Constructing a parse tree for an input string beginning at the leaves and going towards the root is called bottom-up parsing. A general type of bottom-up parser is a shift-reduce

More information

Bottom-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 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 information

LR Parsing. Table Construction

LR Parsing. Table Construction #1 LR Parsing Table Construction #2 Outline Review of bottom-up parsing Computing the parsing DFA Closures, LR(1) Items, States Transitions Using parser generators Handling Conflicts #3 In One Slide An

More information

Bottom-Up Parsing. Parser Generation. LR Parsing. Constructing LR Parser

Bottom-Up Parsing. Parser Generation. LR Parsing. Constructing LR Parser Parser Generation Main Problem: given a grammar G, how to build a top-down parser or a bottom-up parser for it? parser : a program that, given a sentence, reconstructs a derivation for that sentence ----

More information

CA Compiler Construction

CA Compiler Construction CA4003 - Compiler Construction David Sinclair A top-down parser starts with the root of the parse tree, labelled with the goal symbol of the grammar, and repeats the following steps until the fringe of

More information

CSE 401 Compilers. LR Parsing Hal Perkins Autumn /10/ Hal Perkins & UW CSE D-1

CSE 401 Compilers. LR Parsing Hal Perkins Autumn /10/ Hal Perkins & UW CSE D-1 CSE 401 Compilers LR Parsing Hal Perkins Autumn 2011 10/10/2011 2002-11 Hal Perkins & UW CSE D-1 Agenda LR Parsing Table-driven Parsers Parser States Shift-Reduce and Reduce-Reduce conflicts 10/10/2011

More information

CS143 Handout 20 Summer 2011 July 15 th, 2011 CS143 Practice Midterm and Solution

CS143 Handout 20 Summer 2011 July 15 th, 2011 CS143 Practice Midterm and Solution CS143 Handout 20 Summer 2011 July 15 th, 2011 CS143 Practice Midterm and Solution Exam Facts Format Wednesday, July 20 th from 11:00 a.m. 1:00 p.m. in Gates B01 The exam is designed to take roughly 90

More information

LR Parsing - The Items

LR Parsing - The Items LR Parsing - The Items Lecture 10 Sections 4.5, 4.7 Robb T. Koether Hampden-Sydney College Fri, Feb 13, 2015 Robb T. Koether (Hampden-Sydney College) LR Parsing - The Items Fri, Feb 13, 2015 1 / 31 1 LR

More information

A left-sentential form is a sentential form that occurs in the leftmost derivation of some sentence.

A 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 information

Compiler Construction Class Notes

Compiler Construction Class Notes Compiler Construction Class Notes Reg Dodds Department of Computer Science University of the Western Cape rdodds@uwc.ac.za c 2006,2017 Reg Dodds March 22, 2017 Introduction What is a Compiler? What is

More information

Syntax Analysis: Context-free Grammars, Pushdown Automata and Parsing Part - 4. Y.N. Srikant

Syntax Analysis: Context-free Grammars, Pushdown Automata and Parsing Part - 4. Y.N. Srikant Syntax Analysis: Context-free Grammars, Pushdown Automata and Part - 4 Department of Computer Science and Automation Indian Institute of Science Bangalore 560 012 NPTEL Course on Principles of Compiler

More information

LALR stands for look ahead left right. It is a technique for deciding when reductions have to be made in shift/reduce parsing. Often, it can make the

LALR stands for look ahead left right. It is a technique for deciding when reductions have to be made in shift/reduce parsing. Often, it can make the LALR parsing 1 LALR stands for look ahead left right. It is a technique for deciding when reductions have to be made in shift/reduce parsing. Often, it can make the decisions without using a look ahead.

More information

LR Parsing Techniques

LR Parsing Techniques LR Parsing Techniques Introduction Bottom-Up Parsing LR Parsing as Handle Pruning Shift-Reduce Parser LR(k) Parsing Model Parsing Table Construction: SLR, LR, LALR 1 Bottom-UP Parsing A bottom-up parser

More information

Syn S t yn a t x a Ana x lysi y s si 1

Syn S t yn a t x a Ana x lysi y s si 1 Syntax Analysis 1 Position of a Parser in the Compiler Model Source Program Lexical Analyzer Token, tokenval Get next token Parser and rest of front-end Intermediate representation Lexical error Syntax

More information

WWW.STUDENTSFOCUS.COM UNIT -3 SYNTAX ANALYSIS 3.1 ROLE OF THE PARSER Parser obtains a string of tokens from the lexical analyzer and verifies that it can be generated by the language for the source program.

More information

Top-Down Parsing and Intro to Bottom-Up Parsing. Lecture 7

Top-Down Parsing and Intro to Bottom-Up Parsing. Lecture 7 Top-Down Parsing and Intro to Bottom-Up Parsing Lecture 7 1 Predictive Parsers Like recursive-descent but parser can predict which production to use Predictive parsers are never wrong Always able to guess

More information

CS 314 Principles of Programming Languages

CS 314 Principles of Programming Languages CS 314 Principles of Programming Languages Lecture 5: Syntax Analysis (Parsing) Zheng (Eddy) Zhang Rutgers University January 31, 2018 Class Information Homework 1 is being graded now. The sample solution

More information

CSCI312 Principles of Programming Languages

CSCI312 Principles of Programming Languages Copyright 2006 The McGraw-Hill Companies, Inc. CSCI312 Principles of Programming Languages! LL Parsing!! Xu Liu Derived from Keith Cooper s COMP 412 at Rice University Recap Copyright 2006 The McGraw-Hill

More information

Compiler Construction 2016/2017 Syntax Analysis

Compiler 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 information

8 Parsing. Parsing. Top Down Parsing Methods. Parsing complexity. Top down vs. bottom up parsing. Top down vs. bottom up parsing

8 Parsing. Parsing. Top Down Parsing Methods. Parsing complexity. Top down vs. bottom up parsing. Top down vs. bottom up parsing 8 Parsing Parsing A grammar describes syntactically legal strings in a language A recogniser simply accepts or rejects strings A generator produces strings A parser constructs a parse tree for a string

More information

CSE P 501 Compilers. LR Parsing Hal Perkins Spring UW CSE P 501 Spring 2018 D-1

CSE P 501 Compilers. LR Parsing Hal Perkins Spring UW CSE P 501 Spring 2018 D-1 CSE P 501 Compilers LR Parsing Hal Perkins Spring 2018 UW CSE P 501 Spring 2018 D-1 Agenda LR Parsing Table-driven Parsers Parser States Shift-Reduce and Reduce-Reduce conflicts UW CSE P 501 Spring 2018

More information

Syntax Analyzer --- Parser

Syntax Analyzer --- Parser Syntax Analyzer --- Parser ASU Textbook Chapter 4.2--4.9 (w/o error handling) Tsan-sheng Hsu tshsu@iis.sinica.edu.tw http://www.iis.sinica.edu.tw/~tshsu 1 A program represented by a sequence of tokens

More information

4. Lexical and Syntax Analysis

4. Lexical and Syntax Analysis 4. Lexical and Syntax Analysis 4.1 Introduction Language implementation systems must analyze source code, regardless of the specific implementation approach Nearly all syntax analysis is based on a formal

More information

Bottom Up Parsing. Shift and Reduce. Sentential Form. Handle. Parse Tree. Bottom Up Parsing 9/26/2012. Also known as Shift-Reduce parsing

Bottom 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 information

Syntax Analysis. Martin Sulzmann. Martin Sulzmann Syntax Analysis 1 / 38

Syntax Analysis. Martin Sulzmann. Martin Sulzmann Syntax Analysis 1 / 38 Syntax Analysis Martin Sulzmann Martin Sulzmann Syntax Analysis 1 / 38 Syntax Analysis Objective Recognize individual tokens as sentences of a language (beyond regular languages). Example 1 (OK) Program

More information

VIVA QUESTIONS WITH ANSWERS

VIVA QUESTIONS WITH ANSWERS VIVA QUESTIONS WITH ANSWERS 1. What is a compiler? A compiler is a program that reads a program written in one language the source language and translates it into an equivalent program in another language-the

More information

Ambiguity, Precedence, Associativity & Top-Down Parsing. Lecture 9-10

Ambiguity, Precedence, Associativity & Top-Down Parsing. Lecture 9-10 Ambiguity, Precedence, Associativity & Top-Down Parsing Lecture 9-10 (From slides by G. Necula & R. Bodik) 9/18/06 Prof. Hilfinger CS164 Lecture 9 1 Administrivia Please let me know if there are continued

More information

Configuration Sets for CSX- Lite. Parser Action Table

Configuration Sets for CSX- Lite. Parser Action Table Configuration Sets for CSX- Lite State s 6 s 7 Cofiguration Set Prog { Stmts } Eof Stmts Stmt Stmts State s s Cofiguration Set Prog { Stmts } Eof Prog { Stmts } Eof Stmts Stmt Stmts Stmts λ Stmt if ( Expr

More information

Downloaded from Page 1. LR Parsing

Downloaded from  Page 1. LR Parsing Downloaded from http://himadri.cmsdu.org Page 1 LR Parsing We first understand Context Free Grammars. Consider the input string: x+2*y When scanned by a scanner, it produces the following stream of tokens:

More information

CS2210: Compiler Construction Syntax Analysis Syntax Analysis

CS2210: Compiler Construction Syntax Analysis Syntax Analysis Comparison with Lexical Analysis The second phase of compilation Phase Input Output Lexer string of characters string of tokens Parser string of tokens Parse tree/ast What Parse Tree? CS2210: Compiler

More information

4. Lexical and Syntax Analysis

4. Lexical and Syntax Analysis 4. Lexical and Syntax Analysis 4.1 Introduction Language implementation systems must analyze source code, regardless of the specific implementation approach Nearly all syntax analysis is based on a formal

More information

CS 164 Programming Languages and Compilers Handout 9. Midterm I Solution

CS 164 Programming Languages and Compilers Handout 9. Midterm I Solution Midterm I Solution Please read all instructions (including these) carefully. There are 5 questions on the exam, some with multiple parts. You have 1 hour and 20 minutes to work on the exam. The exam is

More information

CSE 130 Programming Language Principles & Paradigms Lecture # 5. Chapter 4 Lexical and Syntax Analysis

CSE 130 Programming Language Principles & Paradigms Lecture # 5. Chapter 4 Lexical and Syntax Analysis Chapter 4 Lexical and Syntax Analysis Introduction - Language implementation systems must analyze source code, regardless of the specific implementation approach - Nearly all syntax analysis is based on

More information

Top-Down Parsing and Intro to Bottom-Up Parsing. Lecture 7

Top-Down Parsing and Intro to Bottom-Up Parsing. Lecture 7 Top-Down Parsing and Intro to Bottom-Up Parsing Lecture 7 1 Predictive Parsers Like recursive-descent but parser can predict which production to use Predictive parsers are never wrong Always able to guess

More information