I need to parse a string representing function like this:
<fsignature>"(" <term1>, <term2> ... <termn>")"
The function' signature and terms also have to be controlled further for the function to be accepted. I've written this DCG in Prolog:
fsign --> {is_leg(A)}, [A].
terms --> (funct, funct; terms).
terms --> (terms, terms; term).
term --> {is_term(T)}, [T].
But it doesn't seem to work, when I try to use phrase(funct, [foo, "(", a, a, ")"]). it goes into overflow. is_leg just checks if the string is legal (a string starting with a character), while is_term should check if the term is a literal (either a constant, a variable or a function).
What is that it's not working? I figure, probably the variables - should I put them as arguments of the nonterminals?
Thanks for any help.
terms --> (terms, terms ; term).
is the same as:terms --> terms, terms.
andterms --> term.
The first is clearly going to be an infiinite recursion. It's unclear what you want this rule to say. - lurker