-
Notifications
You must be signed in to change notification settings - Fork 2
/
data_to_types.pl
executable file
·65 lines (56 loc) · 1.77 KB
/
data_to_types.pl
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
%% data_to_types.pl
/**
?- data_to_types([[1],"a",1],[],T).
T = [[[t, brackets], [[t, number]]], [t, string], [t, number]].
?- data_to_types([1,["a"],1],[],T).
T = [[t, number], [[t, brackets], [[t, string]]], [t, number]].
?- data_to_types([1,"a",[1]],[],T).
T = [[t, number], [t, string], [[t, brackets], [[t, number]]]].
**/
data_to_types([],Types,Types) :- !.
data_to_types(Data,Types1,Types2) :-
get_lang_word("t",T),
get_lang_word("number",Dbw_number),
number(Data),append(Types1,[[T,Dbw_number]],Types2),!.
data_to_types(Data,Types1,Types2) :-
get_lang_word("t",T),
get_lang_word("string",Dbw_string),
string(Data),append(Types1,[[T,Dbw_string]],Types2),!.
data_to_types(Data1,Types1,Types2) :-
get_lang_word("t",T),
get_lang_word("brackets",Dbw_brackets),
Data1=[[Data2]],
data_to_types(Data2,[],Types4),
Types5=[[[T,Dbw_brackets],Types4]],
append_list([Types1,Types5],Types2),!.
data_to_types(Data1,Types1,Types2) :-
get_lang_word("t",T),
get_lang_word("brackets",Dbw_brackets),
Data1=[[Data2]|Data4],
data_to_types(Data2,[],Types4),
Types5=[[[T,Dbw_brackets],Types4]],
data_to_types(Data4,[],Types6),
append_list([Types1,Types5,Types6],Types2),!.
data_to_types(Data1,Types1,Types2) :-
get_lang_word("t",T),
get_lang_word("brackets",Dbw_brackets),
Data1=[[Data2|Data3]|Data4],
data_to_types(Data2,[],Types3),
data_to_types(Data3,Types3,Types4),
Types5=[[[T,Dbw_brackets],Types4]],
data_to_types(Data4,[],Types6),
append_list([Types1,Types5,Types6],Types2),!.
data_to_types(Data1,Types1,Types2) :-
Data1=[Data2|Data3],
data_to_types(Data2,Types1,Types3),
data_to_types(Data3,Types3,Types2),!.
%%Types2=[Types4].
append_list(A1,B):-
append_list(A1,[],B),!.
%/*
append_list([],A,A):-!.
append_list(List,A,B) :-
List=[Item|Items],
append(A,Item,C),
append_list(Items,C,B).
%*/