Download presentation
Presentation is loading. Please wait.
Published byRosemary Stanley Modified over 8 years ago
1
Regular Languages REGULAR LANGUAGES (AKA TYPE 3) REGULAR GRAMMARS FINITE STATE MACHINES
2
Grammar English (subset) | “a” | “the” “large” | “hungry” “rabbit” | “mathematician” “eats” | “hops” “quickly” | “wildly” Key: Terminals non-terminals start symbol the hungry rabbit eats wildly // will parse a mathematician quickly hops // will not parse the large hungry rabbit hops quickly // only 1 adjective is allowed
3
Phase Structure Grammars
4
Regular Vocabulary Example boolean ENGLISH(String word) { if (word is in English language) return true; else return false; } Example ENGLISH(‘dog’) would return true ENGLISH(‘xyz’) world return false
6
Finite Automata In theory of computation, a branch of theoretical computer science, a deterministic finite automaton (DFA)—also known as deterministic finite accepter (DFA) and deterministic finite state machine—is a finite state machine that accepts/rejects finite strings of symbols and only produces a unique computation (or run) of the automaton for each input string. 'Deterministic' refers to the uniqueness of the computation. - Finite number of states - A start state - Acceptable states (double circle) - Unacceptable states (single circle) - Read input left to right and move from state to state
8
State = “good” c = readNext(s); if (c != ‘a’) { state = “no good”; } c = readNext(s); if (c != ‘b’) { state = “no good”; } while (c == ‘b’) { c= readNext(s); } // keep reading b’s if (c != ‘a’) { state = “no good”; } c = readNext(s); if (c != ‘eof’) { state = “no good”; } return state;
9
a a a b a,b b b b a
10
The program needed 1 variable for the state and the ability to read the input string. It’s final state is the output of the program. The FA really did the same thing. The circles are the various states (single circle mean’s “no good” and double circle means “good”) and the arrows tell what state to go to next for each possible input value.
11
Language notation
12
Regular Finite Automata
13
UNIX grep command globally search a regular expression and print created by Ken Thompson in 1974. Used to search files for strings matching regular expressions. grep “McDonald’s" myfile.txt grep McD*s myfile.txt grep apple *.txt
14
Regular Grammar
15
Regular Language Enumerated
16
Regular equivalence Languages = Expressions = FSA Regular languages are depicted to regular expressions Regular languages are accepted by a FSA (finite state automata) with no memory needed. Regular languages have a left linear grammar to describe them. (and all right linear grammars have a corresponding left-linear grammar)
17
Consider the language a a b a b b
18
Left/Right linear grammars Left Linear Grammar (all terminals are on the left side of non-terminals) S AB A aA | a B bB | b Right Linear Grammar(all terminals are on the left side of non-terminals) S AB A Aa | a B Bb | b
19
Consider the language a b a b a b b b b ………………..…… …
20
FA with additional memory You may notice that with a state variable and a count variable counting up the number of a’s read and then counting down the number of b’s read to see if they match would solve this language. Therefore we need - a state machine - some memory
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.