Download presentation
Presentation is loading. Please wait.
1
Context-free Grammars
cs466(Prasad) L4CFG
2
Recursive definition Grammar Derivation cs466(Prasad) L4CFG
3
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
4
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
5
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
6
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
7
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
8
Derivation of aabb Derivation tree S a b S a b l cs466(Prasad) L4CFG
9
Factor left-hand side using syntax for alternatives |.
cs466(Prasad) L4CFG
10
Derivation Tree (abstracts derivation)
l l cs466(Prasad) L4CFG
11
Examples: CFGs and CFLs
cs466(Prasad) L4CFG
12
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
13
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
14
CFG: Ease of understanding vs RG: Efficient left to right generation of string
cs466(Prasad) L4CFG
15
cs466(Prasad) L4CFG Pi is concatenation.
Same numeric variable = equality constraint; Different variables independence; TEMPLATE for sequencing of letters cs466(Prasad) L4CFG
16
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
17
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
18
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
19
Extended regular grammar RHS begins with a string of terminals.
cs466(Prasad) L4CFG
20
Non-terminals are delimited by angular brackets
Non-terminals are delimited by angular brackets. (cf: complement language, DFA) cs466(Prasad) L4CFG
21
Derivations Note that the above result does not hold for sentential forms. S => B does not have a leftmost derivation cs466(Prasad) L4CFG
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.