































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!
































































Grammars Grammars express/specify languages
Example: Grammar of English language
predicate verb
noun phrase article noun
sentence noun phrase predicate
A derivation of string “the dog walks”:
the dog walks
the dog verb
the noun verb
article noun verb
noun phrase verb
sentence noun phrase predicate
_
_
A derivation of string “a cat runs”:
a cat runs
a cat verb
a noun verb
article noun verb
noun phrase verb
sentence noun phrase predicate
_
_
Subset of Language produced by the Englishgrammar: L = { “a cat runs”, “a cat walks”, “the cat runs”, “the cat walks”, “a dog runs”, “a dog walks”, “the dog runs”, “the dog walks” }
Notation
noun dog
noun cat
Variable Sequence of Terminals
Production Rules
Another Example
Grammar: S aSb
Variable
Sequence of terminals and variables
The right side may be
Other derivations: S aSb aaSbb aaaSbbb aaabbb
aaaaSbbbb aaaabbbb
S aSb aaSbb aaaSbbb
S aSb aaSbb aaaSbbb aaabbb
aaaaSbbbb aaaabbbb
S aSb aaSbb aaaSbbb
Other derivations:
Grammar: S aSb
More Notation
Grammar G V ,T,S,P
V : T : S : P :
Set of variables Set of terminal symbols Start variable Set of Production rules
Example
Grammar :
G S aSb
G V ,T,S,P
V {S} T {a ,b}
We write:
Instead of:
S aaabbb
S aSb aaSbb aaaSbbb aaabbb
for zero or more derivation steps
w wn
1 w 1 w 2 w 3 wn in zero or more derivation steps
In general we write:
If:
w w
Trivially: