Context-Free Grammars

Size: px
Start display at page:

Download "Context-Free Grammars"

Transcription

1 Context-Free Grmmrs

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

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

4 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)

5 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

6 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 /

7 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 /

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

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

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

11 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).

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

13 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 once once to to join, join, then then numer. numer.

14 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?

15 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 *

16 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 *

17 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 ε

18 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 ε

19 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 ε

20 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*)

21 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*)

22 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*

23 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*

24 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*

25 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*

26 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 ε

27 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 ε

28 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 ε

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

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

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

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

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

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

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

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

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

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

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

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

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

42 Regulr Lnguges CFLs All Lnguges

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

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

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

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

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

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

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

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

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

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

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

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

55 Time-Out for Announcements!

56 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 (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, sheet of notes with you to the exm, decorted however you d like.

57 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!

58 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?

59 Bck to CS103!

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

61 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

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

63 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. ((()(()))(()))(())((()))

64 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. (( ( ) ( ( ) ) )( ( ) ))(())(( ( ) ))

65 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. (( ( ) ( ( ) ) )( ( ) ))(())(( ( ) ))

66 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. ( ( ) ( ( ) ) )( ( ) ) (())(( ( ) ))

67 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 ε

68 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 once once to to join, join, then then numer. numer.

69 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 once once to to join, join, then then numer. numer.

70 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 once once to to join, join, then then numer. numer.

71 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 once once to to join, join, then then numer. numer.

72 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 once once to to join, join, then then numer. numer.

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

74 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!

75 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

76 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

77 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);

78 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?

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

80 Applictions of Context-Free Grmmrs

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

82 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!

83 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!

84 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)

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

Context-Free Grammars

Context-Free Grammars 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.

More information

Context-Free Grammars

Context-Free Grammars Context-Free Grmmrs Describing Lnguges We've seen two models for the regulr lnguges: Finite utomt ccept precisely the strings in the lnguge. Regulr expressions describe precisely the strings in the lnguge.

More information

Context-Free Grammars

Context-Free Grammars Context-Free Grammars Describing Languages We've seen two models for the regular languages: Finite automata accept precisely the strings in the language. Regular expressions describe precisely the strings

More information

Fig.25: the Role of LEX

Fig.25: the Role of LEX The Lnguge for Specifying Lexicl Anlyzer We shll now study how to uild lexicl nlyzer from specifiction of tokens in the form of list of regulr expressions The discussion centers round the design of n existing

More information

Context-Free Grammars

Context-Free Grammars Context-Free Grammars Describing Languages We've seen two models for the regular languages: Finite automata accept precisely the strings in the language. Regular expressions describe precisely the strings

More information

Dr. D.M. Akbar Hussain

Dr. D.M. Akbar Hussain Dr. D.M. Akr Hussin Lexicl Anlysis. Bsic Ide: Red the source code nd generte tokens, it is similr wht humns will do to red in; just tking on the input nd reking it down in pieces. Ech token is sequence

More information

ASTs, Regex, Parsing, and Pretty Printing

ASTs, Regex, Parsing, and Pretty Printing ASTs, Regex, Prsing, nd Pretty Printing CS 2112 Fll 2016 1 Algeric Expressions To strt, consider integer rithmetic. Suppose we hve the following 1. The lphet we will use is the digits {0, 1, 2, 3, 4, 5,

More information

Definition of Regular Expression

Definition of Regular Expression Definition of Regulr Expression After the definition of the string nd lnguges, we re redy to descrie regulr expressions, the nottion we shll use to define the clss of lnguges known s regulr sets. Recll

More information

CS 430 Spring Mike Lam, Professor. Parsing

CS 430 Spring Mike Lam, Professor. Parsing CS 430 Spring 2015 Mike Lm, Professor Prsing Syntx Anlysis We cn now formlly descrie lnguge's syntx Using regulr expressions nd BNF grmmrs How does tht help us? Syntx Anlysis We cn now formlly descrie

More information

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

CSCI 3130: Formal Languages and Automata Theory Lecture 12 The Chinese University of Hong Kong, Fall 2011 CSCI 3130: Forml Lnguges nd utomt Theory Lecture 12 The Chinese University of Hong Kong, Fll 2011 ndrej Bogdnov In progrmming lnguges, uilding prse trees is significnt tsk ecuse prse trees tell us the

More information

CS321 Languages and Compiler Design I. Winter 2012 Lecture 5

CS321 Languages and Compiler Design I. Winter 2012 Lecture 5 CS321 Lnguges nd Compiler Design I Winter 2012 Lecture 5 1 FINITE AUTOMATA A non-deterministic finite utomton (NFA) consists of: An input lphet Σ, e.g. Σ =,. A set of sttes S, e.g. S = {1, 3, 5, 7, 11,

More information

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.

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. CS 340, Fll 2014 Dec 11 th /13 th Finl Exm Nme: Note: in ll questions, the specil symol ɛ (epsilon) is used to indicte the empty string. Question 1. [5 points] Consider the following regulr expression;

More information

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

CS143 Handout 07 Summer 2011 June 24 th, 2011 Written Set 1: Lexical Analysis CS143 Hndout 07 Summer 2011 June 24 th, 2011 Written Set 1: Lexicl Anlysis In this first written ssignment, you'll get the chnce to ply round with the vrious constructions tht come up when doing lexicl

More information

COMP 423 lecture 11 Jan. 28, 2008

COMP 423 lecture 11 Jan. 28, 2008 COMP 423 lecture 11 Jn. 28, 2008 Up to now, we hve looked t how some symols in n lphet occur more frequently thn others nd how we cn sve its y using code such tht the codewords for more frequently occuring

More information

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

Homework. Context Free Languages III. Languages. Plan for today. Context Free Languages. CFLs and Regular Languages. Homework #5 (due 10/22) Homework Context Free Lnguges III Prse Trees nd Homework #5 (due 10/22) From textbook 6.4,b 6.5b 6.9b,c 6.13 6.22 Pln for tody Context Free Lnguges Next clss of lnguges in our quest! Lnguges Recll. Wht

More information

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

In the last lecture, we discussed how valid tokens may be specified by regular expressions. LECTURE 5 Scnning SYNTAX ANALYSIS We know from our previous lectures tht the process of verifying the syntx of the progrm is performed in two stges: Scnning: Identifying nd verifying tokens in progrm.

More information

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

CS 432 Fall Mike Lam, Professor a (bc)* Regular Expressions and Finite Automata CS 432 Fll 2017 Mike Lm, Professor (c)* Regulr Expressions nd Finite Automt Compiltion Current focus "Bck end" Source code Tokens Syntx tree Mchine code chr dt[20]; int min() { flot x = 42.0; return 7;

More information

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

this grammar generates the following language: Because this symbol will also be used in a later step, it receives the LR() nlysis Drwcks of LR(). Look-hed symols s eplined efore, concerning LR(), it is possile to consult the net set to determine, in the reduction sttes, for which symols it would e possile to perform reductions.

More information

Compilers Spring 2013 PRACTICE Midterm Exam

Compilers Spring 2013 PRACTICE Midterm Exam Compilers Spring 2013 PRACTICE Midterm Exm This is full length prctice midterm exm. If you wnt to tke it t exm pce, give yourself 7 minutes to tke the entire test. Just like the rel exm, ech question hs

More information

CMPSC 470: Compiler Construction

CMPSC 470: Compiler Construction CMPSC 47: Compiler Construction Plese complete the following: Midterm (Type A) Nme Instruction: Mke sure you hve ll pges including this cover nd lnk pge t the end. Answer ech question in the spce provided.

More information

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

CS 340, Fall 2016 Sep 29th Exam 1 Note: in all questions, the special symbol ɛ (epsilon) is used to indicate the empty string. CS 340, Fll 2016 Sep 29th Exm 1 Nme: Note: in ll questions, the speil symol ɛ (epsilon) is used to indite the empty string. Question 1. [10 points] Speify regulr expression tht genertes the lnguge over

More information

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

Languages. L((a (b)(c))*) = { ε,a,bc,aa,abc,bca,... } εw = wε = w. εabba = abbaε = abba. (a (b)(c)) * Pln for Tody nd Beginning Next week Interpreter nd Compiler Structure, or Softwre Architecture Overview of Progrmming Assignments The MeggyJv compiler we will e uilding. Regulr Expressions Finite Stte

More information

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

ΕΠΛ323 - Θεωρία και Πρακτική Μεταγλωττιστών ΕΠΛ323 - Θωρία και Πρακτική Μταγλωττιστών Lecture 3 Lexicl Anlysis Elis Athnsopoulos elisthn@cs.ucy.c.cy Recognition of Tokens if expressions nd reltionl opertors if è if then è then else è else relop

More information

ECE 468/573 Midterm 1 September 28, 2012

ECE 468/573 Midterm 1 September 28, 2012 ECE 468/573 Midterm 1 September 28, 2012 Nme:! Purdue emil:! Plese sign the following: I ffirm tht the nswers given on this test re mine nd mine lone. I did not receive help from ny person or mteril (other

More information

Lecture 10 Evolutionary Computation: Evolution strategies and genetic programming

Lecture 10 Evolutionary Computation: Evolution strategies and genetic programming Lecture 10 Evolutionry Computtion: Evolution strtegies nd genetic progrmming Evolution strtegies Genetic progrmming Summry Negnevitsky, Person Eduction, 2011 1 Evolution Strtegies Another pproch to simulting

More information

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

Tries. Yufei Tao KAIST. April 9, Y. Tao, April 9, 2013 Tries Tries Yufei To KAIST April 9, 2013 Y. To, April 9, 2013 Tries In this lecture, we will discuss the following exct mtching prolem on strings. Prolem Let S e set of strings, ech of which hs unique integer

More information

Context-Free Grammars

Context-Free Grammars Context-Free Grammars Describing Languages We've seen two models for the regular languages: Automata accept precisely the strings in the language. Regular expressions describe precisely the strings in

More information

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

LING/C SC/PSYC 438/538. Lecture 21 Sandiway Fong LING/C SC/PSYC 438/538 Lecture 21 Sndiwy Fong Tody's Topics Homework 8 Review Optionl Homework 9 (mke up on Homework 7) Homework 8 Review Question1: write Prolog regulr grmmr for the following lnguge:

More information

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

Quiz2 45mins. Personal Number: Problem 1. (20pts) Here is an Table of Perl Regular Ex Long Quiz2 45mins Nme: Personl Numer: Prolem. (20pts) Here is n Tle of Perl Regulr Ex Chrcter Description. single chrcter \s whitespce chrcter (spce, t, newline) \S non-whitespce chrcter \d digit (0-9)

More information

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

Some Thoughts on Grad School. Undergraduate Compilers Review and Intro to MJC. Structure of a Typical Compiler. Lexing and Parsing Undergrdute Compilers Review nd Intro to MJC Announcements Miling list is in full swing Tody Some thoughts on grd school Finish prsing Semntic nlysis Visitor pttern for bstrct syntx trees Some Thoughts

More information

Midterm I Solutions CS164, Spring 2006

Midterm I Solutions CS164, Spring 2006 Midterm I Solutions CS164, Spring 2006 Februry 23, 2006 Plese red ll instructions (including these) crefully. Write your nme, login, SID, nd circle the section time. There re 8 pges in this exm nd 4 questions,

More information

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

Operator Precedence. Java CUP. E E + T T T * P P P id id id. Does a+b*c mean (a+b)*c or Opertor Precedence Most progrmming lnguges hve opertor precedence rules tht stte the order in which opertors re pplied (in the sence of explicit prentheses). Thus in C nd Jv nd CSX, +*c mens compute *c,

More information

Topic 2: Lexing and Flexing

Topic 2: Lexing and Flexing Topic 2: Lexing nd Flexing COS 320 Compiling Techniques Princeton University Spring 2016 Lennrt Beringer 1 2 The Compiler Lexicl Anlysis Gol: rek strem of ASCII chrcters (source/input) into sequence of

More information

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

Today. CS 188: Artificial Intelligence Fall Recap: Search. Example: Pancake Problem. Example: Pancake Problem. General Tree Search. CS 88: Artificil Intelligence Fll 00 Lecture : A* Serch 9//00 A* Serch rph Serch Tody Heuristic Design Dn Klein UC Berkeley Multiple slides from Sturt Russell or Andrew Moore Recp: Serch Exmple: Pncke

More information

CSCE 531, Spring 2017, Midterm Exam Answer Key

CSCE 531, Spring 2017, Midterm Exam Answer Key CCE 531, pring 2017, Midterm Exm Answer Key 1. (15 points) Using the method descried in the ook or in clss, convert the following regulr expression into n equivlent (nondeterministic) finite utomton: (

More information

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

CS 236 Language and Computation. Alphabet. Definition. I.2.1. Formal Languages (10.1) C 236 Lnguge nd Computtion Course Notes Prt I: Grmmrs for Defining yntx (II) Chpter I.2: yntx nd Grmmrs (10, 12.1) Anton etzer (Bsed on ook drft y J. V. Tucker nd K. tephenson) Dept. of Computer cience,

More information

Reducing a DFA to a Minimal DFA

Reducing a DFA to a Minimal DFA Lexicl Anlysis - Prt 4 Reducing DFA to Miniml DFA Input: DFA IN Assume DFA IN never gets stuck (dd ded stte if necessry) Output: DFA MIN An equivlent DFA with the minimum numer of sttes. Hrry H. Porter,

More information

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

Unit #9 : Definite Integral Properties, Fundamental Theorem of Calculus Unit #9 : Definite Integrl Properties, Fundmentl Theorem of Clculus Gols: Identify properties of definite integrls Define odd nd even functions, nd reltionship to integrl vlues Introduce the Fundmentl

More information

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

Lexical Analysis. Amitabha Sanyal. (www.cse.iitb.ac.in/ as) Department of Computer Science and Engineering, Indian Institute of Technology, Bombay Lexicl Anlysis Amith Snyl (www.cse.iit.c.in/ s) Deprtment of Computer Science nd Engineering, Indin Institute of Technology, Bomy Septemer 27 College of Engineering, Pune Lexicl Anlysis: 2/6 Recp The input

More information

CSE 401 Midterm Exam 11/5/10 Sample Solution

CSE 401 Midterm Exam 11/5/10 Sample Solution Question 1. egulr expressions (20 points) In the Ad Progrmming lnguge n integer constnt contins one or more digits, but it my lso contin embedded underscores. Any underscores must be preceded nd followed

More information

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

Deterministic. Finite Automata. And Regular Languages. Fall 2018 Costas Busch - RPI 1 Deterministic Finite Automt And Regulr Lnguges Fll 2018 Costs Busch - RPI 1 Deterministic Finite Automton (DFA) Input Tpe String Finite Automton Output Accept or Reject Fll 2018 Costs Busch - RPI 2 Trnsition

More information

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

ΕΠΛ323 - Θεωρία και Πρακτική Μεταγλωττιστών. Lecture 3b Lexical Analysis Elias Athanasopoulos ΕΠΛ323 - Θωρία και Πρακτική Μταγλωττιστών Lecture 3 Lexicl Anlysis Elis Athnsopoulos elisthn@cs.ucy.c.cy RecogniNon of Tokens if expressions nd relnonl opertors if è if then è then else è else relop è

More information

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

CS412/413. Introduction to Compilers Tim Teitelbaum. Lecture 4: Lexical Analyzers 28 Jan 08 CS412/413 Introduction to Compilers Tim Teitelum Lecture 4: Lexicl Anlyzers 28 Jn 08 Outline DFA stte minimiztion Lexicl nlyzers Automting lexicl nlysis Jlex lexicl nlyzer genertor CS 412/413 Spring 2008

More information

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

Announcements. CS 188: Artificial Intelligence Fall Recap: Search. Today. Example: Pancake Problem. Example: Pancake Problem Announcements Project : erch It s live! Due 9/. trt erly nd sk questions. It s longer thn most! Need prtner? Come up fter clss or try Pizz ections: cn go to ny, ut hve priority in your own C 88: Artificil

More information

10.5 Graphing Quadratic Functions

10.5 Graphing Quadratic Functions 0.5 Grphing Qudrtic Functions Now tht we cn solve qudrtic equtions, we wnt to lern how to grph the function ssocited with the qudrtic eqution. We cll this the qudrtic function. Grphs of Qudrtic Functions

More information

Compiler Construction D7011E

Compiler Construction D7011E Compiler Construction D7011E Lecture 3: Lexer genertors Viktor Leijon Slides lrgely y John Nordlnder with mteril generously provided y Mrk P. Jones. 1 Recp: Hndwritten Lexers: Don t require sophisticted

More information

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

CSc 453. Compilers and Systems Software. 4 : Lexical Analysis II. Department of Computer Science University of Arizona CSc 453 Compilers nd Systems Softwre 4 : Lexicl Anlysis II Deprtment of Computer Science University of Arizon collerg@gmil.com Copyright c 2009 Christin Collerg Implementing Automt NFAs nd DFAs cn e hrd-coded

More information

TO REGULAR EXPRESSIONS

TO REGULAR EXPRESSIONS Suject :- Computer Science Course Nme :- Theory Of Computtion DA TO REGULAR EXPRESSIONS Report Sumitted y:- Ajy Singh Meen 07000505 jysmeen@cse.iit.c.in BASIC DEINITIONS DA:- A finite stte mchine where

More information

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

Java CUP. Java CUP Specifications. User Code Additions. Package and Import Specifications Jv CUP Jv CUP is prser-genertion tool, similr to Ycc. CUP uilds Jv prser for LALR(1) grmmrs from production rules nd ssocited Jv code frgments. When prticulr production is recognized, its ssocited code

More information

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

Implementing Automata. CSc 453. Compilers and Systems Software. 4 : Lexical Analysis II. Department of Computer Science University of Arizona Implementing utomt Sc 5 ompilers nd Systems Softwre : Lexicl nlysis II Deprtment of omputer Science University of rizon collerg@gmil.com opyright c 009 hristin ollerg NFs nd DFs cn e hrd-coded using this

More information

Theory of Computation CSE 105

Theory of Computation CSE 105 $ $ $ Theory of Computtion CSE 105 Regulr Lnguges Study Guide nd Homework I Homework I: Solutions to the following problems should be turned in clss on July 1, 1999. Instructions: Write your nswers clerly

More information

Lexical Analysis: Constructing a Scanner from Regular Expressions

Lexical Analysis: Constructing a Scanner from Regular Expressions Lexicl Anlysis: Constructing Scnner from Regulr Expressions Gol Show how to construct FA to recognize ny RE This Lecture Convert RE to n nondeterministic finite utomton (NFA) Use Thompson s construction

More information

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

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 Should e done L hours nd Office hours Sign up for the miling list t, strting to send importnt info to list http://groups.google.com/group/cs453-spring-2011 Red Ch 1 nd skim Ch 2 through 2.6, red 3.3 nd

More information

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

10/12/17. Motivating Example. Lexical and Syntax Analysis (2) Recursive-Descent Parsing. Recursive-Descent Parsing. Recursive-Descent Parsing Motivting Exmple Lexicl nd yntx Anlysis (2) In Text: Chpter 4 Consider the grmmr -> cad A -> b Input string: w = cd How to build prse tree top-down? 2 Initilly crete tree contining single node (the strt

More information

CMSC 331 First Midterm Exam

CMSC 331 First Midterm Exam 0 00/ 1 20/ 2 05/ 3 15/ 4 15/ 5 15/ 6 20/ 7 30/ 8 30/ 150/ 331 First Midterm Exm 7 October 2003 CMC 331 First Midterm Exm Nme: mple Answers tudent ID#: You will hve seventy-five (75) minutes to complete

More information

Midterm 2 Sample solution

Midterm 2 Sample solution Nme: Instructions Midterm 2 Smple solution CMSC 430 Introduction to Compilers Fll 2012 November 28, 2012 This exm contins 9 pges, including this one. Mke sure you hve ll the pges. Write your nme on the

More information

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

George Boole. IT 3123 Hardware and Software Concepts. Switching Algebra. Boolean Functions. Boolean Functions. Truth Tables George Boole IT 3123 Hrdwre nd Softwre Concepts My 28 Digitl Logic The Little Mn Computer 1815 1864 British mthemticin nd philosopher Mny contriutions to mthemtics. Boolen lger: n lger over finite sets

More information

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

UNIVERSITY OF EDINBURGH COLLEGE OF SCIENCE AND ENGINEERING SCHOOL OF INFORMATICS INFORMATICS 1 COMPUTATION & LOGIC INSTRUCTIONS TO CANDIDATES UNIVERSITY OF EDINBURGH COLLEGE OF SCIENCE AND ENGINEERING SCHOOL OF INFORMATICS INFORMATICS COMPUTATION & LOGIC Sturdy st April 7 : to : INSTRUCTIONS TO CANDIDATES This is tke-home exercise. It will not

More information

CS 241 Week 4 Tutorial Solutions

CS 241 Week 4 Tutorial Solutions CS 4 Week 4 Tutoril Solutions Writing n Assemler, Prt & Regulr Lnguges Prt Winter 8 Assemling instrutions utomtilly. slt $d, $s, $t. Solution: $d, $s, nd $t ll fit in -it signed integers sine they re 5-it

More information

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

If you are at the university, either physically or via the VPN, you can download the chapters of this book as PDFs. Lecture 5 Wlks, Trils, Pths nd Connectedness Reding: Some of the mteril in this lecture comes from Section 1.2 of Dieter Jungnickel (2008), Grphs, Networks nd Algorithms, 3rd edition, which is ville online

More information

Lexical analysis, scanners. Construction of a scanner

Lexical analysis, scanners. Construction of a scanner Lexicl nlysis scnners (NB. Pges 4-5 re for those who need to refresh their knowledge of DFAs nd NFAs. These re not presented during the lectures) Construction of scnner Tools: stte utomt nd trnsition digrms.

More information

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

LR Parsing, Part 2. Constructing Parse Tables. Need to Automatically Construct LR Parse Tables: Action and GOTO Table TDDD55 Compilers nd Interpreters TDDB44 Compiler Construction LR Prsing, Prt 2 Constructing Prse Tles Prse tle construction Grmmr conflict hndling Ctegories of LR Grmmrs nd Prsers Peter Fritzson, Christoph

More information

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

Top-down vs Bottom-up. Bottom up parsing. Sentential form. Handles. Handles in expression example Bottom up prsing Generl e LR0) LR LR1) LLR o est exploit JvCUP, should understnd the theoreticl sis LR prsing); op-down vs Bottom-up Bottom-up more powerful thn top-down; Cn process more powerful grmmr

More information

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

Announcements. CS 188: Artificial Intelligence Fall Recap: Search. Today. General Tree Search. Uniform Cost. Lecture 3: A* Search 9/4/2007 CS 88: Artificil Intelligence Fll 2007 Lecture : A* Serch 9/4/2007 Dn Klein UC Berkeley Mny slides over the course dpted from either Sturt Russell or Andrew Moore Announcements Sections: New section 06:

More information

Introduction to Integration

Introduction to Integration Introduction to Integrtion Definite integrls of piecewise constnt functions A constnt function is function of the form Integrtion is two things t the sme time: A form of summtion. The opposite of differentition.

More information

Simplifying Algebra. Simplifying Algebra. Curriculum Ready.

Simplifying Algebra. Simplifying Algebra. Curriculum Ready. Simplifying Alger Curriculum Redy www.mthletics.com This ooklet is ll out turning complex prolems into something simple. You will e le to do something like this! ( 9- # + 4 ' ) ' ( 9- + 7-) ' ' Give this

More information

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

2 Computing all Intersections of a Set of Segments Line Segment Intersection 15-451/651: Design & Anlysis of Algorithms Novemer 14, 2016 Lecture #21 Sweep-Line nd Segment Intersection lst chnged: Novemer 8, 2017 1 Preliminries The sweep-line prdigm is very powerful lgorithmic design

More information

CS 321 Programming Languages and Compilers. Bottom Up Parsing

CS 321 Programming Languages and Compilers. Bottom Up Parsing CS 321 Progrmming nguges nd Compilers Bottom Up Prsing Bottom-up Prsing: Shift-reduce prsing Grmmr H: fi ; fi b Input: ;;b hs prse tree ; ; b 2 Dt for Shift-reduce Prser Input string: sequence of tokens

More information

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

CS311H: Discrete Mathematics. Graph Theory IV. A Non-planar Graph. Regions of a Planar Graph. Euler s Formula. Instructor: Işıl Dillig CS311H: Discrete Mthemtics Grph Theory IV Instructor: Işıl Dillig Instructor: Işıl Dillig, CS311H: Discrete Mthemtics Grph Theory IV 1/25 A Non-plnr Grph Regions of Plnr Grph The plnr representtion of

More information

Section 10.4 Hyperbolas

Section 10.4 Hyperbolas 66 Section 10.4 Hyperbols Objective : Definition of hyperbol & hyperbols centered t (0, 0). The third type of conic we will study is the hyperbol. It is defined in the sme mnner tht we defined the prbol

More information

Patterns and Algebra. My name. Series

Patterns and Algebra. My name. Series Student Techer Ptterns nd Alger My nme Series D Copyright 009 P Lerning. All rights reserved. First edition printed 009 in Austrli. A ctlogue record for this ook is ville from P Lerning Ltd. ISBN 978--9860--

More information

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

Systems I. Logic Design I. Topics Digital logic Logic gates Simple combinational logic circuits Systems I Logic Design I Topics Digitl logic Logic gtes Simple comintionl logic circuits Simple C sttement.. C = + ; Wht pieces of hrdwre do you think you might need? Storge - for vlues,, C Computtion

More information

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

Solving Problems by Searching. CS 486/686: Introduction to Artificial Intelligence Winter 2016 Solving Prolems y Serching CS 486/686: Introduction to Artificil Intelligence Winter 2016 1 Introduction Serch ws one of the first topics studied in AI - Newell nd Simon (1961) Generl Prolem Solver Centrl

More information

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

12 <= rm <digit> 2 <= rm <no> 2 <= rm <no> <digit> <= rm <no> <= rm <number> DDD16 Compilers nd Interpreters DDB44 Compiler Construction R Prsing Prt 1 R prsing concept Using prser genertor Prse ree Genertion Wht is R-prsing? eft-to-right scnning R Rigthmost derivtion in reverse

More information

Lecture 7: Integration Techniques

Lecture 7: Integration Techniques Lecture 7: Integrtion Techniques Antiderivtives nd Indefinite Integrls. In differentil clculus, we were interested in the derivtive of given rel-vlued function, whether it ws lgeric, eponentil or logrithmic.

More information

Lecture T1: Pattern Matching

Lecture T1: Pattern Matching Introduction to Theoreticl CS Lecture T: Pttern Mtchin Two fundmentl questions. Wht cn computer do? Wht cn computer do with limited resources? Generl pproch. Don t tlk out specific mchines or prolems.

More information

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

CS 241. Fall 2017 Midterm Review Solutions. October 24, Bits and Bytes 1. 3 MIPS Assembler 6. 4 Regular Languages 7. CS 241 Fll 2017 Midterm Review Solutions Octoer 24, 2017 Contents 1 Bits nd Bytes 1 2 MIPS Assemly Lnguge Progrmming 2 3 MIPS Assemler 6 4 Regulr Lnguges 7 5 Scnning 9 1 Bits nd Bytes 1. Give two s complement

More information

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

AI Adjacent Fields. This slide deck courtesy of Dan Klein at UC Berkeley AI Adjcent Fields Philosophy: Logic, methods of resoning Mind s physicl system Foundtions of lerning, lnguge, rtionlity Mthemtics Forml representtion nd proof Algorithms, computtion, (un)decidility, (in)trctility

More information

Section 3.1: Sequences and Series

Section 3.1: Sequences and Series Section.: Sequences d Series Sequences Let s strt out with the definition of sequence: sequence: ordered list of numbers, often with definite pttern Recll tht in set, order doesn t mtter so this is one

More information

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

Finite Automata. Lecture 4 Sections Robb T. Koether. Hampden-Sydney College. Wed, Jan 21, 2015 Finite Automt Lecture 4 Sections 3.6-3.7 Ro T. Koether Hmpden-Sydney College Wed, Jn 21, 2015 Ro T. Koether (Hmpden-Sydney College) Finite Automt Wed, Jn 21, 2015 1 / 23 1 Nondeterministic Finite Automt

More information

INTRODUCTION TO SIMPLICIAL COMPLEXES

INTRODUCTION TO SIMPLICIAL COMPLEXES INTRODUCTION TO SIMPLICIAL COMPLEXES CASEY KELLEHER AND ALESSANDRA PANTANO 0.1. Introduction. In this ctivity set we re going to introduce notion from Algebric Topology clled simplicil homology. The min

More information

Information Retrieval and Organisation

Information Retrieval and Organisation Informtion Retrievl nd Orgnistion Suffix Trees dpted from http://www.mth.tu.c.il/~himk/seminr02/suffixtrees.ppt Dell Zhng Birkeck, University of London Trie A tree representing set of strings { } eef d

More information

Algorithm Design (5) Text Search

Algorithm Design (5) Text Search Algorithm Design (5) Text Serch Tkshi Chikym School of Engineering The University of Tokyo Text Serch Find sustring tht mtches the given key string in text dt of lrge mount Key string: chr x[m] Text Dt:

More information

What are suffix trees?

What are suffix trees? Suffix Trees 1 Wht re suffix trees? Allow lgorithm designers to store very lrge mount of informtion out strings while still keeping within liner spce Allow users to serch for new strings in the originl

More information

MTH 146 Conics Supplement

MTH 146 Conics Supplement 105- Review of Conics MTH 146 Conics Supplement In this section we review conics If ou ne more detils thn re present in the notes, r through section 105 of the ook Definition: A prol is the set of points

More information

From Dependencies to Evaluation Strategies

From Dependencies to Evaluation Strategies From Dependencies to Evlution Strtegies Possile strtegies: 1 let the user define the evlution order 2 utomtic strtegy sed on the dependencies: use locl dependencies to determine which ttriutes to compute

More information

Eliminating left recursion grammar transformation. The transformed expression grammar

Eliminating left recursion grammar transformation. The transformed expression grammar Eliminting left recursion grmmr trnsformtion Originl! rnsformed! 0 0! 0 α β α α α α α α α α β he two grmmrs generte the sme lnguge, but the one on the right genertes the rst, nd then string of s, using

More information

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

The Math Learning Center PO Box 12929, Salem, Oregon Math Learning Center Resource Overview Quntile Mesure: Skill or Concept: 80Q Multiply two frctions or frction nd whole numer. (QT N ) Excerpted from: The Mth Lerning Center PO Box 99, Slem, Oregon 9709 099 www.mthlerningcenter.org

More information

Regular Expressions and Automata using Miranda

Regular Expressions and Automata using Miranda Regulr Expressions nd Automt using Mirnd Simon Thompson Computing Lortory Univerisity of Kent t Cnterury My 1995 Contents 1 Introduction ::::::::::::::::::::::::::::::::: 1 2 Regulr Expressions :::::::::::::::::::::::::::::

More information

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

Stack Manipulation. Other Issues. How about larger constants? Frame Pointer. PowerPC. Alternative Architectures Other Issues Stck Mnipultion support for procedures (Refer to section 3.6), stcks, frmes, recursion mnipulting strings nd pointers linkers, loders, memory lyout Interrupts, exceptions, system clls nd conventions

More information

SERIES. Patterns and Algebra OUT. Name

SERIES. Patterns and Algebra OUT. Name D Techer Student Book IN OUT 8 Nme Series D Contents Topic Section Ptterns Answers nd (pp. functions ) identifying ptterns nd nd functions_ creting ptterns_ skip equtions counting nd equivlence completing

More information

Assignment 4. Due 09/18/17

Assignment 4. Due 09/18/17 Assignment 4. ue 09/18/17 1. ). Write regulr expressions tht define the strings recognized by the following finite utomt: b d b b b c c b) Write FA tht recognizes the tokens defined by the following regulr

More information

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

Uninformed Search. Hal Daumé III. Computer Science University of Maryland CS 421: Introduction to Artificial Intelligence 31 Jan 2012 1 Hl Dumé III (me@hl3.nme) Uninformed Serch Hl Dumé III Comuter Science University of Mrylnd me@hl3.nme CS 421: Introduction to Artificil Intelligence 31 Jn 2012 Mny slides courtesy of Dn Klein, Sturt

More information

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

Scanner Termination. Multi Character Lookahead. to its physical end. Most parsers require an end of file token. Lex and Jlex automatically create an Scnner Termintion A scnner reds input chrcters nd prtitions them into tokens. Wht hppens when the end of the input file is reched? It my be useful to crete n Eof pseudo-chrcter when this occurs. In Jv,

More information

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

How to Design REST API? Written Date : March 23, 2015 Visul Prdigm How Design REST API? Turil How Design REST API? Written Dte : Mrch 23, 2015 REpresenttionl Stte Trnsfer, n rchitecturl style tht cn be used in building networked pplictions, is becoming incresingly

More information

CS481: Bioinformatics Algorithms

CS481: Bioinformatics Algorithms CS481: Bioinformtics Algorithms Cn Alkn EA509 clkn@cs.ilkent.edu.tr http://www.cs.ilkent.edu.tr/~clkn/teching/cs481/ EXACT STRING MATCHING Fingerprint ide Assume: We cn compute fingerprint f(p) of P in

More information

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

Sample Midterm Solutions COMS W4115 Programming Languages and Translators Monday, October 12, 2009 Deprtment of Computer cience Columbi University mple Midterm olutions COM W4115 Progrmming Lnguges nd Trnsltors Mondy, October 12, 2009 Closed book, no ids. ch question is worth 20 points. Question 5(c)

More information

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

Problem Set 2 Fall 16 Due: Wednesday, September 21th, in class, before class begins. Problem Set 2 Fll 16 Due: Wednesdy, September 21th, in clss, before clss begins. 1. LL Prsing For the following sub-problems, consider the following context-free grmmr: S T$ (1) T A (2) T bbb (3) A T (4)

More information

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

Solving Problems by Searching. CS 486/686: Introduction to Artificial Intelligence Solving Prolems y Serching CS 486/686: Introduction to Artificil Intelligence 1 Introduction Serch ws one of the first topics studied in AI - Newell nd Simon (1961) Generl Prolem Solver Centrl component

More information

Example: 2:1 Multiplexer

Example: 2:1 Multiplexer Exmple: 2:1 Multiplexer Exmple #1 reg ; lwys @( or or s) egin if (s == 1') egin = ; else egin = ; 1 s B. Bs 114 Exmple: 2:1 Multiplexer Exmple #2 Normlly lwys include egin nd sttements even though they

More information