formal grammar from automaton

135 Views Asked by At

Given this automaton $M=(Q,δ,q0,F)$ over alphabet Σ={a,p}Σ={a,p}: enter image description here

Find a regular grammar $G=( N,Σ,P,S)$ s.t. T(M)=L(G)

I found this grammar and I would know if is correct: G=( N,Σ,P,S) where:

N=Q

S=$q_0$

P=$\{q_0 \rightarrow aq_o|pq_1|a|p$

$q_1 \rightarrow aq_2|pq_1|a|p$

$q_2 \rightarrow aq_o|pq_3|a|p$

$q_3 \rightarrow aq_4|pq_1|p$

$q_4 \rightarrow aq_4|pq_4 \}$

Moreover, I would know if is formally correct delete $q4$ productions (and productions where $q4$ appears) since $q4$ is a trap state and doesn't generate words of L:

$P-(\{q_4 \rightarrow aq_4|p_q4\} \cup \{q_3 \rightarrow aq_4\})$

Thanks in advance.