Background - PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

Background

Description:

Background Previously discussed RL closure properties. Now look at CFL closure properties. Reminder: Why are closure properties useful? Decompose model construction. – PowerPoint PPT presentation

Number of Views:82
Avg rating:3.0/5.0
Slides: 16
Provided by: unt47
Learn more at: http://www.cse.unt.edu
Category:

less

Transcript and Presenter's Notes

Title: Background


1
Background
  • Previously discussed RL closure properties.
  • Now look at CFL closure properties.
  • Reminder Why are closure properties useful?
  • Decompose model construction.
  • Simplify proofs of regularity.
  • Simplify proofs of non-regularity

2
Union
  • L L ? L

3
Concatenation Closure
  • Easy CFG constructions, like union.
  • L L L Combine CFGs, add S ? SS.
  • L L Combine CFGs, add S ? ? SS.

4
Intersection
  • L L ? L

L not necessarily context-free. CFLs not closed
under intersection!
5
Intersection Counterexample
  • L ai bi cj i,j?0
  • L ai bj cj i,j?0
  • L L ? L ai bi ci i?0

6
Complementation
7
Complementation
CFLs are not closed under complemention.
Proof by contradiction. If CFLs were closed
under complementation, they would also be closed
under intersection by DeMorgans laws.
8
Chomsky's Hierarchy
The Chomsky Hierarchy is a hierarchy of types of
grammars where Type k grammars are a subset
of Type k-1 grammars but not the other way
around As we go down the hierarchy, grammars
are more restricted languages they define are
simpler computing machines required to
recognise languages simpler
9
Regular Grammars
Type 3 are the Regular Grammars The right-hand
side of productions may be only a single
terminal symbol or a single non-terminal
followed by a single terminal These languages
can be recognised by finite state automata
10
Context-free Grammars
Type 2 are the Context-free Grammars. Productions
have the form... A B where A is a single
non-terminal, B is some sequence of terminals and
non-terminals This is the typical class for many
programming languages including tiny and
micro Stack automata (Push-down automata (PDA))
can recognise such languages (i.e. An automaton
with a stack memory) Parsers for such languages
either explicitly or implicitly use a stack
11
Context-sensitive Grammars
Type 1 are the Context-sensitive Grammars.
Productions can have the form P A S P B
S but the added restriction is that A is
grammatically shorter than B This means that
derivation steps will grow longer
12
Context-sensitive Restrictions
Some constraints in programming languages are
context-sensitive e.g. Variables must be
declared before being used Since these can't be
defined in CFGs, they are left to semantic
analysis The semantic analyser will operate in
collaboration with the parser and use symbol
table information
13
Context-sensitive Example
The language anbncn n gt 0 has valid
sentences abc, aabbcc, aaabbbccc, etc. It
can't be defined by a CFG, but it can by this
CSG S a S B C S a b C C B B C b B b b b
C b c c C c c
14
Unrestricted Grammars
Type0 are the Unrestricted Grammars. Productions
can have the form... P A S P B S where A
is some non-terminal, P, S and B are sequences
that may involve terminals and non-terminals Noti
ce that its context-sensitive. The one
restriction is that the left-hand side of a
production can't be null (i.e. Nothing can't be
something!) A Turing Machine is required to
recognise such languages
15
Summary
Type 0 and Type 1 grammars are hard to
understand and there are no simple techniques for
building compilers for the languages they
define Type 3 grammars are too restrictive and
cannot define languages with recursive
contructs. Type 2 Context-free Grammars
support recursive descent parsing syntax-direc
ted translation compilers can be automatically
generated for these langauges
Write a Comment
User Comments (0)
About PowerShow.com