0

I want to translate a grammar rule like this, into a clause

char(C) --> [C], { code_type(C, graph), \+ memberchk(C, "()") }.

but does not work

char(C,In,Out):-
   In=[C|Out],
   code_type(C, graph), 
   \+ memberchk(C, "()").
false
  • 10,264
  • 13
  • 101
  • 209
Vincenzoni
  • 55
  • 4

1 Answers1

1

You can use the expand_term/2 built-in Prolog predicate to expand grammar rule into clauses:

?- expand_term((char(C) --> [C], { code_type(C, graph), \+ memberchk(C, "()") }), Clause).
Clause = (char(C, [C|_G1665], _G1651):- (code_type(C, graph), \+memberchk(C, [40, 41])), _G1651=_G1665).
Paulo Moura
  • 18,373
  • 3
  • 23
  • 33