I'm working with Prolog arithmetic and have a program that generates an abstract syntax tree, such as plus(num(1),num(2))
which simply is 1+2
. This is done by using DCG. In this example plus(num(1),num(2))
is the same as the prefix list representation [+,1,2]
.
My problem is that I only want to allow num(x)
greater than 3. For example num(4)
is allowed but not num(1)
.
I'm doing this by:
num(num(4)) --> [4].
num(num(5)) --> [5].
num(num(6)) --> [6].
num(num(7)) --> [7].
etc. but would like to do something like num(num(x)) --> [x].
for numbers greater than 3. Any idea as to how to approach this problem?