210 likes | 449 Views
Context-free Grammars. Recursive definition Grammar Derivation. What is the syntax of the description (meta-language)? External form of the grammar How do we associate a language with such a description? Semantics or use of the grammar
E N D
Context-free Grammars L4CFG
Recursive definition • Grammar • Derivation L4CFG
What is the syntax of the description (meta-language)? • External form of the grammar • How do we associate a language with such a description? • Semantics or use of the grammar • Generators: Grammars specify languages by generating strings in the language. • Recognizers: Grammars can be viewed as a notation for describing a family of recognition algorithms. L4CFG
CFG = (V, ,P,S) • V : Finite set of variables/non-terminals • : Alphabet/Finite set of terminals • P : Finite set of rules/productions • S : Start symbol L4CFG
a* represents a context-free language because we can write a CFG for it. • A-rule, null-rule, -rule. • Context-freeness: An A-rule can be applied whenever A occurs in a string, irrespective of the context (that is, non-terminals and terminals around A). • Cf. context-sensitive grammar (“declare-use”) L4CFG
From CFG to Language • One-step Derivation (Defn: 3.1.2) • w is derivable from v in CFG, if there is a finite sequence of rule applications such that: L4CFG
Let G=(V, S, P, S) be a CFG. • is a sentential form, if . • is a sentence, if . • The language of G, L(G) = L4CFG
S S a a b b • Derivation of aabb • Derivation tree l L4CFG
Derivation Tree (abstracts derivation) S A B A B b a l l L4CFG
Examples: CFGs and CFLs L4CFG
Note that parentheses are part of the meta-language. L4CFG
Regular Grammar • A regular grammar is a CFG in which each of the rules has the form: (Right Linear Grammar) L4CFG
Equivalent Regular Grammar • A regular grammar is a CFG in which each of the rules has the form: (Left Linear Grammar) L4CFG
Derivations Note that the above result does not hold for sentential forms. L4CFG