I have to write some code that translate numbers from english to french (from 1 to 999) using the DCG formalism of Prolog. Do I have to write down two separate grammar rules (one for english and one for french)or not? Can this piece of code found on the internet help me? https://groups.google.com/forum/?fromgroups=#!topic/comp.lang.prolog/ZF8p5cs4q0U Please Help.
You can do it in two steps (english to number, number to french) or you can try doing it directly from english to french. The two-step option is more generic (i.e. would let you convert it both ways, and you can easily extend it to support more languages), and you already have a working code available (the one in the linked topic), so I suggest following this route.
Just remember that, the same way a DCG rule allows you to parse some text, it allows you to generate it too. As the linked topic shows:
?- phrase(number(N), [one, hundred, and, twenty, seven]).
N = 127
?- phrase(number(127), L).
L = [one, hundred, and, twenty, seven]
If you replace the second part with phrase(number_fr(127), L)
, using the rules you implemented, you'd have the number you parsed earlier expressed in french.