1 / 27

CSCI 115

CSCI 115. Chapter 10 Languages and Finite State Machines. CSCI 115. §10 .1 Languages. §10 .1 – Languages. From section 1.3: S = Set of “words” S* = collection of sentences formed from S concatenation. §10 .1 – Languages. Languages Proper construction Syntax

adia
Download Presentation

CSCI 115

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. CSCI 115 Chapter 10 Languages and Finite State Machines

  2. CSCI 115 §10.1 Languages

  3. §10.1 – Languages • From section 1.3: • S = Set of “words”S* = collection of sentences formed from S • concatenation

  4. §10.1 – Languages • Languages • Proper construction • Syntax • An dog talked pink martians • Meaningful • Semantics • The boy ate red candy • Programming Languages

  5. §10.1 – Languages • Grammar • A phrase structure grammar G is a 4-tuple(V, S, v0, ) s.t.:V is some finite setS  Vv0  V – S is a finite relation on V* • production relation

  6. §10.1 – Languages • The  relation and related concepts • w  w’ (w, w’  V*) is called a production on V • No production ever has  on the left side •  is a new relation (the substitution relation) • x  y means y results from x via an allowable production (i.e. xy) • x y means y results from x via a finite number of allowable relations • w  S* is syntactically correct iff v0 w

  7. §10.1 – Languages • Other components of the 4-tuple • S is sometimes called the set of terminal symbols • N = V – S is the set of non-terminal symbols • V = N  S • There is a language corresponding to G • L(G) • Always a subset of S* • L(G) is the set of all properly constructed sentences

  8. §10.1 – Languages • Classifying languages and elements • Derivation Trees • Determine if an arbitrary element is a valid element of the language • Description of languages • Finding a template for the valid elements

  9. §10.1 – Languages • Consider a grammar where  is given by: v0  aw aw  c • Sentences cannot be verified by a derivation tree • Grammar typing

  10. §10.1 – Languages • Let G = (V, S, v0, ) be a phrase structure grammar. G is: • Type 0 if no restrictions are placed on productions of G • Type 1 If for all productions w1w2, the length of w1  length of w2 • Type 2 If for all productions the left hand side is a single non-terminal symbol and the right hand side is 1 or more symbols • Type 3 if for all productions the left hand side is a single non-terminal symbol and the right hand side is 1 or more symbols with at most 1 non terminal symbol. If it has a non terminal symbol, it appears on the extreme right

  11. §10.1 – Languages • Programming language compilers are of type 2 or 3 • We will focus on these types • Type 3 grammars are called regular grammars

  12. §10.1 – Languages • Parsing a sentence • Verifying a sentence is syntactically correct by finding a derivation tree (parse tree) • Compiling • Parse sentence into parse tree • Search parse tree, at each step converting the corresponding sentence into another language • Ultimately need machine language

  13. CSCI 115 §10.2 Representations of Special Grammars & Languages

  14. §10.2 – Representations of Special Grammars & Languages • Representations of languages •  (as in section 10.1) • Backus-Naur form (BNF notations) • Syntax Diagrams

  15. §10.2 – Representations of Special Grammars & Languages • BNF Notation • Place left hand side of production on left • Place all possible productions on the right, separated by: | •  is replaced by ::= • Non terminal symbols are placed in < > • Used for clarification • Allows spaces

  16. §10.2 – Representations of Special Grammars & Languages • Syntax Diagrams • Arrows – direction to travel to complete a substitution • Symbols in boxes – non terminal symbols • Symbols in circles – terminal symbols • Components of diagrams • Sequence, selection, iteration

  17. §10.2 – Representations of Special Grammars & Languages • Syntax Diagrams • Sequence • w::= <w1><w2><w3> (BNF Notation) has the following syntax diagram:

  18. §10.2 – Representations of Special Grammars & Languages • Syntax Diagrams • Selectionw ::= <w1> | a (BNF Notation) has the following syntax diagram

  19. §10.2 – Representations of Special Grammars & Languages • Syntax Diagrams • Iterationw ::= a<w> | a (BNF Notation) has the following syntax diagram

  20. §10.2 – Representations of Special Grammars & Languages • Master Diagrams • Combine the various syntax diagrams of a language into one comprehensive diagram • Involve only v0 and terminal symbols • Are usually too cumbersome to be useful

  21. §10.2 – Representations of Special Grammars & Languages • There is the following correlation between regular expressions (section 1.3) and the components of a regular grammar • Discussion starts on page 399 of section 10.2 • We will not cover in this class

  22. CSCI 115 §10.3 Finite State Machines

  23. §10.3 – Finite State Machines • Machine • A machine is a system that accepts input, produces output, and has memory to keep track of previous inputs (which many be manipulated) • State • A state is the complete internal condition of the machine (i.e. the memory) • Affects reaction to subsequent I/O

  24. §10.3 – Finite State Machines • Finite State Machine (FSM) • A machine that has a finite number of states • Example: computer

  25. §10.3 – Finite State Machines • Assume we have the following: • S = {s0, s1, …, sn} is a set with n elements • A finite set I • xI,  fx:SS. • Let F = {fx | x  I} • Then (S, I, F) is a finite state machine

  26. §10.3 – Finite State Machines • Given (S, I, F) is a FSM, we have the following: • S is the state set • si is a state  si  S • I is the input set •  x  I, fx describes the effect the input x has on the state of the machine • State transition function • If the machine is in state si and the input x occurs, the next state is fx(si) • State transition table – matrix showing the effects of the various inputs on the various states

  27. §10.3 – Finite State Machines • Relation arising from finite state machines • If M is the FSM (S, I, F) then define RM as follows: • RM is a relation on S • si RMsjiff  x  I s.t. fx(si) = sj • Edges in the digraph of RM are labeled with all inputs that create that state transition • We will not be covering Moore Machines, Machine Congruences, or Quotient Machines

More Related