Notes-SecF - COT 4210 Section F Spring 2001 Context-free...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
COT 4210 Section F Spring 2001 Context-free Grammars and Languages Definition 25 . A Context-free grammar (CFG) is a PSG, G = (N, , P, S), where P N G V G *. A production r P is denoted r: X w and means that an occurrence of X can be replaced by w in any context in which X occurs - this is where the term "context free" originates - rewriting X "free of any contextual constraints." NOTE : Context-free grammars were defined by Chomsky to be Phrase Structure grammars with the Type-2 restriction. CFG and Type-2 grammars are synonymous terms. The family of all languages defined by Context-free grammars is called the family of Context- free Languages (CFLs). Example 31. G e = ( {E, T, F, X}, {n,v, +, -, *, /, ( , )}, P, E), where E = { 1: E ’ E + T, 2: E ’ E T, 3: E T, 4: T T F, 5: T ’ T/ F, 6: T F, 7: F +X 8: F X 9: F L X 10: X n, 11: X v, 12: X ( E ), } L(G e ) = { x {n, v, +, -, *, /, ( , )}* | x denotes a well-formed arithmetic expression over the operator symbols {+, , , / } and operand symbols {v, n}allowing parenthesized sub- expressions nested arbitrarily deep.} A derivation of x = (n+v) n L(G e ) is illustrated below. In general, x L(G) may have several distinct derivations. Note : refers to G e [1] E 3 T 4 ’ T F 6 F F 9 ’ X F 12 (E)L F 1 (E+T) F 3 (T+T)L F 6 (F+T)L F 9 (X+T)L F 10 (n+T)L F 6 (n+F) F 9 (n+X)L F 11 (n+v) F 9 (n+v) X 10 (n+v)L n Exercise 14: Show that 3469(10)9(12)169(11)369(10) is also a derivation for (n+v) n in G e . Can you construct yet another derivation for (n+v) n in G e that is distinct from either of the ones already identified? March 28, 2001 Page 61
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Section F Spring 2001 Definition 26. Let G = (N, Σ ,P,S) be a Context-free grammar. A derivation, P* in G is said to be leftmost (rightmost) if and only if every rule of π rewrites the leftmost (rightmost) nonterminal occurring in the sentential form defined at each step. Example 32. Verify that derivation [1] above is a leftmost derivation of (n+v)*n, and [2] is a rightmost derivation of (n+v) n in G e . [2] E 3 T 4 T F 9 T X 10 T*n 6 F*n 9 X*n 12 (E) n 1 (E+T) n 6 (E+F) n 9 (E+X) n 11 (E+v) n 3 (T+v) n 6 (F+v) n 9 (X+v) n 10 (n+v) n π (rightmost) = 349(10)69(12)169(11)369(10) Defintion 27. Let G = (N, Σ ,P,S) be a Context-free grammar. Let x A L(G). A syntax tree for x is a two-dimensional representation of a derivation of x as illustrated in the diagram below. Each rule in the derivation of x that is used to rewrite a non-terminal is expanded as a subtree rooted at the nonterminal (in the figure, X is expanded by the rule: X Y 1 Y 2 …Y n or X λ ). The syntax tree is complete and valid if the root node is the start symbol of G and each nonterminal in the tree is expanded by one of its rules in G. The frontier of a syntax tree is the sequence of leaves (terminal symbols or λ ) enumerated in a left-to-right order. March 28, 2001
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 06/09/2011 for the course COT 4210 taught by Professor Staff during the Spring '08 term at University of Central Florida.

Page1 / 24

Notes-SecF - COT 4210 Section F Spring 2001 Context-free...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online