CS 44 – Jan. 28 Pumping lemma #2 Applications to compiling.

Slides:



Advertisements
Similar presentations
Translator Architecture Code Generator ParserTokenizer string of characters (source code) string of tokens abstract program string of integers (object.
Advertisements

1 Parsing The scanner recognizes words The parser recognizes syntactic units Parser operations: Check and verify syntax based on specified syntax rules.
Chap. 5, Top-Down Parsing J. H. Wang Mar. 29, 2011.
CSE 3302 Programming Languages Chengkai Li, Weimin He Spring 2008 Syntax Lecture 2 - Syntax, Spring CSE3302 Programming Languages, UT-Arlington ©Chengkai.
Context-Free Grammars Lecture 7
1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 5: Syntax Analysis COMP 144 Programming Language Concepts Spring 2002 Felix Hernandez-Campos.
Prof. Bodik CS 164 Lecture 61 Building a Parser II CS164 3:30-5:00 TT 10 Evans.
Chapter 2 A Simple Compiler
Compiler Construction CS 606 Sohail Aslam Lecture 2.
CPSC 388 – Compiler Design and Construction Parsers – Context Free Grammars.
Syntax Analysis (Chapter 4) 1 Course Overview PART I: overview material 1Introduction 2Language processors (tombstone diagrams, bootstrapping) 3Architecture.
BİL 744 Derleyici Gerçekleştirimi (Compiler Design)1 Syntax Analyzer Syntax Analyzer creates the syntactic structure of the given source program. This.
CISC 471 First Exam Review Game Questions. Overview 1 Draw the standard phases of a compiler for compiling a high level language to machine code, showing.
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.
Introduction to Parsing Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University.
CS 461 – Oct. 7 Applications of CFLs: Compiling Scanning vs. parsing Expression grammars –Associativity –Precedence Programming language (handout)
Lesson 3 CDT301 – Compiler Theory, Spring 2011 Teacher: Linus Källberg.
Review 1.Lexical Analysis 2.Syntax Analysis 3.Semantic Analysis 4.Code Generation 5.Code Optimization.
CS 461 – Sept. 19 Last word on finite automata… –Scanning tokens in a compiler –How do we implement a “state” ? Chapter 2 introduces the 2 nd model of.
Bernd Fischer RW713: Compiler and Software Language Engineering.
Comp 311 Principles of Programming Languages Lecture 3 Parsing Corky Cartwright August 28, 2009.
Cs3102: Theory of Computation Class 8: Non-Context-Free Languages Spring 2010 University of Virginia David Evans.
CS412/413 Introduction to Compilers and Translators Spring ’99 Lecture 3: Introduction to Syntactic Analysis.
. n COMPILERS n n AND n n INTERPRETERS. -Compilers nA compiler is a program thatt reads a program written in one language - the source language- and translates.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 4.
Chapter 3 Context-Free Grammars and Parsing. The Parsing Process sequence of tokens syntax tree parser Duties of parser: Determine correct syntax Build.
Syntax Analysis - Parsing Compiler Design Lecture (01/28/98) Computer Science Rensselaer Polytechnic.
Grammars Hopcroft, Motawi, Ullman, Chap 5. Grammars Describes underlying rules (syntax) of programming languages Compilers (parsers) are based on such.
Grammars CS 130: Theory of Computation HMU textbook, Chap 5.
Syntax Analyzer (Parser)
LECTURE 4 Syntax. SPECIFYING SYNTAX Programming languages must be very well defined – there’s no room for ambiguity. Language designers must use formal.
LECTURE 7 Lex and Intro to Parsing. LEX Last lecture, we learned a little bit about how we can take our regular expressions (which specify our valid tokens)
CSCI 3130: Formal languages and automata theory Andrej Bogdanov The Chinese University of Hong Kong Limitations.
CSC 4181 Compiler Construction
Lecture # 10 Grammar Problems. Problems with grammar Ambiguity Left Recursion Left Factoring Removal of Useless Symbols These can create problems for.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 3.
 2004 SDU Lecture8 NON-Context-free languages.  2004 SDU 2 Are all languages context free? Ans: No. # of PDAs on  < # of languages on  Pumping lemma:
CSE 311 Foundations of Computing I Lecture 18 Recursive Definitions: Context-Free Grammars and Languages Autumn 2011 CSE 3111.
CS 461 – Oct. 5 Pumping lemma #2 –Understanding –Use to show a language is not a CFL Next: Applications of CFLs –Expression grammars and Compiling.
Syntax Analysis By Noor Dhia Syntax analysis:- Syntax analysis or parsing is the most important phase of a compiler. The syntax analyzer considers.
Introduction to Parsing
Chapter 3 – Describing Syntax
A Simple Syntax-Directed Translator
Introduction to Parsing
CS 326 Programming Languages, Concepts and Implementation
Parsing and Parser Parsing methods: top-down & bottom-up
Introduction to Parsing (adapted from CS 164 at Berkeley)
Syntax Analysis Chapter 4.
PROGRAMMING LANGUAGES
Parsing with Context Free Grammars
Syntax Analysis Sections :.
Parsing Techniques.
CSE 3302 Programming Languages
Basic Program Analysis: AST
Compiler Design 4. Language Grammars
CPSC 388 – Compiler Design and Construction
Syntax-Directed Definition
Programming Language Syntax 2
ENERGY 211 / CME 211 Lecture 15 October 22, 2008.
Chapter 2: A Simple One Pass Compiler
Lecture 7: Introduction to Parsing (Syntax Analysis)
Programming Languages
CSC 4181Compiler Construction Context-Free Grammars
R.Rajkumar Asst.Professor CSE
Introduction to Parsing
Introduction to Parsing
CS 461 – Sept. 16 Review Pumping lemma Applications of FA:
CSC 4181 Compiler Construction Context-Free Grammars
Limitations of pushdown automata
Limitations of context-free languages
Presentation transcript:

CS 44 – Jan. 28 Pumping lemma #2 Applications to compiling

Adversary’s Revenge In Game #1, how did we win? Ex. { 0 n 1 n }. –Adversary chose p. –We chose s. –Adversary broke up s = xyz subject to constraints. –We were always able to pump and find words outside L. Game #2 strategy –Adversary’s constraints looser. The middle 3 parts have to be within p of each other. Can be anywhere in the string, not just in first p symbols of word.

{ 1 n 2 n 3 n } Let p be any number. Choose s = 1 p 2 p 3 p. Let s = uvxyz such that |vxy| = 1. Where can v and y be? –All 1’s –All 2’s –All 3’s –Straddling 1’s and 2’s –Straddling 2’s and 3’s In every case, can we find a word not in L?

More examples { 1 i 2 j 3 k : i < j < k } –What should we chose as s? –How can the word be split up? { w w } –Let s = 0 p 1 p 0 p 1 p. Where can v & y be? –Same section of 0’s and 1’s. –In neighboring sections –Either v or y straddles a border.

Compiling Grammars are used to define programming language and check syntax. Phases of a compiler source code scanner stream of tokens parser parse tree

Scanning Scanner needs to know what to expect when eating your program. –identifiers –numbers –strings –comments Specifications for tokens can be expressed by regular expression (or regular grammar). While, scanning, we can be in different states, such as inside a comment.

Parser Purpose is to understand structure of program. All programming structures can be expressed as CFG. Simple example for + and – expr  expr + digit | expr – digit | digit digit  0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 How would we derive the string 9 – ?

9 – expr  expr + digit | expr – digit | digit digit  0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 expr expr +digit expr - digit 2 digit 5 9 Leftmost derivation: expr  expr + digit  expr – digit + digit  digit – digit + digit  9 – digit + digit  9 – 5 + digit  9 – “parse tree”

Left & right recursion What is the difference between these 2 grammars? Which one is better? expr  expr + digit | expr – digit | digit digit  0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 expr  digit + expr | digit – expr | digit digit  0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 Let’s try 9 – on both of these. The grammar must convey the order of operations! Operators may be left associative or right associative.

+ - * / Question: How do we write grammar for all 4 operators? Can we do it this way… expr  expr + digit | expr – digit | expr * digit | expr / digit digit digit  0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 BTW, we can ignore “digits” and from now on just replace them with “num”, and understand it’s any single number.