Wednesday, June 3, 2009

Example of Grammar

Construct the Language generated from the given Grammar.

S à aS /bS/є


Ans. In this production rule there are three productions S à aS, S àbS & S à. In  there is no non terminal, so in the language set there is null string (Λ). S can be replaced by aS, bS or .If S is replaced by aS in aS, it will be aaS. If S is replaced by bS, it will be abS. If S is replaced by aS in bS, it will be baS. If S is replaced by bS in bS, it will be bbS. If S is replaced by  in aS and bS it will be a and b respectively, which will belong to the language set. By this process we will get aa, bb, ab, ba, …, aba, bab....abaaba, …. Etc.

In a single statement we can represent the language set as “Any combination of a, b including null”

In mathematics it is represented as L(G) = {a,b}*

[ Any combination of a,b excluding null will represented by {a,b}+ ]

Language & Grammar

Q. What is Language and what is Grammar? Why Language & Grammar is needed for computer science?

Ans. To express our self to someone i.e. to communicate with someone we need some medium. That medium is language. Hindi, English, Bengali all are used to communicate among persons. So these are languages.
For constructing a language there are some rules. With out the rules a language can not exist. These rules are called Grammar for that language. With out a Grammar a language can not exists.
In computer science, to communicate with computer hardware the user needs some languages for programming purpose. Like C, C++, Java. They are called programming language. These languages are used to communicate with computer and user. So they can be called language. For constructing the languages there are some rules to be followed. The rules are called grammar for that programming language.