Possible Duplicate:
Prolog- translating English to C
We basically have an assignment where we're given a list that represent some notation in English, such as [add,3,to,5], and we need to take that and have it output the corresponding notation in C.
english2C([add,3,to,5], C).
C = 3+5
And we have a finite number of these. We can also combine two such lists to make a longer list
english2C([add,3,to,5,',',then,subtract,7], C).
C = 3+5-7
But these longer ones are always made up of the shorter lists, of which there are a set number of. That's where I'm stuck. I want to be able to use pattern matching but I'm not entirely sure how the syntax would be in prolog
english2C([first,second,third,fourth|rest], C)
*pseudo code*
match first with an operator
C = second (matched operator) third
So there would be one case for addition, one for subtraction, one for multiplication, etc. Basically I want to search the list for the phrase "add I to J" and unify that phrase with (I + J). Or search the list for "take the remainder of I after dividing by J" and unify it with (I '%' J). But all the phrases are of varying length and even though I know what I want to do and how to do it, I can't quite seem to get it in prolog.
Bit of an update, but I forgot to mention what I have right now a list of all base rules in a file, like so
rule([add,I,to,J], X) :- X = I+J
rule([subtract,I,from,J], X) :- X = J-I
etc, etc. The problem is combined lists. For example, the list we have could be [add,I,to,J,',',then,subtract,H] which would have to be I+J-H. The individual base rules (I+J and X-H) are defined but I have to be able to match each part in a longer list.