Pushdown Automata and Turing Machine - Lecture Notes | CMSC 330, Study notes of Programming Languages

Material Type: Notes; Class: ORGNZTN PROGM LANG; Subject: Computer Science; University: University of Maryland; Term: Unknown 1989;

Typology: Study notes

Pre 2010

Uploaded on 02/13/2009

koofers-user-alr
koofers-user-alr 🇺🇸

10 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
CMSC 330: Organization of
Programming Languages
Pushdown Automata and
Turing Machines
CMSC 330 2
Last Lecture
Parsing
Recursive descent
FIRST sets
Rewriting grammars
Left factoring
Eliminating left recursion
Question
Where do regular expressions and context free
grammars stand in the world of complexity?
CMSC 330 3
This Lecture
Regular grammars
Pushdown automata
Turing machines
Decidability
Turing tests
CMSC 330 4
Regular Expressions and CFGs
Regular grammar
Subset of context free grammar
All productions are of the form
¾
A aB // 1 terminal followed by 1 nonterminal
¾
A a // 1 terminal
Regular grammars are just as powerful as
regular expressions
For any regular expression R, there is a regular
grammar G that accepts the exact same language
CMSC 330 5
Equivalence of DFA and Regular Grammar
Reducing DFA to regular grammar
CMSC 330 6
Equivalence of DFA and Regular Grammar
Reducing regular grammar to DFA
pf3
pf4

Partial preview of the text

Download Pushdown Automata and Turing Machine - Lecture Notes | CMSC 330 and more Study notes Programming Languages in PDF only on Docsity!

CMSC 330: Organization of

Programming Languages

Pushdown Automata and

Turing Machines

CMSC 330 2

Last Lecture

Parsing

  • Recursive descent
  • FIRST sets

Rewriting grammars

  • Left factoring
  • Eliminating left recursion

Question

  • Where do regular expressions and context free grammars stand in the world of complexity?

CMSC 330 3

This Lecture

Regular grammars

Pushdown automata

Turing machines

Decidability

Turing tests

CMSC 330 4

Regular Expressions and CFGs

Regular grammar

  • Subset of context free grammar
  • All productions are of the form ¾ A → aB // 1 terminal followed by 1 nonterminal ¾ A → a // 1 terminal

Regular grammars are just as powerful as

regular expressions

  • For any regular expression R, there is a regular grammar G that accepts the exact same language

CMSC 330 5

Equivalence of DFA and Regular Grammar

Reducing DFA to regular grammar

CMSC 330 6

Equivalence of DFA and Regular Grammar

Reducing regular grammar to DFA

CMSC 330 7

Regular Expressions and CFGs

CFGs are strictly more powerful than REs

  • Since CFGs are superset of regular grammar

This is good, since programming languages are

not regular

  • No regular expression for ( n^ ) n

But programming languages are usually

(almost) context-free

  • With a few language constructs being exceptions

CMSC 330 8

Regular Expressions and CFGs

We can implement REs with DFAs

Question

  • How can we implement CFGs?

Description Machine

context-free grammars

context-free languages

regular DFAs, NFAs expressions

regular languages

pushdown automata (PDAs)

CMSC 330 9

Pushdown Automaton (PDA)

A PDA is an abstract machine similar to a DFA

  • Has a finite set of states
  • But also has a stack 1 0 1 1 q 1 q (^2) 0

(^0 ) 1

CMSC 330 10

Moves of a PDA

Reads

  • An input symbol is read
  • Top symbol on the stack

Based on both inputs, the machine

  • Enters a new state, and
  • Writes zero or more symbols onto the pushdown stack
  • Or pops zero or more symbols from the stack

String accepted if

  • The stack is empty, AND
  • The string has ended

CMSC 330 11

Power of PDAs

PDAs are more powerful than DFAs

  • a n^ b n^ , which cannot be recognized by a DFA, can easily be recognized by the PDA ¾ Stack all a symbols and, for each b, pop an a off the stack. ¾ If the end of input is reached at the same time that the stack becomes empty, the string is accepted

PDAs can recognize some L(CFG)

  • Table-driven predictive parser ¾ Table = Finite automaton ¾ Stack = Stack
  • Limited to LR(1) grammars in general

CMSC 330 12

Power of PDAs and NDPDA

There are also nondeterministic PDA (NDPDA)

  • NDPDA are more powerful than DPDA
  • NDPDA can recognize even length palindromes over {0,1}, but a DPDA cannot. Why? ¾ Hint: Consider palindromes over {0,1}2{0,1}* vs {0,1}* {0,1}*

NDPDAs can recognize all L(CFG)

  • Equivalent in power to context-free languages

CMSC 330 19

“Enhanced” Turing Machines

Attempts to increase power of Turing machine

  • Additional tapes
  • Additional tape heads
  • 2-dimensional tape
  • BlueGene/L @ Livermore Lab ¾ World’s fastest computer in 2007 ¾ 106K IBM PowerPC nodes (596 x10 12 Flops)

Turns out any computation on enhanced machine

  • Can be computed on standard Turing machine
  • Though may require more time

CMSC 330 20

Computability

Computability

  • A language is computable if it can be recognized by some algorithm with finite number of steps

Church-Turing thesis

  • Turing machine can recognize any language computable on any machine

Intuition

  • Turing machine captures essence of computing ¾ Both in a formal sense, and in an informal practical sense

CMSC 330 21

Computability – Turing Test

Turing Test

  • Test machine’s capability to demonstrate intelligence
  • Proposed by Alan Turing in 1950
  • Practical test for “Can machines think?”

Test procedure

  • Judge converses via text (e.g., instant messaging)
  • Pass if can’t reliably tell whether machine or human

CMSC 330 22

More Turing Tests

“On the Internet,

nobody knows

you’re a dog.”

CMSC 330 23

Computability – Reverse Turing Test

Reverse Turing test

  • Computer determines whether human or machine

CAPTCHA

  • Completely Automated Public Turing test to tell Computers and Humans Apart
  • Challenge-response asking for word identification ¾ Useful for foiling scripts

CMSC 330 24

More Reverse Turing Tests