Languages and Grammar
Languages and Grammar
Grammar
DEFINITIONS AND EXAMPLES
The theory of formal languages is an area with a number of applications in
computer science. in the early 1950s to define precisely
valid sentences and give structural descriptions of sentences. They wanted to
define a formal grammar (i.e. to describe the rules of grammar in a rigorous
mathematical way) to describe English. They thought that such a description of
natural languages (the languages that we use in everyday life such as English,
Hindi. French, etc.) would make language translation using computers easy. It
was Noam Chomsky who gave a mathematical model of a grammar in 1956.
Although it was not useful for describing natural languages such as English, it
turned alit to be useful for computer languages.
Languages
- A set of all legal strings over some alphabet
Formal Language
- A set of all legal strings over some alphabet
Grammar
- Rules that determine legal strings on an alphabet
KEY CONCEPTS RELATED
TO FORMAL LANGUAGE
Example
Grammar
({S, A, B}, {a, b}, S, {S → AB, A → a, B → b})
Grammar G2 −
(({S, A}, {a, b}, S,{S → aAb, aA → aaAb, A → ε } )
S → aAb [by S
→ aaAbb [by aA aaAb]
→ aaaAbbb [by aaAb]
→ aaabbb [by A→ε]
Let us consider the grammar −
G2 = ({S, A}, {a, b}, S, {S → aAb, aA → aaAb, A → ε } )
Some of the strings that can be derived are −
S → aAb using production S → aAb
→ aaAbb using production aA → aAb
→ aaaAbbb using production aA → aaAb
→ aaabbb using production A → ε
In this example grammar, we can start with the symbol "S" (sentence) and keep replacing it with other
symbols, creating strings like "aaabbb" by following a step-by-step.
S → aAb: This rule states that the starting symbol "S" (sentence) can be replaced with the string "aAb".
aA → aaAb: This rule allows you to replace the combination "aA" with "aaAb".
A → ε: This rule is a bit special. It says that the symbol "A" can be replaced with the empty string (ε),
which means it disappears completely.
THANK YOU!