TOC Notes Endsem
TOC Notes Endsem
Set of rules
V –> Variables / Non terminals
T Terminals
P Production rules
S Start symbol
Type 3 regular languages
No need as
(a+b)* covers
a^n.b^n
R =Reverse
Context free grammers
Sentential forms
sentential form is a string of symbols (both terminals and nonterminals)
derived from the start symbol of a context-free grammar (CFG) through
a sequence of replacement operations, known as derivations.
Formal Definitions
S → a | S + S | S ∗ S | (S)
1.
Addressing Ambiguity
There are several approaches to addressing ambiguity in CFGs:
●
Rewriting the Grammar: The most desirable approach is often to rewrite the grammar to
eliminate ambiguity. This may involve introducing new variables and productions to enforce
the desired interpretation.
●
Precedence and Associativity Rules: In grammars for expressions, ambiguity can be
resolved by explicitly specifying precedence and associativity rules for operators. This
approach is illustrated in the unambiguous grammar for Expr.
●
Parser-Based Disambiguation: If rewriting the grammar is not feasible, the parser can be
designed to handle the ambiguity by applying specific disambiguation rules. However, this
approach can be complex and less desirable than having an unambiguous grammar.
Definition
Properties
1. Non-Regular Languages:
o CFLs are more powerful than regular languages.
2. \
3. Closure Properties:
o CFLs are closed under the following operations:
Union: The union of two CFLs is a CFL.
Concatenation: Concatenation of two CFLs results in a CFL.
Kleene Star: Repeating a CFL zero or more times gives a CFL.
4. Non-Closure Properties:
o CFLs are not closed under:
Intersection: The intersection of two CFLs may not be a CFL.
Complement: Complementing a CFL may not result in a CFL.
Difference: Subtracting one CFL from another may not yield a CFL.
Key Theorems
Applications of CFLs
1. Programming Languages: CFGs define the syntax of programming languages.
2. Compiler Design: Parsing (breaking code into components) relies on CFGs and
PDAs.
3. Natural Language Processing (NLP): Models syntactic structures of languages.
4. Formal Verification: Specifies and verifies system behavior using CFLs.
Simplification
Remove null production A epsilon
Remove unit procuctions
A B , both side single non terminal
Remove useless
Normalization of CFG
First step is to minimize using steps shown
Then you can do CNF/GNF
CNF (Chomsky normal form)
V AB / a
If a CFG is CNF, then if we try to constrict a word of length n then exactly 2n-1
steps are required
Greiback normal form
https://youtu.be/oCBi3g0N358?si=-eBQbPb27VO_dzeE
Recursive and recursively enumerable languages
Twos complement tm
rL all deciadavle
CFL membership finiteness emptiness