chapter 12
play

Chapter 12 How do you get a derivation from a Phrase Structured - PDF document

Chapter 12 How do you get a derivation from a Phrase Structured Grammar GV,T,S,P ICS 6B Suppose a phrasestructured grammar has Boolean Algebra & Logic productions: S ABa, A BB, B ab, AB b 1


  1. Chapter 12 � How do you get a derivation from a Phrase Structured Grammar �G�V,T,S,P� ICS 6B Suppose a phrase‐structured grammar has Boolean Algebra & Logic productions: S �ABa, A �BB, B �ab, AB �b �1� �2� �3� �4� Find the derivation of BBaba: Lecture Notes for Summer Quarter, 2008 ba �4� �1� �3�, �3�, �3� S � ABa � BBBa �2� � abababa Michele Rousseau �3� Aaba �BBaba �3�, �3� �2� Answer: ABa � Aaba � Bbaba Final Review (Some slides inspired and adapted from Alessandra Pantano) ABa � BBBa � BBaba or 2 Different types of Grammars Construct the Language of a Grammar G ��V, T, S, P� with Type AKA Productions Allowed ● V��S, A, a, b� 0 Any production – no restrictions ● T��a, b� Change 1 (non-terminal symbol) between 2 strings AND ● S� the start element S � λ lAr � lwr Context – ● P��S�aA, S �b, A�aa� 1 sensitive A is a N (non-terminal) symbol lr is a string of T & N symbols (may be λ ) l i t i f T & N b l ( b λ ) Find L�G� w is a string of T & N symbols (can’t be empty) Change 1 non-terminal symbol S � aA � aaa A �lr � 2 Context-free A is a single N terminal symbol lr is a string of T & N symbols (may be λ ) b L(G) = {b, aaa} Change 1 non-terminal symbol � very restricted how it can be changed A �aB; A�a & S�λ 3 regular A & B are non terminal, a is terminal 3 4 Example S � AB �CaBa �cbaba � V��S,A,B,a,b� Productions Type AKA Allowed ● Given P: � T��a,b� 0 no restrictions S�AB Context – S � λ S � P� 1 1. A �Ca sensitive lAr � lwr 2. B �Ba �1�S�Aba, AB � a, Context- A �lr 2 A B free 3. B �Cb �2�S �λ, aAb �aab A �aB; A�a & 3 3 regular regular 4. B �b 4 B b S�λ C a a B �3�S�λ, A�aa 5. C �cb �4�S�λ, A �b 6. C �b c b b G1� type 0, but not type 1 G4� type 3 � � Construct a derivation tree for cbaba ● AB is 2 N symbols We see that cbaba can be derived from: G2� type 1, but not type 2 � S � AB � CaBa � cbaba ● Not a single N symbol �has some T symbols too� Terminal elements are at the G3� type 2, but not type 3 end of each branch so we are done � ● Goes to two T & N strings 5 6 1

  2. Remember Vending Machine Vending Maching I/O and States Table Inputs Outputs Transition – f(s,i) Output – g(s,i) Possible inputs Possible outputs �5�Nickel �N� Nada States 5 O A 5 O A Nickel �5� nothing �N� �O� O‐btn �5� Nickel 0 s 0 s 1 s 0 s 0 N N N �A�‐A‐Btn �OJ� O‐button �O� Nickel �5� 5c s 1 s 2 s 1 s 1 N N N …. �AJ� A‐button �A� OJ 10c s 2 s 3 s 2 s 2 N N N 15c s 3 s 3 s 0 s 0 5 OJ AJ A Directed Graph Possible states It is important to �A, AJ� O know how to go from one initial state s 0 �no money in the machine� to the other �O, N� �O, N� state s 1 �5c in the machine� �O, N� Start �5, N� �5, N� �5, N� s 0 s 1 s 2 s 3 �5, 5� state s 2 �10c in the machine� �A, N� �A, N� �A, N� state s 3 �15 in the machine� �O, OJ� 7 8 What strings are recognized by Going from Graph to Table the following machine s 1 � Only 1 final state s 3 s 1 � Think of all possible paths that O originate at s 0 and end at s 3 Transition– f(s,i) Output – g(s,i) O �1,0� start s 0 s 3 States 0 1 0 1 s 3 s 0 s 0 s 1 s 0 1 0 � We can loop as many times � We can loop as many times �0 0� �0,0� s 1 s 3 s 0 1 1 O as we want, s 2 s 1 s 2 0 1 0 ; 1 s 2 s 2 and then we must follow s 3 s 2 s 1 0 0 �1,1� This says the strings recognized s 1 � Also, be able to determine output by the machine are all of the form Also be able to do this O n 11, with n�0 Example with automaton What is the output of 1110? start s 0 s 3 0001 9 10 Given a automaton determine How is a Non-Deterministic L(M) automaton different? 1 O � M: s 1 Start � Final states: s 2, s 3 0 1 0,1 s 0 s 1 s 2 s 3 0,1 Inputs O O,1 O States 0 1 start s 0 1 s 3 s 0 s 0, s 2 s 3 � There’s only 1 final state �s 2 �. So we look y � 2 � s 0 s 1 , s 3 s 1 s for paths from s 0 to s s 0 , s 2 s 2 1 O s 3 s 0 , s 2, s 2 s 1 s 2 0 1 1 OR 1 s 0 s 2 s 0 s 1 s 2 Notice that the transition function with state s 2 and input 0 produces the empty set of states: f�s 2 , 0� does not give any next state � �� L�M� ��0,01� 11 2

  3. Chapter 1: Chapter 1 � Determine whether this proposition is a � In the questions below write the statement in the form “If … , tautology: ��p � �q� � q� � � p then … .” “The team wins if the quarterback can pass.” p q � p � q p �� q � q � � p If the quarterback can pass, then the team wins. T T F F F F T T F F T T F T Write the contrapositive, converse, and inverse of the following: “You sleep late if it is Saturday” following: You sleep late if it is Saturday T T T F T T F Contrapositive: �q � �p T T T F T F F If you do not sleep late, then it is not Saturday. � Also know how to prove equivalences Converse: q � p and how to show using identities If you sleep late, then it is Saturday. �� know the identities Inverse: �p � �q If it is not Saturday, then you do not sleep late. 13 14 CHAPTER 2 English to Logical Expressions F�x�: x is a fleegle Remember the Cartesian Product? S�x�: x is a snurd Let A��1,2� , B� �a,b,c�, C� �y,z� T�x�: x is a thingamabob What is A x B x C U��fleegles, snurds, thingamabobs� � A x B x C� ��1,a,y�, �1,a,z�, �1,b,y�, �1,b,z�, �1,c,y�, �1,c,z�, �2,a,y�, �2,a,z�, �2,b,y�, �2,b,z�, �2,c,y�, �2,c,z�� “ Everything is a fleegle” ∀ x F�x� � � ∃ x � F�x� � � � � “ Nothing is snurd” ∀ x � S�x� � � ∃ x S�x� “ All fleegles are snurds” ∀ x� F�x� �S�x�� � ∀ x�� F�x� � S�x�� � ∀ x �� F�x� � � S�x�� Thus A x B x C is all possible ordered tuples (a,b,c) where a � A , b � B , and c � C � � ∃ x�F�x� � � S�x�� 15 16 Operations on Sets Inverse Functions (Example) U � �0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10� f ‐1 f A B A B A� �1, 2, 3, 4, 5� a B � �4, 5, 6, 7, 8� a V V b b W A � B� �1, 2, 3, 4, 5, 6, 7, 8� W c c X X A �B � A �B �4, 5� �4 5� d d d d Y Y A c � �0, 6, 7, 8, 9, 10� B c � �0, 1, 2, 3, 9, 10� A ‐ B � �1, 2, 3� A bijection is called invertible because you can define B ‐ A � �6, 7, 8� the inverse function. To be invertible it must be a bijection. A�B � �1, 2, 3, 6, 7, 8� 17 18 3

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend