0% found this document useful (0 votes)
14 views12 pages

Languages and Grammar

Uploaded by

jocellmayprado
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views12 pages

Languages and Grammar

Uploaded by

jocellmayprado
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Languages and

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

ALPHABET STRING Language


a set of all legal strings
a finite set of atomic over some alphabet. Ex:
symbol where strings are a sequence of symbols L0= (all words in the
formed. Ex: A={ from an alphabet. Ex. lion a dictionary) a language
a,b,c.....x,y,z} string over A over A
Imagine a language like English. We have rules how
to form correct sentences. Formal languages are
similar, but instead of words, they use symbols to
define valid strings. Chomsky's model provides a
mathematical way to describe these rules.
Grammar
A GRAMMAR G CAN BE FORMALLY WRITTEN AS A 4-
TUPLE (N, T, S, P) WHERE −

N or VN is a set of variables or non-terminal


symbols.

T or ∑ is a set of Terminal symbols.

S is a special variable called the Start symbol, S


∈N

P is Production rules for Terminals and Non-


terminals. A production rule has the form α → β,
where α and β are strings on VN ∪ ∑ and least
one symbol of α belongs to VN.
S, A, and B are Non-terminal symbols;
a and b are Terminal symbols
S is the Start symbol, S ∈ N
Productions, P : S → AB, A → a, B → b

Example
Grammar
({S, A, B}, {a, b}, S, {S → AB, A → a, B → b})

non-terminal Terminal Start Production


Example

Grammar G2 −
(({S, A}, {a, b}, S,{S → aAb, aA → aaAb, A → ε } )

S and A are Non-terminal symbols.


a and b are Terminal symbols.
ε is an empty string.
S is the Start symbol, S ∈ N
Production P : S → aAb, aA → aaAb, A → ε
Derivations from a Grammar
Strings may be derived from other strings using the
productions in a grammar. If a grammar G has a
production α → β, we can say that x α y derives x β y
in G. This derivation is written as −
Derivations from a
Grammar
Example: Consider the Grammar G1

= ({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!

You might also like