/* cs342 homework 7 Dan J. Fraser (1219229) 5] evaluate(ParseTree, Value) calculates the Value that corresponds to ParseTree in a manner similar to Section 11.1 of the Prolog text [An Introduction to Logic Programming through Prolog by Michael Spivey]. 6] tokenize(Sentence, Tokens) says whether or not Tokens is the list of words that form Sentence. It can't find the Sentence for given Tokens, but it can find the Tokens for a given Sentence. Since this program is processing English, tokens are the same as words. A word can be a delimiter or a sequence of characters that contains neither a space nor a delimiter, but is followed by a space, a delimiter, or the end of the list. Grammar: question ::= "How much is" number_expression "?" number_expression ::= number number_expression ::= "the sum of" sum_number_list number_expression ::= "the product of" product_number_list sum_number_list ::= number_expression "and" number_expression sum_number_list ::= number_expression "," sum_number_list sum_number_list ::= number_expression "," "and" number_expression product_number_list ::= number_expression "and" number_expression product_number_list ::= number_expression "," product_number_list product_number_list ::= number_expression "," "and" number_expression */ parse("How":"much":"is":Tokens,question(ParseTree)) :- print("parsing."),nl, append(B,"?":nil,Tokens), not B = nil, print("b: "),print(B),nl, number_expression(B,ParseTree). number_expression(B,number(Y)) :- evaluate_number(B,Y). number_expression(B:nil,number(Y)) :- evaluate_number(B,Y). number_expression("the":"sum":"of":SumExpr,ParseTree) :- print("sum expr: "), print(SumExpr),nl, sum_number_list(SumExpr,ParseTree), print("sum expr done: "),print(ParseTree),nl. number_expression("the":"product":"of":ProductExpr,ParseTree) :- print("product expr: "), print(ProductExpr),nl, product_number_list(ProductExpr,ParseTree), print("product expr done: "),print(ParseTree),nl. sum_number_list(SumExpr,sum(T1,T2)) :- print("working on sum rule 1"),nl, append(T0,",":List,SumExpr), not T0 = nil, print("T0: "),print(T0),nl, number_expression(T0,T1), print("T1: "),print(T1),nl, print("List: "),print(List),nl, sum_number_list(List,T2), print("T1: "),print(T1),nl, print("T2: "),print(T2),nl. sum_number_list("and":SumExpr,T1) :- print("working on sum rule 2"),nl, number_expression(SumExpr,T1), print("SumExpr: "),print(SumExpr),nl, print("T1: "),print(T1),nl. sum_number_list(SumExpr,sum(T1,T2)) :- print("working on sum rule 3"),nl, append(T0,"and":List,SumExpr), number_expression(T0,T1), not T0 = nil, print("T0: "),print(T0),nl, print("List: "),print(List),nl, number_expression(List,T2), print("T1: "),print(T1),nl, print("T2: "),print(T2),nl, print("List: "),print(List),nl. product_number_list(ProductExpr,product(T1,T2)) :- print("working on Product rule 1"),nl, append(T0,",":List,productExpr), not T0 = nil, print("T0: "),print(T0),nl, number_expression(T0,T1), print("T1: "),print(T1),nl, print("List: "),print(List),nl, product_number_list(List,T2), print("T1: "),print(T1),nl, print("T2: "),print(T2),nl. product_number_list("and":ProductExpr,T1) :- print("working on product rule 2"),nl, number_expression(ProductExpr,T1), print("productExpr: "),print(productExpr),nl, print("T1: "),print(T1),nl. product_number_list(ProductExpr,product(T1,T2)) :- print("working on product rule 3"),nl, append(T0,"and":List,ProductExpr), number_expression(T0,T1), not T0 = nil, print("T0: "),print(T0),nl, print("List: "),print(List),nl, number_expression(List,T2), print("T1: "),print(T1),nl, print("T2: "),print(T2),nl, print("List: "),print(List),nl.