Ch 2 : Context Free Languages Flashcards

1
Q

What capability does a context free grammar bring that was not available in a regular langauge?

A

They can describe certain features that have a recursive structure.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Describe what a context-free language is

A

It is the collection of languages associated with context-free grammars.

It includes all the regular languages, and many others.

Context free languages are recognized by pushdown automata

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a substitution rule?

A

also called a production, it is written with the symbol left of the arrow indicating a variable and a string on the right side of the arrow, the string on the right side can be terminals or other variables, including the one on the left side of the arrow. The terminals are analogous to the input alphabet. At the leftmost part of the top rule is the start variable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a derivation?

A

the sequence of substitutions to obtain a string. can be shown pictorially with a parse tree, or via derivation type writing. Start with the top variable, continually replace all the variables on the right with the corresponding right side of a rule that has that variable on the left. Keep doing that until there are no variables left. All that remains will be a string. That string was derived from the grammar

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a language of a grammar?

A

It is all strings that are generated in the way we described the derivation above.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a grammar?

A

A list of rules containing variables and terminals. The terminals are the input string and the variables are how you can replace symbols according to the rules (?)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the book’s four tips for constructing CFG’s?

A
  1. Break into smaller pieces and ‘or’ together.
  2. Construct a DFA if its regular and convert
  3. Remember how two substrings are linked and the machine has to remember one to get the other
  4. Remember recursion and place variables where they are recursively referenced.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does it mean for a grammar to be ambiguous?

A

It derives the same string in different ways, in other words, it has two or more left-most derivations or parse trees.

Because the derivations could be different based on the orders of the variable replacement, really we mean the parse trees and thus throw down with left most as the standard.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is Chomsky normal form?

A

Every rule in a CNF is of the form:
A -> BC
A -> a

(BC cannot be the start variable, also S-> epsilon is legit)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the steps to convert to Chomsky Normal Form?

A
  1. Add new start variable
  2. Take care of all epsilon rules
  3. Handle all unit rules
  4. Convert all remaining to proper form
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are steps for creating a PDA from a CFL/CFG?

A
  1. put $ on top of stack
  2. Repeat forever…..
    a. if top of stack is a $, enter accept (accepts the input if it’s all been read)
    b. if top of stack is a terminal, read the next input and match it. continue if matches, fail if not.
    c. if top of stack is a variable, nondeterministically select one of the rules for A and substitute it with one of the rules on the right side of A.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How do I prove a language is non-regular?

A

Use the pumping lemma….. see those cards

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is a DPDA? Why does it matter, where is it used, what does it tell us?

A

Deterministic Push Down Automata.

Unlike DFA’s and NFA’s which are equivalent, PDA’s are not equivalent across DPDA’s and NPDA’s.

But DPDA’s are really practical especially in parsers for programming languages.

DPDA’s have at most one way of moving forward (no choice, or guess).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the language called that represents a DPDA>

A

A deterministic context-free language.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Are all CFL’s DCFL’s?

A

No, absolutely not. Any CFL whose complement isn’t a a CFL isn’t a DCFL

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the meaning and use of end markers?

A

A is a DCFL if and only if A -| is a DCFL. Adding end markers doesn’t change the power of DPDA’s, however, designing DPDA’s on endmarked inputs is often easier because we take advantage of knowing when the string ends.

17
Q

What is the relationship between DCFG and DPDA’s

A

They are equivalent provided that we restrict our atttentionto endmarked languages. The equivalence does NOT hold without the endmarkers.

18
Q

How does defining DCFG’s differ from deriving CFG’s?

A

They go from the bottom up.

19
Q

What is a reduce step? How does it relate to a substitution?

A

A reduction is the entire process of reversed derivations. Basically a reduce step is a reversed substitution.

strings of terminals from the right side are replaced by the variable on the corresponding left hand side.

20
Q

How do reductions and reverse derivations relate?

A

A leftmost reduction is a right most derivation in reverse.

21
Q

What is a handle?

What is a valid string?

A

h, which is the reducing string in a in leftmost reduction of w, which is the equivalent of T-> h is applied in reverse.

h, together with its reducing rule T is called the handle.

A valid string is a string that appears in a leftmost reduction of some string in L(G)

22
Q

How do handles relate to ambiguity?

A

If a grammar is ambiguous, a valid string can have several handles. For unambiguous grammars, the left most reductions, (only one parse tree) are unique, as well as the handles.

23
Q

How are handles related to the definition of deterministic context free grammars?

A

As we read from left to right, once we’ve seen the handle, we have to KNOW it. and we don’t need to read beyond. A handle is a forced handle if h is the unique handle in every valid string xhy

A DCFG is a CFG such that every valid string has a forced handle.

24
Q

Pickup again on page 139

A

….[INSERT]

25
Q

What is the definition of a string being a prefix, a proper prefix, and a language being prefix free?

A

First, a language is just a set of strings.

x is a prefix of y if z exists such that xz = y….

x is a proper prefix if x != y

A language is prefix-free if no member is a proper prefix of another member.

26
Q

What is a deterministic context free grammar?

A

DCFG’s are those who’s reductions have a certain property. That property is that every valid string has a forced handle.

A DCFG is a CFG such that every string has a forced handel.

27
Q

What is the definition of a context free grammar?

A

The 4-tuple of the following …

(V, E, R, S)

V : finite set of variables
E : finite set of terminals disjoint from V
R is a finite set of rules, each rule being a variable and a string of variables and terminals
S is the start variable.

28
Q

Why are grammars called context free?

A

Derivation of single step does not depend on context of occurrence of a given variable.

29
Q

𝑢𝐴𝑣⇒𝑢𝑤𝑣 (𝑢𝐴𝑣 yields 𝑢𝑤𝑣): 𝑢,𝑣∈(𝑉 ∪ Σ)*, 𝐴→𝑤 a production of 𝐺

A

A derives w, and we do it in any context, u v, we can do it the same in any context. This is why called context free.

30
Q

𝐿𝐺=𝑤∈Σ∗𝑆∗⇒𝑤} the language generated by the context free grammar 𝐺

A

Language of our grammar consists of those terminal strings which can be derived in some finite amount of steps out of the start symbol

31
Q

Does CNF remove ambiguity?

A

No, as any grammar can be put in CNF

32
Q

How’s a PDA like an NFA?

A

A PDA is a NFA with a stack

33
Q

What implications and inclusions do we need to show to prove that we’ve got appropriate and equivalent (PDA/NFA, etc.)

A
  1. If string is of that form, then our PDA/NFA accepts…

2. If our PDA/NFA accepts, then our string is of that form.