Context-free Grammars cs466(Prasad) L4CFG
Recursive definition Grammar Derivation cs466(Prasad) 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. cs466(Prasad) 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 cs466(Prasad) L4CFG
A-rule, null-rule, -rule. 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”) cs466(Prasad) 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: cs466(Prasad) 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) = Normally, parenthesis is used in the meta-language for grouping. Parenthesis can be used as a terminal too: “(“ for a and “)” for b. cs466(Prasad) L4CFG
Derivation of aabb Derivation tree S a b S a b l cs466(Prasad) L4CFG
Factor left-hand side using syntax for alternatives |. cs466(Prasad) L4CFG
Derivation Tree (abstracts derivation) l l cs466(Prasad) L4CFG
Examples: CFGs and CFLs cs466(Prasad) L4CFG
Constructive definitions : systematic buldup vs declarative definitions : generate and test Same numeric variable = equality constraint; Different variables independence; TEMPLATE for sequencing of letters cs466(Prasad) L4CFG
are part of the meta-language. Parenthesis is a part of the meta-language here. Note that parentheses are part of the meta-language. cs466(Prasad) L4CFG
CFG: Ease of understanding vs RG: Efficient left to right generation of string cs466(Prasad) L4CFG
cs466(Prasad) L4CFG Pi is concatenation. Same numeric variable = equality constraint; Different variables independence; TEMPLATE for sequencing of letters cs466(Prasad) L4CFG
Left to right generation of string. CFG: Ease of understanding vs RG: Efficient left to right generation of string Left to right generation of string. cs466(Prasad) L4CFG
Regular Grammar A regular grammar is a CFG in which each of the rules has the form: (Right Linear Grammar) Left linear grammar A-> Ba Cannot mix A->Ba and A->aB rules in regular grammars. cs466(Prasad) L4CFG
Equivalent Regular Grammar A regular grammar is a CFG in which each of the rules has the form: (Left Linear Grammar) Right linear grammar A-> aB Cannot mix A->Ba and A->aB rules in regular grammars. cs466(Prasad) L4CFG
Extended regular grammar RHS begins with a string of terminals. cs466(Prasad) L4CFG
Non-terminals are delimited by angular brackets Non-terminals are delimited by angular brackets. (cf: complement language, DFA) cs466(Prasad) L4CFG
Derivations Note that the above result does not hold for sentential forms. S => B does not have a leftmost derivation cs466(Prasad) L4CFG