1 / 9

Fundamentals of Languages and Grammars

Explore formal language concepts like syntax, semantics, and phrase-structure grammar. Understand types of grammars and finite-state machines with practical examples and exercises.

haroldheath
Download Presentation

Fundamentals of Languages and Grammars

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CMSC 203 / 0201Fall 2002 Week #14 – 25/27 November 2002 Prof. Marie desJardins clip art courtesy of www.dumpty.com

  2. MON 11/25LANGUAGES AND GRAMMARS (10.1)

  3. 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. Concepts/Vocabulary cont. • Types of grammars: • Type 0: no restrictions • Type 1 (context-sensitive): productions must be w1 or w1w2 where w2 has length  w1 • Type 2 (context-free): All productions must have w1N (single symbol) • Type 3 (regular): All productions must have w1N and w2N or w2=aB where B N • (Top-down parsing, bottom-up parsing) • (Backus-Naur form)

  5. 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. 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. WED 11/27FINITE-STATE MACHINES (10.2)

  8. Concepts/Vocabulary • Finite-state machine M=(S,I,O,f,g,s0): • States S, input alphabet I, output alphabet O, transition function f: SIS, output function g SIg, initial state s0S • State table, state diagram • (Mealy machines, Moore machines)

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

More Related