Docsity

Introduction to Grammar and Derivations in Computer Science, Exams of Theory of Automata

Partial preview of the text

Download Introduction to Grammar and Derivations in Computer Science and more Exams Theory of Automata in PDF only on Docsity!

Grammars

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

 _

_

  • Courtesy wikipedia

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

S

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:

S

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 :

S

G S aSb

G  V ,T,S,P

V {S} T {a ,b}

P  {S  aSb, S  }

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: 