<< Prev | - Up - | Next >> |
Make sure that you understand how the Prolog programs that we saw in this section work.
We will start out with a couple of simple keyboard exercises so make sure that you understand how the Prolog programs that we saw in this section work.
Note: The file recognize1.pl
contains a version of our recognizer/generator that that only works for FSAs without jump arcs. It defines the same predicates as recognize.pl
, but all predicate names end in a 1
.
Start Prolog and consult recognize.pl
, recognize1.pl
, and haha.pl
. Using both test1
(which does not deal with jump arcs) and test
(which does) see whether various strings are accepted e.g
test1(a1,[h,a,!]).
test(a1,[h,a,!]).
test1(a1,[h,a,h,a,h,a,!]).
Make sure you understand why these strings are accepted. That is, use trace to step through the execution so that you understand exactly what is going on.
Now let's have a look at the automaton a3
. The difference between a1
and a3
is that haha5
is not deterministic. Try giving the following queries:
test(a3,[h,a,!]).
test1(a3,[h,a,!]).
test(a3,[h,a,h,a,h,a,!]).
Make sure you understand why these strings are accepted. That is, use trace to step through the execution so that you understand exactly what is going on.
We now turn to a2
. The big difference between a1
and a2
is that a2
contains a jump arc #
. Now, recognize1
does not handle jump arcs so it should not be able to handle a2
correctly.
Try out the following experiments, and make sure you understand why recognize1 gives the responses it gives:
test1(a2,[h,a,!]).
test1(a2,[h,a,h,a,!]).
test1(a2,[h,a,h,a,h,a,!]).
Now try these examples with test
instead of test1
. Again, carry out traces.
Finally, make sure that you understand how the generate predicates are defined. Try using generate1
to generate using a2
. Now try using generate
with a2
. Why does generate1
give a wrong response?
<< Prev | - Up - | Next >> |