Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

DFA Applications - Automata and Complexity Theory - Lecture Slides, Slides of Theory of Automata

Some concept of Automata and Complexity Theory are Administrivia, Closure Properties, Context-Free Grammars, Decision Properties, Deterministic Finite Automata, Intractable Problems, More Undecidable Problems. Main points of this lecture are: Dfa Applications, Formal Languages, Practical Applications, Computer Programs, Based Text Filter, Java, Table-Driven Alternatives, Programming Language Processing, Command Language Processing, Text Pattern Matching

Typology: Slides

2012/2013

Uploaded on 04/29/2013

juni
juni 🇮🇳

4

(17)

122 documents

1 / 20

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Chapter Four:
DFA Applications
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14

Partial preview of the text

Download DFA Applications - Automata and Complexity Theory - Lecture Slides and more Slides Theory of Automata in PDF only on Docsity!

Chapter Four:

DFA Applications

We have seen how DFAs can be used to define

formal languages. In addition to this formal

use, DFAs have practical applications. DFA-

based pieces of code lie at the heart of many

commonly used computer programs.

DFA Applications

• Programming language processing

  • Scanning phase: dividing source file into "tokens"

(keywords, identifiers, constants, etc.), skipping

whitespace and comments

• Command language processing

  • Typed command languages often require the

same kind of treatment

• Text pattern matching

  • Unix tools like awk, egrep, and sed, mail systems

like ProcMail, database systems like MySQL, and

many others

More DFA Applications

• Signal processing

  • Speech processing and other signal processing

systems use finite state models to transform the

incoming signal

• Controllers for finite-state systems

  • Hardware and software
  • A wide range of applications, from industrial

processes to video games

The Mod3 DFA, Revisited

• We saw that this DFA accepts a language of

binary strings that encode numbers divisible

by 3

• We will implement it in Java

• We will need one more state, since our

natural alphabet is Unicode, not {0,1}

1 2

1

0 0 0

0

1

1

The Mod3 DFA, Modified

• Here, Σ is the Unicode character set

• The DFA enters the non-accepting trap state

on any symbol other than 0 or 1

1 2

1

0 0 0

0

1 1

3 -{0,1} -{0,1}

-{0,1}

static private int delta(int s, char c) { switch (s) { case q0: switch (c) { case '0': return q0; case '1': return q1; default: return q3; } case q1: switch (c) { case '0': return q2; case '1': return q0; default: return q3; } case q2: switch (c) { case '0': return q1; case '1': return q2; default: return q3; } default: return q3; } }

  • Reset the current state to the start state. */ public void reset() { state = q0; }

/**

  • Make one transition on each char in the given
  • string.
  • @param in the String to use */ public void process(String in) { for (int i = 0; i < in.length(); i++) { char c = in.charAt(i); state = delta(state, c); } }

import java.io.*;

/**

  • A Java application to demonstrate the Mod3 class by
  • using it to filter the standard input stream. Those
  • lines that are accepted by Mod3 are echoed to the
  • standard output. */ public class Mod3Filter { public static void main(String[] args) throws IOException {

Mod3 m = new Mod3(); // the DFA BufferedReader in = // standard input new BufferedReader(new InputStreamReader(System.in));

// Read and echo lines until EOF.

String s = in.readLine(); while (s!=null) { m.reset(); m.process(s); if (m.accepted()) System.out.println(s); s = in.readLine(); } } }

Outline

• 4.1 DFA Applications

• 4.2 A DFA-Based Text Filter in Java

• 4.3 Table-Driven Alternatives

Making Delta A Table

• We might want to encode delta as a two-

dimensional array

• Avoids method invocation overhead

• Then process could look like this:

static void process(String in) { for (int i = 0; i < in.length(); i++) { char c = in.charAt(i); state = delta[state, c]; } }

/*

  • The transition function represented as an array.
  • The next state from current state s and character c
  • is at delta[s,c-'0']. / static private int[][] delta = {{q0,q1},{q2,q0},{q1,q2},{q3,q3}}; /*
  • Make one transition on each char in the given
  • string.
  • @param in the String to use */ public void process(String in) { for (int i = 0; i < in.length(); i++) { char c = in.charAt(i); try { state = delta[state][c-'0']; } catch (ArrayIndexOutOfBoundsException ex) { state = q3; } } }

Tradeoffs

  • Function or table?
  • Truncated table or full table?
    • By hand, a truncated table is easier
    • Automatically generated systems generally produce the full table, so the same process can be used for different DFAs
  • Table representation
    • We used an int for every entry: wasteful!
    • Could have used a byte, or even just two bits
    • Time/space tradeoff: table compression saves space but slows down access