View
272
Download
3
Tags:
Embed Size (px)
Citation preview
2
GrammarsGrammars express languages
Example: the English language
verbpredicate
nounarticlephrasenoun
predicatephrasenounsentence
_
_
4
A derivation of “the boy walks”:
walksboythe
verbboythe
verbnounthe
verbnounarticle
verbphrasenoun
predicatephrasenounsentence
_
_
5
A derivation of “a dog runs”:
runsdoga
verbdoga
verbnouna
verbnounarticle
verbphrasenoun
predicatephrasenounsentence
_
_
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” }
12
More Notation
Grammar PSTVG ,,,
V
T
S
P
Set of variables
Set of terminal symbols
Start variable
Set of Production rules
14
More NotationSentential Form: A sentence that contains Variables and terminals
Example:
aaabbbaaaSbbbaaSbbaSbS
Sentential Forms sentence
25
A Linear GrammarGrammars with at most one variable on the right sideof a production
Examples:
A
aAbA
AbS
S
aSbS
31
Regular GrammarsDefinition: A regular grammar is any right-linear or left-linear grammar
Examples:
aS
abSS
aB
BAabA
AabS
|
32
ObservationRegular grammars generate regular languages
Examples:
aS
abSS
Grammar G:
aabGL *)()(
Grammar G:
aB
BAabA
AabS
|
*)()( abaabGL