I am trying to create a NFA to describe it with states which accepts "y|x*"
This is what I have tried so far:
acpt(State, [A]).
acpt(State, []) :- acpt(State).
acpt(State, InputList) :- InputList = [A],
transition(State, X).
When given the input
acpt(q0, [x,y]).
I'm looking for it to return t
true
When given
acpt(q0, [x,x,y]).
it should return
false
The code I have produces a few errors and I was wondering if I can get some help. Thx.
I comment the corrections required to get
1 ?- acpt(q0, [x,y]).
true
.
2 ?- acpt(q0, [x,x,y]).
false.
working code:
% totally useless:
% acpt(State, [A|B]).
% typo: of course, we need acptng/1
% acpt(State, []) :- acpt(State).
acpt(State, []) :- acptng(State).
acpt(State, [A|B]) :-
transition(State, X, A),
acpt(X, B).
now, apart the test input being working, I must say that I cannot see the 'epsilon rule' implementation. IIRC, a NFA should allows to change state without consuming input.
edit
a trace
4 ?- leash(-all),trace,acpt(q0, [x,x,x]).
Call: (7) so:acpt(q0, [x, x, x])
Call: (8) so:transition(q0, _G1431, x)
Exit: (8) so:transition(q0, q3, x)
Call: (8) so:acpt(q3, [x, x])
Call: (9) so:transition(q3, _G1431, x)
Exit: (9) so:transition(q3, q3, x)
Call: (9) so:acpt(q3, [x])
Call: (10) so:transition(q3, _G1431, x)
Exit: (10) so:transition(q3, q3, x)
Call: (10) so:acpt(q3, [])
Call: (11) so:acptng(q3)
Exit: (11) so:acptng(q3)
Exit: (10) so:acpt(q3, [])
Exit: (9) so:acpt(q3, [x])
Exit: (8) so:acpt(q3, [x, x])
Exit: (7) so:acpt(q0, [x, x, x])
true
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With