Is there a quick and easy way to translate the Prolog representation of a DCG production back to DCG notation? Ideally, I’d like to find a library that already does that, so that I don’t have to roll my own.

To clarify, suppose I translate the following production using dcg_translate_rule/2:

?- dcg_translate_rule(('S'-->'A','B'), P), numbervars(P). % for readability
P = ('S'(A, B):-'A'(A, C), 'B'(C, B)).

Can I translate P back to ('S'-->'A','B') easily? Is there a library or pack that does that? A quick look did not turn up anything.

AFAIK, not. For a specific DCG translator this is probably possible. In general it might be hard as there are multiple valid translations for the same non-terminal rule.

Gladly, but the effort will probably be spread over a long time because it’s not something absolutel necessary- rather, it’s something that would be “nice to have” for a certain project of mine.

If you want you can always drop some simple things into a few post and then latter they can be edited/deleted/moved/converted into another category/etc.