Variables using DCG

I am having problems with syntax sequences that start with capital letters in variables using the Prolog DCG notation. For example, if I have a string

f a X y Z X

and DCG, which parses this string, is there a way to parse each uppercase letter into a unique Prolog variable. For example, analyze a Yvariable and each Xvariable? The intended application would have to create a functor

T = f(a,X,y,Z,X)

using a DCG rule ending with an operator

{T =.. [Head|Args]}
+3
source share
2 answers

You may be looking for term_to_atom/3:

?- term_to_atom(Term, 'f(a,X,y,Z,X)').
Term = f(a, _G304, y, _G306, _G304).
+3
source

, . . 'X' 'Z'.

.

+3

All Articles