This action might not be possible to undo. Are you sure you want to continue?

**CS 410 - Lecture 4 West Virginia University Fall semester, 2002 Frances L. Van Scoy fvanscoy@wvu.edu
**

29 August 2002 4. Left and Right Linear Grammars; Regular Expressions;Scanner Implementation 1

Scanner Implementation 2 . Regular Expressions. and regular expressions are all equivalent in power. a third way of defining some languages (along with grammars and automata).Overview In this lecture we introduce regular expressions. 29 August 2002 4. finite state automata. right linear grammars. Left and Right Linear Grammars. We show some techniques for implementing finite state automata and scanners. We show that left linear grammars.

Regular Expressions. where A and B are in N where A and B are in N and a is in 7 and a is in 7 29 August 2002 4.Definition of Type 3 Grammars (Review) right linear left linear A -> a B or A -> a. A -> B a or A -> a.Scanner Implementation 3 . Left and Right Linear Grammars.

Regular Expressions.A Right Linear Grammar for Identifiers (Review) S -> a T S -> b T S -> a S -> b T -> a T T -> b T T -> 1 T T -> 2 T T -> a T -> b T -> 1 T -> 2 S => a S => a T => a 1 S => a T => a 1 T => a 1 b T => a 1 b 2 29 August 2002 4.Scanner Implementation 4 . Left and Right Linear Grammars.

P. Left and Right Linear Grammars.Constructing a Nondeterministic Finite State Automaton from a Right Linear Grammar Let G = (N. X not in N or 7 F = {X} H is constructed by If A -> a B is in P. 7. S.Scanner Implementation 5 .a) If A -> a is in P. Construct a nondeterministic finite state automaton M = (Q. 7. H. then X is in H (A. S).a) 29 August 2002 4. Regular Expressions. then B is in H(A. F). where Q = N U {X}.

X} H(T.Example: RLG to NDFSA S -> a T S -> b T S -> a S -> b T -> a T T -> b T T -> 1 T T -> 2 T T -> a T -> b T -> 1 T -> 2 H(S. Regular Expressions.Scanner Implementation . X} H(S.b) = {T.2) = {T.1) = {T.X} H(T.b) = {T.a) = {T.X} H(S.X} H(T.1) = * H(S.a) = {T. Left and Right Linear Grammars.X} 6 29 August 2002 4.2) = * H(T.

Left and Right Linear Grammars.A Left Linear Grammar for Identifiers (Review) S -> S a S -> S b S -> S 1 S -> S 2 S -> a S -> b S => a S => S 1 => a 1 S => S 2 => S b 2 => S 1 b 2 => a 1 b 2 7 4.Scanner Implementation 29 August 2002 . Regular Expressions.

then A is in H(B. 7. F).Scanner Implementation 8 . X. then A is in H (X.a) 29 August 2002 4. S). P.a) If A -> a is in P. where Q = N U {X}. 7. Construct a nondeterministic finite state automaton M = (Q. Left and Right Linear Grammars.Constructing a Nondeterministic Finite State Automaton from a Left Linear Grammar Let G = (N. H. Regular Expressions. X not in N or 7 F = {S} H is constructed by If A -> B a is in P.

b) = {S} H(S.2) = * H(S.2) = {S} 9 4.a) 29 August 2002 .1) = * H(X. Left and Right Linear Grammars.b) = {S} H(X.Example: LLG to NDFSA S -> S a S -> S b S -> S 1 S -> S 2 S -> a S -> b = {S} H(X. Regular Expressions.1) = {S} H(S.a) = {S} H(S.Scanner Implementation H(X.

Left and Right Linear Grammars.. 29 August 2002 4.e. If x and y are r.e.Scanner Implementation 10 . then x y is a r. If x is a r. If x is a r. Regular Expressions. Nothing else is a r..Definition of a Regular Expression Definition of a regular expression over alphabet S If a is in S then a is a r.e.e.e.e.e. then ( x ) is a r.. If x and y are r. then x | y is a r.e. then x* is a r.e.e..

Left and Right Linear Grammars. 1+ | P) 29 August 2002 4.Examples of Some Regular Expressions Identifier (a | b) (a | b | 1 | 2)* Real numeric literal 1 1* . 1 1* 1+ .Scanner Implementation 11 . 1+ Numeric literal 1+ ( . Regular Expressions.

a P x If x is a r.Construction of a NDFSA with PTransitions from a RE (1) If a is in S then a is a r.. Regular Expressions. then ( x ) is a r.e.. Left and Right Linear Grammars. P x 29 August 2002 4.e.e. then x* is a r.e.Scanner Implementation 12 . If x is a r.e.

then x | y is a r. then x y is a r.Scanner Implementation 13 . P x P P P If x and y are r. Left and Right Linear Grammars.e..e..e. Regular Expressions. y P x P y P 29 August 2002 4.e.Construction of a NDFSA with PTransitions from a RE (2) If x and y are r.

Left and Right Linear Grammars. Regular Expressions.Scanner Implementation 14 .Construction of a NDFSA from a NDFSA with P-transitions 29 August 2002 4.

Scanner Implementation 15 .Summary of Conversions Is a special case of DFSA NDFSA NDFSA with P-transitions LLG RLG Regular Expression Shown in lecture Not shown in lecture. Regular Expressions. 29 August 2002 4. but true So these six ways of defining a language are equivalent in power. Left and Right Linear Grammars.

Left and Right Linear Grammars. Regular Expressions.The Practical Question How do we implement a finite state automaton? A loop containing a case statement. with one case per state Or Lex (next week·s lectures) 29 August 2002 4.Scanner Implementation 16 .

a) = {S} H(S.Scanner Implementation .b) = {S} H(S. End loop.1) = * H(X.a) State := X.1) = {S} H(S. Regular Expressions. Input(State). Loop case State is when X => Case Input is When a => When b => When 1 => When 2 => End case.2) = {S} 29 August 2002 H(X. When Empty => Case Input is When a => When b => When 1 => When 2 => End case.Example of Implementation = {S} H(X. Left and Right Linear Grammars.b) = {S} H(X. When S => Case Input is When a => When b => When 1 => When 2 => End case.2) = * H(S. 17 4. End case.

Summary 29 August 2002 4. Regular Expressions. Left and Right Linear Grammars.Scanner Implementation 18 .

Regular Expressions. Left and Right Linear Grammars.Quiz 29 August 2002 4.Scanner Implementation 19 .

- 2nd sess comp
- Transactions Journals (11)
- TOCAssigment
- Lec 1 (Automata Theory)
- BGS Users Guide
- Urdu Style
- FirstFollow LL(1) parser
- Paper Format
- cs431ch2rvw
- Parallelisms in Ancient Hebrew Verse
- Lecture 3 an Introduction to SINGULAR
- dataypes
- gs_dps.ps
- A Theoretical Review on SMS Normalization using Hidden Markov Models (HMMs)
- CLess 19 Dataty
- Python Tutorial
- orginal
- Z-Notation
- Turing Machine Notes
- Readme
- BI - Best Practice - Coding & Development
- llncsdoc
- Introduction to the Objective Caml Programming Language - Jason Hickey (Sep 2002)
- Electronic Lexicography in the 21st Century
- Zitierregeln (Englisch)
- software testing
- Programming Language
- Contenidos mínimos
- Chapter 2 - Parallel Programming Platforms
- rr320504-language-processors
- 410L04

Are you sure?

This action might not be possible to undo. Are you sure you want to continue?

We've moved you to where you read on your other device.

Get the full title to continue

Get the full title to continue reading from where you left off, or restart the preview.

scribd