0% found this document useful (0 votes)
12 views4 pages

Grammar Derivation Analysis

Uploaded by

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

Grammar Derivation Analysis

Uploaded by

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

Question 4 : ‫محمد صالح على‬

Sec(3)
190034

A) S → 0 S 1 | 0 1 with string 000111


1. Right most derivation
S → 0 S 1 →0 0 S 1 1 → 0 0 0 1 1 1
2. Left most derivation
S → 0 S 1 →0 0 S 1 1 → 0 0 0 1 1 1
Parse tree
S

0 S 1

0 S 1

0 1

4) It is not ambiguous

5) It is the language of all strings of 0,1 that must start


with 0 and end with 1 and has same number of 0 at
the beginning then followed by the same number of 1
.

---------------
c) S → S S + | S S * | a with string aaa * +

1. Left most derivation


S → + S S → + S a →+ * S S a→+ * S a a→ + * a a a

2. Right most derivation


S → S S + → S a S * + →S a a * + →a a a * +

Parse tree
S

+ S S

* S S a

a a

4) It is not ambiguous

5) This language of all strings that consists of a,*,+


and it must start with + or * and end with a

-------------
E) S → (L) | a and L → L, S | S with string ((a, a), a, (a))
1. Left most derivation
S = (L) = (L, S) = (L, S, S) = ((S), S, S) = ((L), S, S)
= ((L, S), S, S) = ((S, S), S, S) = ((a, S), S, S)
= ((a, a), S, S) = ((a, a), a, S) = ((a, a), a, (L))
= ((a, a), a, (S)) = ((a, a), a, (a))
2. Right most derivation
S = (L) = (L , S) = ( L ,(L) ) = ( L , (S)) =( L , (a))
= (L , S , (a)) = (L , a , (a)) = (S , a , (a))
= ((L), a , (a)) =((L , S),a,(a)) = ((L,a),a,(a))
= ((S , a), a , (a)) = ((a,a),a,(a))

Parse tree
( L )
L , S

L , S ( L )

S a S
( L ) a

L , S

S a

a
4) It is not ambiguous
5) This language of all strings that consists of a,,,( and )
and it “a” Enclosed with () and separated with “,”.

Question 5:
A) S → 0S0 | 1S1 | 0 | 1 | ε
D) S → A | B
A → C0A | C0C
B → C1A | C1C
C → CC | 0C1 | 1C0 | ε

-----------------------

You might also like