Readahead FSMs, Readback FSMs, and Reduce States

Slides:



Advertisements
Similar presentations
Parsing V: Bottom-up Parsing
Advertisements

Compiler Construction
A question from last class: construct the predictive parsing table for this grammar: S->i E t S e S | i E t S | a E -> B.
Lesson 8 CDT301 – Compiler Theory, Spring 2011 Teacher: Linus Källberg.
 CS /11/12 Matthew Rodgers.  What are LL and LR parsers?  What grammars do they parse?  What is the difference between LL and LR?  Why do.
Bottom up Parsing Bottom up parsing trys to transform the input string into the start symbol. Moves through a sequence of sentential forms (sequence of.
6/12/2015Prof. Hilfinger CS164 Lecture 111 Bottom-Up Parsing Lecture (From slides by G. Necula & R. Bodik)
Top-Down Parsing.
CS Summer 2005 Top-down and Bottom-up Parsing - a whirlwind tour June 20, 2005 Slide acknowledgment: Radu Rugina, CS 412.
1 Foundations of Software Design Lecture 23: Finite Automata and Context-Free Grammars Marti Hearst Fall 2002.
Prof. Fateman CS 164 Lecture 91 Bottom-Up Parsing Lecture 9.
Professor Yihjia Tsai Tamkang University
Top-Down Parsing.
1 CIS 461 Compiler Design & Construction Fall 2012 slides derived from Tevfik Bultan, Keith Cooper, and Linda Torczon Lecture-Module #12 Parsing 4.
1 Bottom-up parsing Goal of parser : build a derivation –top-down parser : build a derivation by working from the start symbol towards the input. builds.
Bottom-up parsing Goal of parser : build a derivation
Parsing IV Bottom-up Parsing Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University.
Syntax and Semantics Structure of programming languages.
410/510 1 of 21 Week 2 – Lecture 1 Bottom Up (Shift reduce, LR parsing) SLR, LR(0) parsing SLR parsing table Compiler Construction.
Top-Down Parsing - recursive descent - predictive parsing
10/13/2015IT 3271 Tow kinds of predictive parsers: Bottom-Up: The syntax tree is built up from the leaves Example: LR(1) parser Top-Down The syntax tree.
Profs. Necula CS 164 Lecture Top-Down Parsing ICOM 4036 Lecture 5.
CMSC 331, Some material © 1998 by Addison Wesley Longman, Inc. 1 Chapter 4 Chapter 4 Bottom Up Parsing.
Syntax and Semantics Structure of programming languages.
Bottom-Up Parsing David Woolbright. The Parsing Problem Produce a parse tree starting at the leaves The order will be that of a rightmost derivation The.
Top-Down Parsing.
Parsing and Code Generation Set 24. Parser Construction Most of the work involved in constructing a parser is carried out automatically by a program,
GRAMMARS & PARSING. Parser Construction Most of the work involved in constructing a parser is carried out automatically by a program, referred to as a.
CS 330 Programming Languages 09 / 25 / 2007 Instructor: Michael Eckmann.
Bottom Up Parsing CS 671 January 31, CS 671 – Spring Where Are We? Finished Top-Down Parsing Starting Bottom-Up Parsing Lexical Analysis.
COMP 3438 – Part II-Lecture 6 Syntax Analysis III Dr. Zili Shao Department of Computing The Hong Kong Polytechnic Univ.
Bottom-Up Parsing Algorithms LR(k) parsing L: scan input Left to right R: produce Rightmost derivation k tokens of lookahead LR(0) zero tokens of look-ahead.
Syntax and Semantics Structure of programming languages.
Error recovery in predictive parsing An error is detected during the predictive parsing when the terminal on top of the stack does not match the next input.
Parsing #1 Leonidas Fegaras.
Parsing Bottom Up CMPS 450 J. Moloney CMPS 450.
Programming Languages Translator
Bottom-up parsing Goal of parser : build a derivation
Compiler design Bottom-up parsing Concepts
Parsing and Parser Parsing methods: top-down & bottom-up
Unit-3 Bottom-Up-Parsing.
UNIT - 3 SYNTAX ANALYSIS - II
Parsing IV Bottom-up Parsing
Table-driven parsing Parsing performed by a finite state machine.
Syntax Analysis Part II
4 (c) parsing.
Subject Name:COMPILER DESIGN Subject Code:10CS63
4d Bottom Up Parsing.
Parsing #2 Leonidas Fegaras.
BOTTOM UP PARSING Lecture 16.
Lecture 8 Bottom Up Parsing
Bottom Up Parsing.
Parsing IV Bottom-up Parsing
LR Parsing. Parser Generators.
Parsing #2 Leonidas Fegaras.
Syntax Analysis - Parsing
4d Bottom Up Parsing.
Kanat Bolazar February 16, 2010
Parsing Bottom-Up.
4d Bottom Up Parsing.
4d Bottom Up Parsing.
4d Bottom Up Parsing.
4d Bottom Up Parsing.
Finishing Tool Construction
Building Readahead FSMs for Grammars
Building Readback FSMs for Readahead FSMs
COMPILER CONSTRUCTION
Scanners/Parsers in a Nutshell
Overview of the Course.
Parsing CSCI 432 Computer Science Theory
Presentation transcript:

Readahead FSMs, Readback FSMs, and Reduce States 95.3002 Readahead FSMs, Readback FSMs, and Reduce States

How does a Parser Work Again! Find the right end of a handle (while munching inputs, stacking stuff (3 stacks that grow on the right), and moving R (indicator for the right end of a handle)) Find the left end of a handle (while traversing the stack from right to left and moving L) Reduce to a nonterminal A (using the stack contents between L and R, build a new tree and replace everything by an A-token) and repeat until no more input (EndOfFile encountered); equivalent to reaching an accept table.

The Process ReadaheadFSM ReadbackFSM Reduce to A {lookahead} Computed from Follow (A); i.e., what comes after ReadaheadFSM Build and stacks input from left to right Stops when it reaches the right end of a unique handle with R pointing at the rightmost stack entry {lookback} ReadbackFSM Computed from ReadaheadFSM; i.e., what comes before Scans stack from right to left Stops when it reaches the left end of a unique handle with L pointing at the leftmost stack entry Reduce to A Build a tree from information between L and R, pops it off, and replaces it by A and the new tree The lookahead and lookback is used as a bridge to interconnect different parts The process keeps repeating

Example -1 -1 G {EndOfFile}-> a b c d Acc grammar 12 G Ra Ra Ra Ra Readahead FSM 1 2 3 4 5 Rb Rb Rb Rb Rb {-1} a2 b3 c4 d5 Readback FSM 10 9 8 7 6 Red G 11 bridging lookahead bridging lookback Some initial entry -1 How the stack grows during readahead a2 c4 Left initially past right b3 d5 R L How left moves during readback L -1 How stack (generally) shrinks by the reduce G12

Parsing Versus Derivations grammar G {EndOfFile}-> a b c d Input a b c d EndOfFile As we saw on the previous slide, the stack changes as follows This corresponds to the derivation -1 G => abcd a2 b3 c4 d5 -1 G2 So the parser works in the reverse order of a derivation. More specifically, from left-to-right and bottom-up, simulating a specific type of derivation (but we can’t show that here since the example is too simple)

What Precisely Is The Stack Information -1 Stack as shown on previous slide a2 b3 c4 d5 In reality, these are 2 parallel stacks. Token stack - a b c d Table number stack 1 2 3 4 5 They grow on the right Also, there exists a 3rd parallel stack. Tree stack Each entry is an entire tree (not a node in the tree), This is easy to do with object-oriented programming

Bridging G {EndOfFile}-> a b c d Acc grammar 12 G Ra Ra Ra Ra Ra a Readahead FSM 1 2 3 4 5 Rb Rb Rb Rb Rb {-1} a2 b3 c4 d5 Readback FSM 10 9 8 7 6 Red A 11 bridging lookahead bridging lookback Computing lookahead: For each nonterminal A, we need to compute Follow (A); i.e., what can come after “according to the grammar”. Computing lookback: Computed from the information in the readahead FSM.

What Order Do We Implement Things Standard order Compute Follow Sets 1 week to do Build readahead and readback FSMs 2 week sto do What we might want to do instead Switch the order So we have to pretend we have the follows sets What if we don’t Takes a long time to explain latter, could waste a week of assignment time.