Вы находитесь на странице: 1из 26

REYNALD JAY F.

HIDALGO, MS Computer Science


Professor

set of atomic/non-divissible symbols

Eg.
A=
{a,b,c,d,e,f,g,h,I,j,k,l,m,n,o,p,q,r,s,t,u,v,
w,x,y,z}
A = {a,b,c}
A = {0, 1}
A = {+,-,*,/}

sequence of symbol/s from a given


alphabet

Eg.
A = {a,b,c}
w=a w=b
w=c
w = aa w = abc w = ccc

Denotes

w=

the empty string

Denotes

the length of a given string


(an integer value)

w
w
w
w

=
=
=
=

abcd
0 /w/
12 /w/
/w/

/w/ = 4
=1
=2
=0

Fundamental

operation on strings

Let be the first string and


be the 2nd string
The concatenation of and is
denoted by
= .

= .
Where
is the prefix of and is a
proper prefix if while
is the suffix of and is a
proper suffix if

string concatenated with will


result to the same string

Any

denotes

k copies of w

Given w = abc
w3 = 3 copies 0f w
= abcabcabc

Is

a subset of the powerset W

SLE
L V :=
E if B then A
else E
EA
BA<A
BA=A
AT+A
AT
TV
T0
T1
T (E)
Vx
Vy

1. Generate the Algol


statement
w:= if x < y then 0 else x
+y+1
2.

Prove that the following


Algol
statement is valid
x:= ( 1 + ( 0 + x ) )

3.

Generate the Algol


Statement

N
T
P

It

is a four-tuple
G = (N, T, P, )
Where
N is a finite set of nonterminal
symbols
T is a finite set of terminal symbols
N and T are disjoint: N T =
P is a finite set of productions
is the sentence symbol; (NT)

Each production P is an ordered pair of


strings (,)
=
=
In which ,, are possible empty
strings in (NT)* and A is or a
nonterminal letter. We usually write
production () as

Let G1 have N = {A,B,C}, T =(a,b) and


the set of productions
A
A aABC
A abC
CB BC
bB bb
bC b
Identify the Language L generated by G1

Let G2 have N = {A,B,C}, T (a,b,c) and


the set of productions
A
A aABC
A abC
CB BC
bB bb
bC bc
cC cc
Identify the Language L generated by G2

Let G3 have N = {S}, T= (a,b) and the


set of productions
S
S aSb
S ab
dentify the Language L generated by
G3

The Language L(G) generated by a


formal grammar G is the set of
terminal strings derivable from

Given a G an L can be
derived

1. Let G4 have N = {A,B}, T= (1,0) and the set of


productions
1B
1
A 1B
B 0A
A 1
Identify the Language L generated by G4
2. Let G5 have N = {A,B}, T= (1,0) and the set of
productions
B1
1
A B1
B A0
A 1
Identify the Language L generated by G5

Occurs

when 2 or more derivation


trees can be drawn from a single w

Structural
Labeling

Let G6 have N = {A}, T (0,1) and the


set of productions
A
A A0A
A1
Draw a derivation tree for the string
10101

Let G7 have N = {A,B}, T (1,0) and the


set of productions
A
A B0
A A0
B B0
A 1
B 1
Draw a derivation tree for the string 100

Prove that the following Grammars are ambiguous. How? Concepts

N = {A,B,S}
1.

S
S ScS
Sc

2. A B A
Aa
Ab
Ac
B+
B*

TYP
E

FORMAT OF
PRODUCTIONS

REMARKS

Unrestricted
Substitution Rules

Contracting

A,

A ,

Context Sensitive

NonContracting

Context Free

NonContracting

A aB
Regular, Right
Linear
Aa

A Ba
Regular, Left Linear
Aa
AN {}, , and (N T)*, B N, a T

NonContracting

Вам также может понравиться