RACSO
DFA
CFG
Operations:
Reg
,
CF
PDA
Reductions:
K
,
WP
,
CFG
,
NP
,
SAT
ANTLR:
lexical
,
syntactic
Exams
log in
,
register
,
become guest
This site uses cookies only for the purpose of identifying user sessions. This is required to properly register actions.
Exercises on context-free grammars (CFG)
Non-ambiguous CFG for
{
a
n
b
n
∣
n
≥
0
}
\{ a^n b^n \mid n\geq 0 \}
{
a
n
b
n
∣
n
≥
0
}
Non-ambiguous CFG for
{
a
n
c
b
n
∣
n
>
0
}
\{ a^n c b^n \mid n>0 \}
{
a
n
c
b
n
∣
n
>
0
}
Non-ambiguous CFG for
{
a
i
b
j
∣
i
≥
j
}
\{ a^i b^j \mid i\geq j \}
{
a
i
b
j
∣
i
≥
j
}
Non-ambiguous CFG for
{
a
i
b
j
∣
i
≤
j
}
\{ a^i b^j \mid i\leq j \}
{
a
i
b
j
∣
i
≤
j
}
Non-ambiguous CFG for
{
a
i
b
j
∣
2
i
≤
j
}
\{ a^i b^j \mid 2i\leq j \}
{
a
i
b
j
∣
2
i
≤
j
}
CFG for
{
a
i
b
j
∣
2
i
≥
j
}
\{ a^i b^j \mid 2i\geq j \}
{
a
i
b
j
∣
2
i
≥
j
}
Non-ambiguous CFG for
{
a
i
b
j
∣
2
i
≥
j
}
\{ a^i b^j \mid 2i\geq j \}
{
a
i
b
j
∣
2
i
≥
j
}
Non-ambiguous CFG for
{
a
i
b
j
∣
j
≤
i
≤
2
j
}
\{ a^i b^j \mid j\leq i\leq 2j \}
{
a
i
b
j
∣
j
≤
i
≤
2
j
}
Non-ambiguous CFG for
{
a
i
b
j
∣
i
≥
j
∨
i
≤
2
j
}
\{ a^i b^j \mid i\geq j \vee i\leq 2j \}
{
a
i
b
j
∣
i
≥
j
∨
i
≤
2
j
}
Non-ambiguous CFG for
{
a
i
b
j
c
k
∣
i
=
j
+
k
}
\{ a^i b^j c^k \mid i=j+k \}
{
a
i
b
j
c
k
∣
i
=
j
+
k
}
Non-ambiguous CFG for
{
a
i
b
j
c
k
∣
j
=
i
+
k
}
\{ a^i b^j c^k \mid j=i+k \}
{
a
i
b
j
c
k
∣
j
=
i
+
k
}
CFG for
{
a
i
b
j
c
k
∣
i
=
j
∨
j
=
k
∨
i
=
k
}
\{ a^i b^j c^k \mid i=j \vee j=k \vee i=k \}
{
a
i
b
j
c
k
∣
i
=
j
∨
j
=
k
∨
i
=
k
}
CFG for
{
a
n
0
b
a
n
1
b
…
a
n
m
−
1
b
a
n
m
∣
m
≥
1
∧
∃
i
∈
{
1
,
…
,
m
}
:
(
n
0
=
n
i
)
}
\{ a^{n_0} b a^{n_1} b \ldots a^{n_{m-1}} b a^{n_m} \mid m\geq 1 \wedge \exists i\in\{1,\ldots,m\}: (n_0 = n_i) \}
{
a
n
0
b
a
n
1
b
…
a
n
m
−
1
b
a
n
m
∣
m
≥
1
∧
∃
i
∈
{
1
,
…
,
m
}
:
(
n
0
=
n
i
)}
Non-ambiguous CFG for
{
a
n
0
b
a
n
1
b
…
a
n
m
−
1
b
a
n
m
∣
m
≥
1
∧
(
n
0
=
∑
1
≤
i
≤
m
n
i
)
}
\{ a^{n_0} b a^{n_1} b \ldots a^{n_{m-1}} b a^{n_m} \mid m\geq 1 \wedge (n_0 = \sum_{1\leq i\leq m} n_i) \}
{
a
n
0
b
a
n
1
b
…
a
n
m
−
1
b
a
n
m
∣
m
≥
1
∧
(
n
0
=
∑
1
≤
i
≤
m
n
i
)}
CFG for
{
a
n
0
b
a
n
1
b
…
a
n
m
−
1
b
a
n
m
∣
m
≥
1
∧
∃
I
⊆
{
1
,
…
,
m
}
:
(
n
0
=
∑
i
∈
I
n
i
)
}
\{ a^{n_0} b a^{n_1} b \ldots a^{n_{m-1}} b a^{n_m} \mid m\geq 1 \wedge \exists I\subseteq\{1,\ldots,m\}: (n_0 = \sum_{i\in I} n_i) \}
{
a
n
0
b
a
n
1
b
…
a
n
m
−
1
b
a
n
m
∣
m
≥
1
∧
∃
I
⊆
{
1
,
…
,
m
}
:
(
n
0
=
∑
i
∈
I
n
i
)}
Non-ambiguous CFG for
{
w
∈
{
a
,
b
}
∗
∣
w
=
w
R
}
\{ w \in \{a,b\}^* \mid w=w^R \}
{
w
∈
{
a
,
b
}
∗
∣
w
=
w
R
}
Non-ambiguous CFG for
{
w
∈
{
a
,
b
}
∗
∣
w
=
w
R
∧
∣
w
∣
a
b
a
=
0
}
\{ w \in \{a,b\}^* \mid w=w^R \wedge |w|_{aba}=0 \}
{
w
∈
{
a
,
b
}
∗
∣
w
=
w
R
∧
∣
w
∣
aba
=
0
}
Non-ambiguous CFG for
{
w
∈
{
a
,
b
}
∗
∣
w
=
w
R
∧
∣
w
∣
a
>
0
∧
∣
w
∣
b
>
0
}
\{ w \in \{a,b\}^* \mid w=w^R \wedge |w|_a>0 \wedge |w|_b>0 \}
{
w
∈
{
a
,
b
}
∗
∣
w
=
w
R
∧
∣
w
∣
a
>
0
∧
∣
w
∣
b
>
0
}
Non-ambiguous CFG for
{
w
∈
{
a
,
b
}
∗
∣
w
=
w
R
∧
∣
w
∣
a
b
a
>
0
}
\{ w \in \{a,b\}^* \mid w=w^R \wedge |w|_{aba}>0 \}
{
w
∈
{
a
,
b
}
∗
∣
w
=
w
R
∧
∣
w
∣
aba
>
0
}
CFG for the well-parenthesized words over
{
(
,
)
}
\{ ( , ) \}
{(
,
)}
CFG for the well-parenthesized words over
{
[
,
]
,
(
,
)
}
\{ [ , ] , ( , ) \}
{[
,
]
,
(
,
)}
Non-ambiguous CFG for the well-parenthesized words over
{
(
,
)
}
\{ ( , ) \}
{(
,
)}
Non-ambiguous CFG for the well-parenthesized words over
{
[
,
]
,
(
,
)
}
\{ [ , ] , ( , ) \}
{[
,
]
,
(
,
)}
CFG for
{
w
∈
{
a
,
b
}
∗
∣
∣
w
∣
a
=
∣
w
∣
b
}
\{ w \in \{a,b\}^* \mid |w|_a=|w|_b \}
{
w
∈
{
a
,
b
}
∗
∣
∣
w
∣
a
=
∣
w
∣
b
}
CFG for
{
w
∈
{
a
,
b
,
c
}
∗
∣
∣
w
∣
a
=
∣
w
∣
b
}
\{ w \in \{a,b,c\}^* \mid |w|_a=|w|_b \}
{
w
∈
{
a
,
b
,
c
}
∗
∣
∣
w
∣
a
=
∣
w
∣
b
}
CFG for
{
w
∈
{
a
,
b
,
c
}
∗
∣
∣
w
∣
a
+
∣
w
∣
b
=
∣
w
∣
c
}
\{ w \in \{a,b,c\}^* \mid |w|_a+|w|_b=|w|_c \}
{
w
∈
{
a
,
b
,
c
}
∗
∣
∣
w
∣
a
+
∣
w
∣
b
=
∣
w
∣
c
}
CFG for
{
w
∈
{
a
,
b
}
∗
∣
2
∣
w
∣
a
=
∣
w
∣
b
}
\{ w \in \{a,b\}^* \mid 2|w|_a=|w|_b \}
{
w
∈
{
a
,
b
}
∗
∣
2∣
w
∣
a
=
∣
w
∣
b
}
Non-ambiguous CFG for
{
w
∈
{
a
,
b
}
∗
∣
∣
w
∣
a
=
∣
w
∣
b
}
\{ w \in \{a,b\}^* \mid |w|_a=|w|_b \}
{
w
∈
{
a
,
b
}
∗
∣
∣
w
∣
a
=
∣
w
∣
b
}
Non-ambiguous CFG for
{
w
∈
{
a
,
b
,
c
}
∗
∣
∣
w
∣
a
=
∣
w
∣
b
}
\{ w \in \{a,b,c\}^* \mid |w|_a=|w|_b \}
{
w
∈
{
a
,
b
,
c
}
∗
∣
∣
w
∣
a
=
∣
w
∣
b
}
Non-ambiguous CFG for
{
w
∈
{
a
,
b
,
c
}
∗
∣
∣
w
∣
a
+
∣
w
∣
b
=
∣
w
∣
c
}
\{ w \in \{a,b,c\}^* \mid |w|_a+|w|_b=|w|_c \}
{
w
∈
{
a
,
b
,
c
}
∗
∣
∣
w
∣
a
+
∣
w
∣
b
=
∣
w
∣
c
}
Non-ambiguous CFG for
{
w
∈
{
a
,
b
}
∗
∣
2
∣
w
∣
a
=
∣
w
∣
b
}
\{ w \in \{a,b\}^* \mid 2|w|_a=|w|_b \}
{
w
∈
{
a
,
b
}
∗
∣
2∣
w
∣
a
=
∣
w
∣
b
}
Non-ambiguous CFG for
{
x
c
y
∣
x
,
y
∈
{
a
,
b
}
∗
∧
∣
x
∣
a
=
∣
y
∣
b
}
\{ xcy \mid x,y\in\{a,b\}^* \wedge |x|_a=|y|_b \}
{
x
cy
∣
x
,
y
∈
{
a
,
b
}
∗
∧
∣
x
∣
a
=
∣
y
∣
b
}
Non-ambiguous CFG for
{
x
c
y
∣
x
,
y
∈
{
a
,
b
}
∗
∧
∣
x
∣
a
b
=
∣
y
∣
b
a
}
\{ xcy \mid x,y\in\{a,b\}^* \wedge |x|_{ab}=|y|_{ba} \}
{
x
cy
∣
x
,
y
∈
{
a
,
b
}
∗
∧
∣
x
∣
ab
=
∣
y
∣
ba
}
Non-ambiguous CFG for
{
x
c
y
∣
x
,
y
∈
{
a
,
b
}
∗
∧
∣
x
∣
a
b
a
=
∣
y
∣
b
a
b
}
\{ xcy \mid x,y\in\{a,b\}^* \wedge |x|_{aba}=|y|_{bab} \}
{
x
cy
∣
x
,
y
∈
{
a
,
b
}
∗
∧
∣
x
∣
aba
=
∣
y
∣
bab
}
Non-ambiguous CFG for
{
x
c
y
∣
x
,
y
∈
{
a
,
b
}
∗
∧
y
R
prefix of
x
}
\{ xcy \mid x,y\in\{a,b\}^* \wedge y^R \text{ prefix of } x \}
{
x
cy
∣
x
,
y
∈
{
a
,
b
}
∗
∧
y
R
prefix of
x
}
Non-ambiguous CFG for
{
x
c
y
∣
x
,
y
∈
{
a
,
b
}
∗
∧
y
R
suffix of
x
}
\{ xcy \mid x,y\in\{a,b\}^* \wedge y^R \text{ suffix of } x \}
{
x
cy
∣
x
,
y
∈
{
a
,
b
}
∗
∧
y
R
suffix of
x
}
Non-ambiguous CFG for
{
x
c
y
∣
x
,
y
∈
{
a
,
b
}
∗
∧
∣
x
∣
=
∣
y
∣
∧
∣
x
∣
a
a
>
0
}
\{ xcy \mid x,y\in\{a,b\}^* \wedge |x|=|y| \wedge |x|_{aa}>0 \}
{
x
cy
∣
x
,
y
∈
{
a
,
b
}
∗
∧
∣
x
∣
=
∣
y
∣
∧
∣
x
∣
aa
>
0
}
CFG for the complement of
{
a
n
b
n
∣
n
≥
0
}
\{ a^n b^n \mid n\geq 0 \}
{
a
n
b
n
∣
n
≥
0
}
Non-ambiguous CFG for the complement of
{
a
n
b
n
∣
n
≥
0
}
\{ a^n b^n \mid n\geq 0 \}
{
a
n
b
n
∣
n
≥
0
}
Non-ambiguous CFG for the complement of
{
w
∈
{
a
,
b
}
∗
∣
w
=
w
R
}
\{ w \in \{a,b\}^* \mid w=w^R \}
{
w
∈
{
a
,
b
}
∗
∣
w
=
w
R
}
CFG for the complement of
{
a
n
b
n
c
n
∣
n
≥
0
}
\{ a^n b^n c^n \mid n\geq 0 \}
{
a
n
b
n
c
n
∣
n
≥
0
}
CFG for the complement of
{
w
c
w
∣
w
∈
{
a
,
b
}
∗
}
\{ wcw \mid w\in\{a,b\}^* \}
{
w
c
w
∣
w
∈
{
a
,
b
}
∗
}
CFG for expressions over
{
+
,
−
,
∗
,
/
,
(
,
)
,
0
,
1
,
…
,
9
}
\{ + , - , * , / , ( , ) , 0 , 1, \ldots, 9 \}
{
+
,
−
,
∗
,
/
,
(
,
)
,
0
,
1
,
…
,
9
}
Non-ambiguous CFG for expressions over
{
+
,
−
,
∗
,
/
,
(
,
)
,
0
,
1
,
…
,
9
}
\{ + , - , * , / , ( , ) , 0 , 1, \ldots, 9 \}
{
+
,
−
,
∗
,
/
,
(
,
)
,
0
,
1
,
…
,
9
}
CFG for
{
a
n
b
m
c
k
d
t
∣
n
=
m
∨
n
=
k
∨
n
=
t
}
\{ a^n b^m c^k d^t \mid n=m \vee n=k \vee n=t \}
{
a
n
b
m
c
k
d
t
∣
n
=
m
∨
n
=
k
∨
n
=
t
}