Context-Free Grammars

Similar documents
Context-Free Grammars

Context-Free Grammars

Context-Free Grammars

Fig.25: the Role of LEX

Context-Free Grammars

Dr. D.M. Akbar Hussain

ASTs, Regex, Parsing, and Pretty Printing

Definition of Regular Expression

CS 430 Spring Mike Lam, Professor. Parsing

CSCI 3130: Formal Languages and Automata Theory Lecture 12 The Chinese University of Hong Kong, Fall 2011

CS321 Languages and Compiler Design I. Winter 2012 Lecture 5

CS 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.

CS143 Handout 07 Summer 2011 June 24 th, 2011 Written Set 1: Lexical Analysis

COMP 423 lecture 11 Jan. 28, 2008

Homework. Context Free Languages III. Languages. Plan for today. Context Free Languages. CFLs and Regular Languages. Homework #5 (due 10/22)

In the last lecture, we discussed how valid tokens may be specified by regular expressions.

CS 432 Fall Mike Lam, Professor a (bc)* Regular Expressions and Finite Automata

this grammar generates the following language: Because this symbol will also be used in a later step, it receives the

Compilers Spring 2013 PRACTICE Midterm Exam

CMPSC 470: Compiler Construction

CS 340, Fall 2016 Sep 29th Exam 1 Note: in all questions, the special symbol ɛ (epsilon) is used to indicate the empty string.

Languages. L((a (b)(c))*) = { ε,a,bc,aa,abc,bca,... } εw = wε = w. εabba = abbaε = abba. (a (b)(c)) *

ΕΠΛ323 - Θεωρία και Πρακτική Μεταγλωττιστών

ECE 468/573 Midterm 1 September 28, 2012

Lecture 10 Evolutionary Computation: Evolution strategies and genetic programming

Tries. Yufei Tao KAIST. April 9, Y. Tao, April 9, 2013 Tries

Context-Free Grammars

LING/C SC/PSYC 438/538. Lecture 21 Sandiway Fong

Quiz2 45mins. Personal Number: Problem 1. (20pts) Here is an Table of Perl Regular Ex

Some Thoughts on Grad School. Undergraduate Compilers Review and Intro to MJC. Structure of a Typical Compiler. Lexing and Parsing

Midterm I Solutions CS164, Spring 2006

Operator Precedence. Java CUP. E E + T T T * P P P id id id. Does a+b*c mean (a+b)*c or

Topic 2: Lexing and Flexing

Today. CS 188: Artificial Intelligence Fall Recap: Search. Example: Pancake Problem. Example: Pancake Problem. General Tree Search.

CSCE 531, Spring 2017, Midterm Exam Answer Key

CS 236 Language and Computation. Alphabet. Definition. I.2.1. Formal Languages (10.1)

Reducing a DFA to a Minimal DFA

Unit #9 : Definite Integral Properties, Fundamental Theorem of Calculus

Lexical Analysis. Amitabha Sanyal. ( as) Department of Computer Science and Engineering, Indian Institute of Technology, Bombay

CSE 401 Midterm Exam 11/5/10 Sample Solution

Deterministic. Finite Automata. And Regular Languages. Fall 2018 Costas Busch - RPI 1

ΕΠΛ323 - Θεωρία και Πρακτική Μεταγλωττιστών. Lecture 3b Lexical Analysis Elias Athanasopoulos

CS412/413. Introduction to Compilers Tim Teitelbaum. Lecture 4: Lexical Analyzers 28 Jan 08

Announcements. CS 188: Artificial Intelligence Fall Recap: Search. Today. Example: Pancake Problem. Example: Pancake Problem

10.5 Graphing Quadratic Functions

Compiler Construction D7011E

CSc 453. Compilers and Systems Software. 4 : Lexical Analysis II. Department of Computer Science University of Arizona

TO REGULAR EXPRESSIONS

Java CUP. Java CUP Specifications. User Code Additions. Package and Import Specifications

Implementing Automata. CSc 453. Compilers and Systems Software. 4 : Lexical Analysis II. Department of Computer Science University of Arizona

Theory of Computation CSE 105

Lexical Analysis: Constructing a Scanner from Regular Expressions

Should 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

10/12/17. Motivating Example. Lexical and Syntax Analysis (2) Recursive-Descent Parsing. Recursive-Descent Parsing. Recursive-Descent Parsing

CMSC 331 First Midterm Exam

Midterm 2 Sample solution

George Boole. IT 3123 Hardware and Software Concepts. Switching Algebra. Boolean Functions. Boolean Functions. Truth Tables

UNIVERSITY OF EDINBURGH COLLEGE OF SCIENCE AND ENGINEERING SCHOOL OF INFORMATICS INFORMATICS 1 COMPUTATION & LOGIC INSTRUCTIONS TO CANDIDATES

CS 241 Week 4 Tutorial Solutions

If you are at the university, either physically or via the VPN, you can download the chapters of this book as PDFs.

Lexical analysis, scanners. Construction of a scanner

LR Parsing, Part 2. Constructing Parse Tables. Need to Automatically Construct LR Parse Tables: Action and GOTO Table

Top-down vs Bottom-up. Bottom up parsing. Sentential form. Handles. Handles in expression example

Announcements. CS 188: Artificial Intelligence Fall Recap: Search. Today. General Tree Search. Uniform Cost. Lecture 3: A* Search 9/4/2007

Introduction to Integration

Simplifying Algebra. Simplifying Algebra. Curriculum Ready.

2 Computing all Intersections of a Set of Segments Line Segment Intersection

CS 321 Programming Languages and Compilers. Bottom Up Parsing

CS311H: Discrete Mathematics. Graph Theory IV. A Non-planar Graph. Regions of a Planar Graph. Euler s Formula. Instructor: Işıl Dillig

Section 10.4 Hyperbolas

Patterns and Algebra. My name. Series

Systems I. Logic Design I. Topics Digital logic Logic gates Simple combinational logic circuits

Solving Problems by Searching. CS 486/686: Introduction to Artificial Intelligence Winter 2016

12 <= rm <digit> 2 <= rm <no> 2 <= rm <no> <digit> <= rm <no> <= rm <number>

Lecture 7: Integration Techniques

Lecture T1: Pattern Matching

CS 241. Fall 2017 Midterm Review Solutions. October 24, Bits and Bytes 1. 3 MIPS Assembler 6. 4 Regular Languages 7.

AI Adjacent Fields. This slide deck courtesy of Dan Klein at UC Berkeley

Section 3.1: Sequences and Series

Finite Automata. Lecture 4 Sections Robb T. Koether. Hampden-Sydney College. Wed, Jan 21, 2015

INTRODUCTION TO SIMPLICIAL COMPLEXES

Information Retrieval and Organisation

Algorithm Design (5) Text Search

What are suffix trees?

MTH 146 Conics Supplement

From Dependencies to Evaluation Strategies

Eliminating left recursion grammar transformation. The transformed expression grammar

The Math Learning Center PO Box 12929, Salem, Oregon Math Learning Center

Regular Expressions and Automata using Miranda

Stack Manipulation. Other Issues. How about larger constants? Frame Pointer. PowerPC. Alternative Architectures

SERIES. Patterns and Algebra OUT. Name

Assignment 4. Due 09/18/17

Uninformed Search. Hal Daumé III. Computer Science University of Maryland CS 421: Introduction to Artificial Intelligence 31 Jan 2012

Scanner Termination. Multi Character Lookahead. to its physical end. Most parsers require an end of file token. Lex and Jlex automatically create an

How to Design REST API? Written Date : March 23, 2015

CS481: Bioinformatics Algorithms

Sample Midterm Solutions COMS W4115 Programming Languages and Translators Monday, October 12, 2009

Problem Set 2 Fall 16 Due: Wednesday, September 21th, in class, before class begins.

Solving Problems by Searching. CS 486/686: Introduction to Artificial Intelligence

Example: 2:1 Multiplexer

Transcription:

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. Finite utomt recognize strings in the lnguge. Perform computtion to determine whether specifc string is in the lnguge. Regulr expressions mtch strings in the lnguge. Descrie the generl shpe of ll strings in the lnguge.

Context-Free Grmmrs A context-free grmmr (or CFG) is n entirely diferent formlism for defning clss of lnguges. Gol: Give description of lnguge y recursively descriing the structure of the strings in the lnguge. CFGs re est explined y exmple...

Arithmetic Expressions Suppose we wnt to descrie ll legl rithmetic expressions using ddition, sutrction, multipliction, nd division. Here is one possile CFG: E int E E Op E E (E) Op + Op - Op * Op / E E Op E E Op (E) E Op (E Op E) E * (E Op E) int * (E Op E) int * (int Op E) int * (int Op int) int * (int + int)

Arithmetic Expressions Suppose we wnt to descrie ll legl rithmetic expressions using ddition, sutrction, multipliction, nd division. Here is one possile CFG: E int E E Op E E (E) Op + Op - Op * Op / E E Op E E Op int int Op int int / int

Context-Free Grmmrs Formlly, context-free grmmr is collection of four items: A set of nonterminl symols (lso clled vriles), A set of terminl symols (the lphet of the CFG) A set of production rules sying how ech nonterminl cn e replced y string of terminls nd nonterminls, nd A strt symol (which must e nonterminl) tht egins the derivtion. E int E E Op E E (E) Op + Op - Op * Op /

Context-Free Grmmrs Formlly, context-free grmmr is collection of four items: A set of nonterminl symols (lso clled vriles), A set of terminl symols (the lphet of the CFG) A set of production rules sying how ech nonterminl cn e replced y string of terminls nd nonterminls, nd A strt symol (which must e nonterminl) tht egins the derivtion. E int E E Op E E (E) Op + Op - Op * Op /

Some CFG Nottion In tody s slides, cpitl letters in Bold Red Uppercse will represent nonterminls. e.g. A, B, C, D Lowercse letters in lue monospce will represent terminls. e.g. t, u, v, w Lowercse Greek letters in gry itlics will represent ritrry strings of terminls nd nonterminls. e.g. α, γ, ω You don't need to use these conventions on your own; just mke sure whtever you do is redle.

A Nottionl Shorthnd E int E E Op E E (E) Op + Op - Op * Op /

A Nottionl Shorthnd E int E Op E (E) Op + - * /

Derivtions E E Op E int (E) Op + * - / E E Op E E Op (E) E Op (E Op E) E * (E Op E) int * (E Op E) int * (int Op E) int * (int Op int) int * (int + int) A sequence of steps where nonterminls re replced y the right-hnd side of production is clled derivtion. If string α derives string ω, we write α * ω. In the exmple on the left, we see E * int * (int + int).

The Lnguge of Grmmr If G is CFG with lphet Σ nd strt symol S, then the lnguge of G is the set L(G) = { ω Σ* S * ω } Tht is, ( L G) is the set of strings of terminls derivle from the strt symol.

If If G is is CFG CFG with with lphet lphet Σ nd nd strt strt symol symol S, S, then then the the lnguge of of G is is the the set set L(G) L(G) = { ω Σ* Σ* S * * ω } Consider the the following CFG CFG G over over Σ = {, {,,, c, c, d}: d}: S S S dt dt T T T c How How mny mny of of the the following strings re re in in L (( G)? G)? dc dc cd cd c c dt Answer Answer t t PollEv.com/cs103 PollEv.com/cs103 or or text text CS103 CS103 to to 22333 22333 once once to to join, join, then then numer. numer.

Context-Free Lnguges A lnguge L is clled context-free lnguge (or CFL) if there is CFG G such tht L = L( G). Questions: Wht lnguges re context-free? How re context-free nd regulr lnguges relted?

From Regexes to CFGs CFGs consist purely of production rules of the form A ω. They do not hve the regulr expression opertors * or. However, we cn convert regulr expressions to CFGs s follows: S *

From Regexes to CFGs CFGs consist purely of production rules of the form A ω. They do not hve the regulr expression opertors * or. However, we cn convert regulr expressions to CFGs s follows: S *

From Regexes to CFGs CFGs consist purely of production rules of the form A ω. They do not hve the regulr expression opertors * or. However, we cn convert regulr expressions to CFGs s follows: S * A A ε

From Regexes to CFGs CFGs consist purely of production rules of the form A ω. They do not hve the regulr expression opertors * or. However, we cn convert regulr expressions to CFGs s follows: S * A A ε

From Regexes to CFGs CFGs consist purely of production rules of the form A ω. They do not hve the regulr expression opertors * or. However, we cn convert regulr expressions to CFGs s follows: S A A A ε

From Regexes to CFGs CFGs consist purely of production rules of the form A ω. They do not hve the regulr expression opertors * or. However, we cn convert regulr expressions to CFGs s follows: S ( c*)

From Regexes to CFGs CFGs consist purely of production rules of the form A ω. They do not hve the regulr expression opertors * or. However, we cn convert regulr expressions to CFGs s follows: S ( c*)

From Regexes to CFGs CFGs consist purely of production rules of the form A ω. They do not hve the regulr expression opertors * or. However, we cn convert regulr expressions to CFGs s follows: S ( c*) X c*

From Regexes to CFGs CFGs consist purely of production rules of the form A ω. They do not hve the regulr expression opertors * or. However, we cn convert regulr expressions to CFGs s follows: S ( c*) X c*

From Regexes to CFGs CFGs consist purely of production rules of the form A ω. They do not hve the regulr expression opertors * or. However, we cn convert regulr expressions to CFGs s follows: S X X c*

From Regexes to CFGs CFGs consist purely of production rules of the form A ω. They do not hve the regulr expression opertors * or. However, we cn convert regulr expressions to CFGs s follows: S X X c*

From Regexes to CFGs CFGs consist purely of production rules of the form A ω. They do not hve the regulr expression opertors * or. However, we cn convert regulr expressions to CFGs s follows: S X X c* C Cc ε

From Regexes to CFGs CFGs consist purely of production rules of the form A ω. They do not hve the regulr expression opertors * or. However, we cn convert regulr expressions to CFGs s follows: S X X c* C Cc ε

From Regexes to CFGs CFGs consist purely of production rules of the form A ω. They do not hve the regulr expression opertors * or. However, we cn convert regulr expressions to CFGs s follows: S X X C C Cc ε

Regulr Lnguges nd CFLs Theorem: Every regulr lnguge is context-free. Proof Ide: Use the construction from the previous slides to convert regulr expression for L into CFG for L. Prolem Set 8 Exercise: Insted, show how to convert DFA/NFA into CFG.

The Lnguge of Grmmr Consider the following CFG G: S S ε Wht strings cn this generte?

The Lnguge of Grmmr Consider the following CFG G: S S ε Wht strings cn this generte? S

The Lnguge of Grmmr Consider the following CFG G: S S ε Wht strings cn this generte? S

The Lnguge of Grmmr Consider the following CFG G: S S ε Wht strings cn this generte? S

The Lnguge of Grmmr Consider the following CFG G: S S ε Wht strings cn this generte? S

The Lnguge of Grmmr Consider the following CFG G: S S ε Wht strings cn this generte? S

The Lnguge of Grmmr Consider the following CFG G: S S ε Wht strings cn this generte? S

The Lnguge of Grmmr Consider the following CFG G: S S ε Wht strings cn this generte? S

The Lnguge of Grmmr Consider the following CFG G: S S ε Wht strings cn this generte? S

The Lnguge of Grmmr Consider the following CFG G: S S ε Wht strings cn this generte?

The Lnguge of Grmmr Consider the following CFG G: S S ε Wht strings cn this generte?

The Lnguge of Grmmr Consider the following CFG G: S S ε Wht strings cn this generte? L(G) = { n n n N }

Regulr Lnguges CFLs All Lnguges

Why the Extr Power? Why do CFGs hve more power thn regulr expressions? Intuition: Derivtions of strings hve unounded memory. S S ε

Why the Extr Power? Why do CFGs hve more power thn regulr expressions? Intuition: Derivtions of strings hve unounded memory. S S ε

Why the Extr Power? Why do CFGs hve more power thn regulr expressions? Intuition: Derivtions of strings hve unounded memory. S S ε S

Why the Extr Power? Why do CFGs hve more power thn regulr expressions? Intuition: Derivtions of strings hve unounded memory. S S ε S

Why the Extr Power? Why do CFGs hve more power thn regulr expressions? Intuition: Derivtions of strings hve unounded memory. S S ε S

Why the Extr Power? Why do CFGs hve more power thn regulr expressions? Intuition: Derivtions of strings hve unounded memory. S S ε S

Why the Extr Power? Why do CFGs hve more power thn regulr expressions? Intuition: Derivtions of strings hve unounded memory. S S ε S

Why the Extr Power? Why do CFGs hve more power thn regulr expressions? Intuition: Derivtions of strings hve unounded memory. S S ε S

Why the Extr Power? Why do CFGs hve more power thn regulr expressions? Intuition: Derivtions of strings hve unounded memory. S S ε S

Why the Extr Power? Why do CFGs hve more power thn regulr expressions? Intuition: Derivtions of strings hve unounded memory. S S ε S

Why the Extr Power? Why do CFGs hve more power thn regulr expressions? Intuition: Derivtions of strings hve unounded memory. S S ε

Why the Extr Power? Why do CFGs hve more power thn regulr expressions? Intuition: Derivtions of strings hve unounded memory. S S ε

Time-Out for Announcements!

Midterm Exm Logistics The next midterm is tonight from 7:00PM 10:00PM. Loctions re divvied up y lst (fmily) nme: A-I: Go to Cuerley Auditorium. J-Z: Go to Cemex Auditorium. The exm focuses on Lecture 06 13 (inry reltions through induction) nd PS3 PS5. Finite utomt onwrd is not tested. Topics from erlier in the qurter (proofwriting, frst-order logic, set theory, etc.) re lso fir gme, ut tht s primrily ecuse the lter mteril uilds on this erlier mteril. The exm is closed-ook, closed-computer, nd limitednote. You cn ring doule-sided, 8.5 11 sheet of notes with you to the exm, decorted however you d like.

Our Advice Et dinner tonight. You re not rin in jr. You re rich, complex, eutiful iologicl system. Plese tke cre of yourself. Red ll the questions efore diving into them. Tunnel vision cn hurt you on n exm. There s evidence tht spreding your time out leds to etter outcomes. Refect on how fr you ve come. How mny of these questions would you hve een le to understnd two months go? Tht s the mrk tht you re lerning something!

Three Questions Wht is something you know now tht, t the strt of the qurter, you knew you didn t know? Wht is something you know now tht, t the strt of the qurter, you didn t know tht you didn t know? Wht is something you don t know tht, t the strt of the qurter, you didn t know tht you didn t know?

Bck to CS103!

Designing CFGs Like designing DFAs, NFAs, nd regulr expressions, designing CFGs is crft. When thinking out CFGs: Think recursively: Build up igger structures from smller ones. Hve construction pln: Know in wht order you will uild up the string. Store informtion in nonterminls: Hve ech nonterminl correspond to some useful piece of informtion.

Designing CFGs Let Σ = {, } nd let L = {w Σ* w is plindrome } We cn design CFG for L y thinking inductively: Bse cse: ε,, nd re plindromes. If ω is plindrome, then ω nd ω re plindromes. No other strings re plindromes. S ε S S

Designing CFGs Let Σ = {(, )} nd let L = {w Σ* w is string of lnced prentheses } Some smple strings in L: ((())) (())() (()())(()()) ((((()))(()))) ε ()()

Designing CFGs Let Σ = {(, )} nd let L = {w Σ* w is string of lnced prentheses } Let's think out this recursively. Bse cse: the empty string is string of lnced prentheses. Recursive step: Look t the closing prenthesis tht mtches the frst open prenthesis. ((()(()))(()))(())((()))

Designing CFGs Let Σ = {(, )} nd let L = {w Σ* w is string of lnced prentheses } Let's think out this recursively. Bse cse: the empty string is string of lnced prentheses. Recursive step: Look t the closing prenthesis tht mtches the frst open prenthesis. (( ( ) ( ( ) ) )( ( ) ))(())(( ( ) ))

Designing CFGs Let Σ = {(, )} nd let L = {w Σ* w is string of lnced prentheses } Let's think out this recursively. Bse cse: the empty string is string of lnced prentheses. Recursive step: Look t the closing prenthesis tht mtches the frst open prenthesis. (( ( ) ( ( ) ) )( ( ) ))(())(( ( ) ))

Designing CFGs Let Σ = {(, )} nd let L = {w Σ* w is string of lnced prentheses } Let's think out this recursively. Bse cse: the empty string is string of lnced prentheses. Recursive step: Look t the closing prenthesis tht mtches the frst open prenthesis. ( ( ) ( ( ) ) )( ( ) ) (())(( ( ) ))

Designing CFGs Let Σ = {(, )} nd let L = {w Σ* w is string of lnced prentheses } Let's think out this recursively. Bse cse: the empty string is string of lnced prentheses. Recursive step: Look t the closing prenthesis tht mtches the frst open prenthesis. Removing the frst prenthesis nd the mtching prenthesis forms two new strings of lnced prentheses. S (S)S ε

Designing CFGs Let Σ = {, } nd let L = {w Σ* w hs the sme numer of 's nd 's } How How mny mny of of the the following following CFGs CFGs hve hve lnguge lnguge L? L? S S S ε S S S ε S S S ε S SS SS ε Answer Answer t t PollEv.com/cs103 PollEv.com/cs103 or or text text CS103 CS103 to to 22333 22333 once once to to join, join, then then numer. numer.

Designing CFGs Let Σ = {, } nd let L = {w Σ* w hs the sme numer of 's nd 's } How How mny mny of of the the following following CFGs CFGs hve hve lnguge lnguge L? L? S S S ε S S S ε S S S ε S SS SS ε Answer Answer t t PollEv.com/cs103 PollEv.com/cs103 or or text text CS103 CS103 to to 22333 22333 once once to to join, join, then then numer. numer.

Designing CFGs Let Σ = {, } nd let L = {w Σ* w hs the sme numer of 's nd 's } How How mny mny of of the the following following CFGs CFGs hve hve lnguge lnguge L? L? S S S ε S S S ε S S S ε S SS SS ε Answer Answer t t PollEv.com/cs103 PollEv.com/cs103 or or text text CS103 CS103 to to 22333 22333 once once to to join, join, then then numer. numer.

Designing CFGs Let Σ = {, } nd let L = {w Σ* w hs the sme numer of 's nd 's } How How mny mny of of the the following following CFGs CFGs hve hve lnguge lnguge L? L? S S S ε S S S ε S S S ε S SS SS ε Answer Answer t t PollEv.com/cs103 PollEv.com/cs103 or or text text CS103 CS103 to to 22333 22333 once once to to join, join, then then numer. numer.

Designing CFGs Let Σ = {, } nd let L = {w Σ* w hs the sme numer of 's nd 's } How How mny mny of of the the following following CFGs CFGs hve hve lnguge lnguge L? L? S S S ε S S S ε S S S ε S SS SS ε Answer Answer t t PollEv.com/cs103 PollEv.com/cs103 or or text text CS103 CS103 to to 22333 22333 once once to to join, join, then then numer. numer.

Designing CFGs: A Cvet When designing CFG for lnguge, mke sure tht it genertes ll the strings in the lnguge nd never genertes string outside the lnguge. The frst of these cn e tricky mke sure to test your grmmrs! You'll design your own CFG for this lnguge on Prolem Set 8.

CFG Cvets II Is the following grmmr CFG for the lnguge { n n n N }? S S Wht strings in {, }* cn you derive? Answer: None! Wht is the lnguge of the grmmr? Answer: Ø When designing CFGs, mke sure your recursion ctully termintes!

Designing CFGs When designing CFGs, rememer tht ech nonterminl cn e expnded out independently of the others. Let Σ = {, } nd let L = {n n n N }. Is the following CFG for L? S X X X X ε S X X X X X X X X

Finding Build Order Let Σ = {, } nd let L = { n n n N }. To uild CFG for L, we need to e more clever with how we construct the string. If we uild the strings of 's independently of one nother, then we cn't enforce tht they hve the sme length. Ide: Build oth strings of 's t the sme time. Here's one possile grmmr sed on tht ide: S S S S S S

Function Prototypes Let Σ = {void, int, doule, nme, (, ),,, ;}. Let's write CFG for C-style function prototypes! Exmples: void nme(int nme, doule nme); int nme(); int nme(doule nme); int nme(int, int nme, int); void nme(void);

Function Prototypes Here's one possile grmmr: S Ret nme (Args); Ret Type void Type int doule Args ε void ArgList ArgList OneArg ArgList, OneArg OneArg Type Type nme Fun question to think out: wht chnges would you need to mke to support pointer types?

Summry of CFG Design Tips Look for recursive structures where they exist: they cn help guide you towrd solution. Keep the uild order in mind often, you'll uild two totlly diferent prts of the string concurrently. Usully, those prts re uilt in opposite directions: one's uilt left-to-right, the other right-to-left. Use diferent nonterminls to represent diferent structures.

Applictions of Context-Free Grmmrs

CFGs for Progrmming Lnguges BLOCK STMT { STMTS } STMTS ε STMT STMTS STMT EXPR; if (EXPR) BLOCK while (EXPR) BLOCK do BLOCK while (EXPR); BLOCK EXPR identifier constnt EXPR + EXPR EXPR EXPR EXPR * EXPR...

Grmmrs in Compilers One of the key steps in compiler is fguring out wht progrm mens. This is usully done y defning grmmr showing the high-level structure of progrmming lnguge. There re certin clsses of grmmrs (LL(1) grmmrs, LR(1) grmmrs, LALR(1) grmmrs, etc.) for which it's esy to fgure out how prticulr string ws derived. Tools like ycc or ison utomticlly generte prsers from these grmmrs. Curious to lern more? Tke CS143!

Nturl Lnguge Processing By uilding context-free grmmrs for ctul lnguges nd pplying sttisticl inference, it's possile for computer to recover the likely mening of sentence. In fct, CFGs were frst clled phrse-structure grmmrs nd were introduced y Nom Chomsky in his seminl work Syntctic Structures. They were then dpted for use in the context of progrmming lnguges, where they were clled Bckus- Nur forms. Stnford's CoreNLP project is one plce to look for n exmple of this. Wnt to lern more? Tke CS124 or CS224N!

Biogrphy Minute: Nom Chomsky Invented CFGs! Helped found felds of linguistics nd cognitive science PC: Hns Peters / Anefo (vi Wikimedi) Tody, perhps more well known for politicl writing thn linguistics Mde it onto President Nixon s Enemies List Anti-cpitlism, nti-imperilism, nti-wr Drwing on linguistics expertise, written extensively on stte propgnd (Mnufcturing Consent)

Next Time Turing Mchines Wht does computer with unounded memory look like? How would you progrm it?