-
Notifications
You must be signed in to change notification settings - Fork 3
/
hooks.lgt
82 lines (60 loc) · 3.02 KB
/
hooks.lgt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
:- object(hook,
implements(expanding)).
:- info([
version is 1:0:1,
author is 'Paulo Moura',
date is 2020-03-03,
comment is 'Hook predicates for converting example sets into ordered sets.']).
:- uses(list, [sort/2]).
term_expansion(alphabet([H| T]), [alphabet(OrderedExpression)]) :-
sort([H| T], OrderedExpression).
term_expansion(expression([H| T]), [expression(OrderedExpression)]) :-
sort([H| T], OrderedExpression).
term_expansion(finals(Finals), [finals(OrderedFinals)]) :-
sort(Finals, OrderedFinals).
term_expansion(rules(Rules), [rules(OrderedRules)]) :-
sort(Rules, OrderedRules).
term_expansion(transitions(Transitions), [transitions(OrderedTransitions)]) :-
sort(Transitions, OrderedTransitions).
:- end_object.
% the following expansions are only necessary when using object proxies:
% (due to the lack of Prolog portability of the predicate_property/2, we
% cannot apply the obvious simplification to this code in order to avoid
% the duplicating the definitions of term_expansion/2!)
:- if(predicate_property(term_expansion(_, _), multifile)).
:- multifile(term_expansion/2).
:- dynamic(term_expansion/2).
term_expansion(fa(Initial, Transitions, Finals), [fa(Initial, OrderedTransitions, OrderedFinals)]) :-
sort(Transitions, OrderedTransitions),
sort(Finals, OrderedFinals).
term_expansion(cfg(StartSymbol, Rules), [cfg(StartSymbol, OrderedRules)]) :-
sort(Rules, OrderedRules).
term_expansion(pda(Initial, InitialStackSymbol, Transitions, Finals), [pda(Initial, InitialStackSymbol, OrderedTransitions, OrderedFinals)]) :-
sort(Transitions, OrderedTransitions),
sort(Finals, OrderedFinals).
term_expansion(tm(Initial, Transitions, Finals), [tm(Initial, OrderedTransitions, OrderedFinals)]) :-
sort(Transitions, OrderedTransitions),
sort(Finals, OrderedFinals).
:- elif(current_logtalk_flag(prolog_dialect, qp)).
:- multifile(term_expansion/2).
:- dynamic(term_expansion/2).
term_expansion(fa(Initial, Transitions, Finals), [fa(Initial, OrderedTransitions, OrderedFinals)]) :-
sort(Transitions, OrderedTransitions),
sort(Finals, OrderedFinals).
term_expansion(cfg(StartSymbol, Rules), [cfg(StartSymbol, OrderedRules)]) :-
sort(Rules, OrderedRules).
term_expansion(pda(Initial, InitialStackSymbol, Transitions, Finals), [pda(Initial, InitialStackSymbol, OrderedTransitions, OrderedFinals)]) :-
sort(Transitions, OrderedTransitions),
sort(Finals, OrderedFinals).
term_expansion(tm(Initial, Transitions, Finals), [tm(Initial, OrderedTransitions, OrderedFinals)]) :-
sort(Transitions, OrderedTransitions),
sort(Finals, OrderedFinals).
:- else.
:- initialization((
nl,
write('************************************* WARNING **************************************'), nl,
write('Your back-end Prolog compiler does not seem to support the term expansion mechanism.'), nl,
write('Representing languages and automata using object proxies is therefore not supported.'), nl,
write('************************************************************************************'), nl, nl
)).
:- endif.