Ch 2 : Context Free Languages Flashcards
What capability does a context free grammar bring that was not available in a regular langauge?
They can describe certain features that have a recursive structure.
Describe what a context-free language is
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
What is a substitution rule?
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.
What is a derivation?
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
What is a language of a grammar?
It is all strings that are generated in the way we described the derivation above.
What is a grammar?
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 (?)
What are the book’s four tips for constructing CFG’s?
- Break into smaller pieces and ‘or’ together.
- Construct a DFA if its regular and convert
- Remember how two substrings are linked and the machine has to remember one to get the other
- Remember recursion and place variables where they are recursively referenced.
What does it mean for a grammar to be ambiguous?
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.
What is Chomsky normal form?
Every rule in a CNF is of the form:
A -> BC
A -> a
(BC cannot be the start variable, also S-> epsilon is legit)
What are the steps to convert to Chomsky Normal Form?
- Add new start variable
- Take care of all epsilon rules
- Handle all unit rules
- Convert all remaining to proper form
What are steps for creating a PDA from a CFL/CFG?
- put $ on top of stack
- 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 do I prove a language is non-regular?
Use the pumping lemma….. see those cards
What is a DPDA? Why does it matter, where is it used, what does it tell us?
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).
What is the language called that represents a DPDA>
A deterministic context-free language.
Are all CFL’s DCFL’s?
No, absolutely not. Any CFL whose complement isn’t a a CFL isn’t a DCFL