


















































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Description about Context Free Grammars, Reading assignment, Non-Determinism, PDA Push Down Automata, Eliminating non-generative symbols, Modifying productions.
Typology: Study notes
1 / 58
This page cannot be seen from the preview
Don't miss anything!



















































Grammar : Grammar is a recursive definition of Language (Natural or Programming) Formally : Grammar G = {V,T,P,S} Terminals : Basically T = ∑ Variables : Non terminal symbols that represent sets of strings being defined recursively Start Symbols S : S belongs to V and is a special symbol that generates the desired language Production rules P : Recursive definitions Note : T, V and P are always finite sets.
eq Example : The grammar: G eq
P = { S ε|oA|1B A 1S|0AA B 0S|1BB} Notations : For set of rules A α 1 , A α 2 , A α 3 Short cut: A α 1 | α 2 | α 3
Language of CFG G = {V, T, P, S} is defined as Context Free Language is any language which has a Context Free Grammar G Terminology: Sentence : Any w Є T* such that S => w Sentential form : any α Є (V U T)* such that S => α Terminals : a, b, c… Variables : A, B, C, … Terminal Strings : …, u, v, w, x, y, z V U T : …, X, Y, T Sentential Form : α, β, γ, …
Reading assignment: From Textbook, ( nd edition,) Theorem 5.7 (which talks about language of palindromes) Example : Arithmetic Expressions G = {V, T, P, S} V = {E, I} S = E; T = { x, y, z, +, , (, )} P = { E I|(E)|E+E|EE I x|y|z } Apply : E => E+E => E+EE => I+EE => x+E*E
Left-most derivation : Always substitute the leftmost variable with a production rule in sentential form arising in course of a derivation. Notation : Example : E => E+E => I+E => x+E…. Similarly : We can define right-most derivations Example : E => E+E => E=EE => E=EI…. Now we can talk about canonical derivation sequence and
Derivation Trees : Also called as parse trees in compilers Idea is to represent the derivation pictorially This tree represents the derivation x+y*z In General to represent A => α (^) Root labeled A (^) Leaves in left to right order gives α (^) Internal nodes are labeled with variables and their children specify the production rule
Leftmost derivation(lm) is obtained by traversing the tree in depth-first order always going into left subtrees before right one’s Similarly , Rightmost derivation(rm) comes from depth-first traversal going into right subtrees first.
Claim : Following are all equivalent statements. For CFG G = (V, T, P, S) and string w Є T* a)w Є L(G) b)S =(LM)=> w c)S =(RM)=> w d)There exists an S-tree which yields w Of course : we could always use leftmost derivations to specify a simplest way to derive any w belonging to L(G) or convert parse tree to unique derivations – Thus simplifying the task of parsers. But , what if some w belonging to L(G) has two
Definition : A CFG is ambiguous if for some w Є L(G), there exists more than one distinct parse tree. In compilers parse trees determine interpretation and we cannot allow ambiguity. Of course we can force use of parenthesis, but we should really redesign the grammar to be unambiguous by encoding precedence of operators. (See textbook for redesigning of grammars)
Definition : A CFG is called Inherently Ambiguous if all its grammars are ambiguous. Example : L = {a n b n c m d m | n,m≥1} U {a n b m c m d n | n,m≥1} Consider the strings of the form a k b k c k d k , (^) We can never tell whether this string came from first or second type of strings in L and any CFG must allow both of these possibilities.
Setup : A PDA on transition 1.Consumes an input symbol 2.Goes to a new state(or stays in the old) 3.Replaces top of the stack by any string (does nothing, pops the stack or pushes a string onto the stack) Push Down Automata (PDA) is essentially an ε-NFA
Stack Notation Content : (top)ABBAC(bottom) Pop : returns A; new content BBAC Push(XYZ) : new content XYZBBAC Transitions : Determined by : Input or ε-move Current state Stack top Effect : New state Pop Push new string
Transition function : δ takes as argument a triple given as Suppose we have δ(q, a, X) then
: { } 2 Q Q
Action : First PDA pops stack top to determine X, reads input to determine a (unless it is an ε-transition) then knowing q, a, X it selects non-deterministically one of the possibilities of (p i , α i ) Finally : State : goes from q to p i Input : scans past a (unless a = ε) Stack : Loses old top symbol X but gets α i pushed onto it. Note : We thus need Z 0 on stack initially to allow the first transition to pop the stack Convention : String in Σ
: … x, y, z