Download presentation
Presentation is loading. Please wait.
Published byLauren Hamilton Modified over 9 years ago
1
September1999 CMSC 203 / 0201 Fall 2002 Week #14 – 25/27 November 2002 Prof. Marie desJardins clip art courtesy of www.dumpty.com
2
September1999 MON 11/25 LANGUAGES AND GRAMMARS (10.1)
3
September1999 October 1999 Concepts/Vocabulary Formal language, syntax, semantics Vocabulary (alphabet) V, word (sentence) V*, language V* Phrase-structure grammar G=(V,T,S,P) Alphabet V; terminal symbols T V; nonterminal elements N=V-T; start symbol S N; productions P: {x y: x, y V*} Derivation * (sequence of productions) Derivation tree / parse tree L(G): {w T*: S * w}
4
September1999 October 1999 Concepts/Vocabulary cont. Types of grammars: Type 0: no restrictions Type 1 (context-sensitive): productions must be w 1 or w 1 w 2 where w 2 has length w 1 Type 2 (context-free): All productions must have w 1 N (single symbol) Type 3 (regular): All productions must have w 1 N and w 2 N or w 2 =aB where B N (Top-down parsing, bottom-up parsing) (Backus-Naur form)
5
September1999 October 1999 Examples Find a phrase-structure grammar for each of the following languages: (a) the set of all bit strings containing an even number of 0s and no 1s (e) the set of all strings containing more 0s than 1s (g) the set of all strings containing an unequal number of 0s and 1s Show a derivation tree for the string 00110010 from the grammar given in (g)
6
September1999 October 1999 Examples II Exercise 23(a): Construct a phrase-structure grammar that generates all signed decimal numbers, consisting of a sign, either + or -; a nonnegative integer; and a decimal fraction that is either the empty string or a decimal point followed by a positive integer, where initial zeros in an integer are allowed. Consider the 4 PSGs we’ve constructed. What type is each?
7
September1999 WED 11/27 FINITE-STATE MACHINES (10.2)
8
September1999 October 1999 Concepts/Vocabulary Finite-state machine M=(S,I,O,f,g,s 0 ): States S, input alphabet I, output alphabet O, transition function f: S I S, output function g S I g, initial state s 0 S State table, state diagram (Mealy machines, Moore machines)
9
September1999 October 1999 Examples Vending machine model (Table 1) Draw a state diagram for the vending machine Draw a state diagram to recognize the signed decimal integer grammar from Exercise 23(a) Exercise 10.3.7: Construct a FSM that delays an input string two bits, giving 00 as the first two bits of output.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.