% -------------------------------------------------------------
% bottom-up chart parser with agenda of Gazdar/Mellish, p.208-210
% -------------------------------------------------------------

% load predicates used by all agenda chart parsers: start_agenda/3,
% extend_edges/3, add_edge/3, add_edges/3, not/1, member/2
:- ensure_loaded(common_code).

% -------------------------------------------------------------

new_edges(edge(V1,V2,Category1,[]),Chart,Edges) :-
	findall(edge(V1,V1,Category2,[Category1|Categories1]),
			  rule(Category2,[Category1|Categories1]),
			  Edges1),
	findall(edge(V0,V2,Category3,Categories2),
			  member(edge(V0,V1,Category3,[Category1|Categories2]),Chart),
			  Edges2),
	add_edges(Edges1,Edges2,Edges).
new_edges(edge(V1,V2,Category1,[Category2|Categories]),Chart,Edges) :-
	findall(edge(V1,V3,Category1,Categories),
			  member(edge(V2,V3,Category2,[]),Chart),
			  Edges).

% -------------------------------------------------------------

test(String) :-
	start_agenda(String,0,Agenda),
   extend_edges(Agenda,[],Chart),
	found_parse(Chart).

% -------------------------------------------------------------

