0% found this document useful (0 votes)
24 views

Context Free Grammar

This document discusses context-free grammars for generating different types of languages, including: 1) The language b* using rules S->bS and S-># to recursively generate strings of b's. 2) Generating palindromes using rules like S->aSa and S->bSb to recursively add matching prefix and suffix letters. 3) The language (a+b)* using rules S->aS, S->bS, and S-># to recursively add a's and b's or end the string.

Uploaded by

vshlvvk
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Context Free Grammar

This document discusses context-free grammars for generating different types of languages, including: 1) The language b* using rules S->bS and S-># to recursively generate strings of b's. 2) Generating palindromes using rules like S->aSa and S->bSb to recursively add matching prefix and suffix letters. 3) The language (a+b)* using rules S->aS, S->bS, and S-># to recursively add a's and b's or end the string.

Uploaded by

vshlvvk
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Context Free Grammar/Language

PPL,CS-403

Generate the language b*


Rule1: S->bS Rule2: S-> # S-> bS bbS bbbS bbbbS bbbbbS bbbbb#

To generate aaa?
S -> SS S -> a S -> # S -> SS aS aSS aaS aaa S
S S

n n a b
S -> aSb S -> # S -> aSb aaSbb aaaSbbb aaaaSbbbb aaaa#bbbb aaaabbbb

Palindrome
S -> aSa S -> bSb S -> a S -> b S -> #
To generate abbababba?

S -> aSa -> abSba -> abbSbba -> abbaSabba -> abbababba

(a+b)*
S -> aS | bS |# To generate the string ababba S -> aS abS ab

Non palindrome
S -> aXb|bXa X -> # | aX | bX S -> aSa|bSb To derive abba S -> aSa abSba ??

You might also like