1 Grammars
2 Grammars express languages Example: the English language
3
4 A derivation of “the boy walks”:
5 A derivation of “a dog runs”:
6 Language of the grammar: L = { “a boy runs”, “a boy walks”, “the boy runs”, “the boy walks”, “a dog runs”, “a dog walks”, “the dog runs”, “the dog walks” }
7 Notation Variable or Non-terminal Terminal Production rule
8 Another Example Grammar: Derivation of sentence :
9
10 Other derivations:
11 Language of the grammar
12 More Notation Grammar Set of variables Set of terminal symbols Start variable Set of Production rules
13 Example Grammar :
14 More Notation Sentential Form: A sentence that contains Variables and terminals Example: Sentential Formssentence
15 We write: Instead of:
16 In general we write: If:
17 By default:
18 Examples Grammar:
19 Another Example Grammar G: Derivations:
20
21 Language of a Grammar For a grammar with start variable
22 Example For grammar G: Since:
23 A Convenient Notation
24 Linear Grammars
25 A Linear Grammar Grammars with at most one variable on the right side of a production Examples:
26 A Non-Linear Grammar Grammar
27 Another Linear Grammar Grammar
28 Right-Linear Grammars All productions have the form: Example: or
29 Left-Linear Grammars All productions have form: Example: or
30 Regular Grammars
31 Regular Grammars Definition: A regular grammar is any right-linear or left-linear grammar Examples:
32 Observation Regular grammars generate regular languages Examples: Grammar G:
33 Theorem A Language is regular if and only if there is a grammar such that