recently I've been playing with DCG in Prolog but I've been facing some issues regarding how exactly does it work. For instance, I have this small grammar:
<atom> :: <letter> <atom_part> | <letter>
<atom_part> :: <letter> | <digit> | <letter> <atom_part> | <digit> <atom_part>
<letter>:: 'a' | 'b' ... |'Z'
<digit> :: '0' |...|'9'
Which, If I'm not mistaken, is any string of letters or numbers that must start with a letter. Anyway, my attempt to parse it is the following:
letter("a") --> "a".
number(X) --> number(X).
...
%etc
programme(I) --> atomm(I).
atomm(C) --> letter(Ch).
atomm(C) --> numb(Ch).
atomm((E)) --> atomm_part(E).
atomm_part(E1,E2) --> atomm(E1),!,atomm(E2).
Here I think is clear that the last 2 lines are wrong. That's really because I'm not sure how to make the 'recursive call' so the parser goes again to check if the next character in the string is a number or a string. How can I correct this? Thanks in advance!
btw, i'm using swi-prolog