Grammars
Observations:
We have seen in the case of the palindrome generator that SRSs are
well suited for generating strings with structure.
By modifying the standard SRS just slightly we obtain a convenient
framework for generating strings with desirable structure –
Grammars
Definition:
[Grammar] A
grammar
is a triple (Γ
,
R
, γ
) such that,
Γ =
T
∪
N
with
T
∩
N
=
∅
, where
T
is a set of symbols called the
terminals
and
N
is a set of symbols called the
nonterminals
,
1
R
is a set of rules of the form
u
→
v
with
u
,
v
∈
Γ
∗
,
γ
is called the
start symbol
and
γ
∈
N
.
1
The fact that
T
and
N
are nonoverlapping means that there will never be
confusion between terminals and nonterminals.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Grammars
Example:
Grammar for arithmetic expressions. We define the grammar
(Γ
,
R
,
s
) as follows:
Γ =
T
∪
N
with
T
=
{
a
,
b
,
c
,
+
,
∗
,
(
,
)
}
and
N
=
{
E
}
,
R
is the set of rules,
E
→
E
+
E
E
→
E
∗
E
E
→
(
E
)
E
→
a
E
→
b
E
→
c
γ
=
E
(clearly this satisfies
s
γ
∈
N
).
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '09
 Staff
 Formal language, γ, Contextfree grammar, grammars

Click to edit the document details