You are on page 1of 5

‫‪Second Stage‬‬ ‫‪Computational Theory‬‬ ‫‪Dr.

Ghiath Hameed‬‬

‫‪Language Grammar‬‬

‫‪The foundations and principles used to link the vocabulary.‬‬

‫ﺗﻤﺜﻞ اﻷﺳﺲ واﻟﻤﺒﺎدئ اﻟﺘﻲ ﯾﻌﺘﻤﺪ ﻋﻠﯿﮭﺎ ﻟﻠﺮﺑﻂ ﺑﯿﻦ اﻟﻤﻔﺮدات‪.‬‬

‫‪Sentence = nounphrase + verbphrace + nounphrase‬‬

‫)‪= (NP) + (VP) + (NP‬‬

‫‪Where:‬‬ ‫‪NP = Art + Noun‬‬


‫‪Art = a, an, the‬‬
‫… ‪Noun = book, Ali, car,‬‬
‫… ‪Verb = go, play, write, read,‬‬

‫‪Ex.The man read the book.‬‬

‫‪Tuples of Grammar:‬‬

‫)‪G(L) = (N, T, P, S‬‬

‫)‪1. Set of terminal symbols (T‬‬

‫ﺗﻤﺜﻞ اﻟﻌﻨﺎﺻﺮ اﻟﻨﮭﺎﺋﯿﺔ ﻏﯿﺮ اﻟﻘﺎﺑﻠﺔ ﻟﻠﺘﺠﺰﺋﺔ وﻻ ﺗﺤﺘﺎج إﻟﻰ ﺗﺤﻠﯿﻞ وﻧﺴﺘﺨﺪم ﻟﮭﺎ اﻷﺣﺮف اﻟﺼﻐﯿﺮة )‪(lower case‬‬

‫)‪2. Set of non-terminal symbols (N‬‬

‫ﺗﻤﺜﻞ اﻟﻌﻨﺎﺻﺮ اﻟﻼﻧﮭﺎﺋﯿﺔ وھﻲ ﻋﻜﺲ اﻟﺮﻣﻮز اﻟﺴﺎﺑﻘﺔ وﺗﻜﻮن ﻗﺎﺑﻠﺔ ﻟﻠﺘﺠﺰﺋﺔ وﺗﺘﺤﻠﻞ إﻟﻰ رﻣﻮز ﻧﮭﺎﺋﯿﺔ ﻓﻲ اﻟﻨﮭﺎﺋﯿﺔ‬
‫وﺗﻈﮭﺮ ﻋﺎدة ﻓﻲ اﻟﻄﺮف اﻷﯾﺴﺮ ﻣﻦ اﻟﻘﻮاﻋﺪ وﺗﺴﺘﺨﺪم ﻟﮭﺎ اﻷﺣﺮف اﻟﻜﺒﯿﺮة )‪(UPPER CASE‬‬

‫)‪3. Set of production rules (P‬‬

‫‪S  Fa / b‬‬ ‫ﺗﻤﺜﻞ ﻗﻮاﻋﺪ اﻻﻧﺘﺎج‬

‫)‪4. Starting symbol (S‬‬

‫ﯾﻤﺜﻞ ﻋﻨﺼﺮ اﻟﺒﺪاﯾﺔ أو اﻟﺮﻣﺰ اﻷول ﻣﻮﺟﻮد ﻓﻲ اﻟﺠﮭﺔ اﻟﯿﺴﺮى ﻣﻦ اﻟﻘﻮاﻋﺪ واﻟﺬي ﯾﻮﺻﻠﻨﺎ إﻟﻰ ﺑﻘﯿﺔ اﻟﻘﻮاﻋﺪ ﺑﺸﻜﻞ‬
‫ﻣﺒﺎﺷﺮ أو ﻏﯿﺮ ﻣﺒﺎﺷﺮ ﺑﺎﻗﻞ ﻋﺪد ﻣﻦ اﻟﻤﻔﺮدات‬

‫‪10 ‬‬
‫‪ ‬‬
Second Stage Comp
putational Theory
T Dr. Ghiatth Hameed
d

Ex. Let G
G(L) = ({S
S, B}, {a, b},
b P, S), where P denoted
d ass:

S  aSB
S  aB
Bb

Is the striing "aabb"" accept orr not?

Sol.

S  aSB
 aaBB
 aabb

Then, thee string "aaabb" is accepted

Ex. Let G
G(L) = ({S
S, A, B}, {a,
{ b}, P, S),
S where P denoted
d as:

S  aA / bB
B/a /b
A  aA / a
B  bB / b

1. Is tthe string "aa" acceppt or not?


2. Is tthe string "bbb" acccept or nott?

Sol.

1. For the string "aa"


S  aA by usingg S  aA
 aa by usingg A a
Thhen, the strring "aa" is
i acceptedd.

2. For the string "bbb"


11 
Second Stage Computational Theory Dr. Ghiath Hameed
S  bB by using S  bB
 bbB by using B  bB
 bbb by using Bb
Then, the string "bbb" is accepted.

Ex. Let G(L) = ({S, A}, {a, b}, P, S), where P denoted as:

S  aAb
aA  aaAb

Is the string "aaabbb" accept in G(L) or not?

Sol.

S  aAb by using S  aAb


 aaAbb by using aA  aaAb
 aaaAbbb by using aA  aaAb

Then, the string "aaabbb" is not accepted.

Ex. Let G(L) = ({S, A, B}, {a, b}, P, S), and P denoted as:

S  aA / bB / a / b
A  aA / a
B  bB / b

Are the strings "aa" and "bb" accept in G(L)?

Sol.

S  aA by using S  aA
S  aa by using Aa

 the string "aa" is accepted.

S  bB by using S  bB
S  bb by using Bb

 the string "bb" is accepted.

12 
 
Second Stage Computational Theory Dr. Ghiath Hameed
Ex. Let G(L) = ({S, B, C}, {a, b, c}, P, S) , and the P denoted as:

S  aSBC / aBC
CB  BC
aB  ab
bB  bb
bC  bc
cC  cc

Is the string "a2b2c2" accepted for the G(L) or not?


Sol.
S  aSBC by using S  aSBC
 a aBCBC by using S  aBC
 aabCBC by using aB  ab
 aa bBCC by using CB  BC
 aabbCC by using Bb  bb
 aabbcC by using bC  bc
 aabbcc by using cC  cc
 the string "a b c " is accepted.
2 2 2

H.W. Let G(L) = ({ S, B, C} , {a, b, c}, P,S) where P denoted as: 

S  aSBC / aBC
aB  ab
CB  BC
  bB  bb  

bC  bc
cC  cc
1- is the string "aabcc" Accept or not ?
2- is the string " abc" Accept or not ?
3- is the string " a3 b3 c3 " Accept or not ?

13 
 
Second Stage Computational Theory Dr. Ghiath Hameed
ChomiskyHierachy ‫ھﺮم ﭼﻮﻣﺴﻜﻲ‬

Chomisky classify language grammar into FOUR types:

1. Type (0) (Non-Restricted Grammar)


u  v , u, v  ( N  t ) * , (Turing Machine (TM)) ‫ﻣﻦ ﺗﻄﺒﯿﻘﺎﺗﮭﺎ‬
2. Type (1) (Context Sensitive Grammar)
u  v , u, v  ( N  t )  , (Push-Down Automata (PDA)) ‫وﻣﻦ ﺗﻄﺒﯿﻘﺎﺗﮭﺎ‬
3. Type (2) (Context Free Grammar)
N  V , N  nonterminal, V  ( N  T ) * , (Finite Automata (FA)) ‫وﻣﻦ ﺗﻄﺒﯿﻘﺎﺗﮭﺎ‬
4. Type (3) (Regular Grammar) of (Linear Grammar)
N  tN / t , (Regular Expression) ‫وﻣﻦ ﺗﻄﺒﯿﻘﺎﺗﮭﺎ‬

14 
 

You might also like