Write a program that does calcuations (addition and multiplication) where the interface looks like English, for example
How much is the product of 1, 2, 3, 4, and 5?
You are given all of the program except the part that parses the subset
of English being used. In preparation for the upcoming year 2001, the
main predicate is called hal_9000.
Details:
For a competing implementation that taking a different approach, see 3001 by Arthur C. Clarke: Talk to HAL 9000.
1] hal_9000(Sentence, Response) is the start of construction of the
program for the HAL 9000 computer. This first step is meant to
compute numeric responses to simple English questions. Samples
of the kinds of questions we are trying to handle are:
How much is 3?
How much is the sum of 3 and 4?
How much is the sum of 3, 4, and 5?
How much is the product of 12 and 5?
How much is the product of 1, 2, 3, 4, and 5?
How much is the sum of 1, 2, the product of 3 and 4, and 5?
The above six questions are wellformed under the following rules.
Each question begins with "How much is" and ends with a question
mark. In general wherever a number could occur a sum or product
could also occur. You can sum or product two or more numbers.
If two numbers, then they are separated by `and'. If more than two
numbers, then each number before the `and' is followed by a comma.
Anything that is not well formed under the above is not well formed
and an attempt to parse it will fail.
Handin Requirements
cat Hmwk7.pp
cat Hmwk7.GivenRules.pp
pprolog Hmwk7.pp Hmwk7.GivenRules.pp
test_hal.
test_hal_some_more.
Reference:
Chapters 10 and 11 of the Spivey text on Prolog are sufficient for this assignment.
Sample Run:
This is an example of what it looks like to run this assignment on a sample program that moves the contents of the first location in memory to the eight location and then quits.
brown[221]: pprolog Hmwk7.Given.pp Hmwk7.pp Welcome to picoProlog Reading Hmwk7.Given.pp Reading Hmwk7.pp # :- test_hal. "In response to: How much is 3?" hal_says(3) "In response to: How much is the sum of 3 and 4?" hal_says(7) "In response to: How much is the sum of 3, 4, and 5?" hal_says(12) "In response to: How much is the product of 12 and 5?" hal_says(60) "In response to: How much is the product of 1, 2, 3, 4, and 5?" hal_says(120) "In response to: How much is the sum of 1, and 2?" "In response to: How much is the sum of 1, 2, the product of 3 and 4, and 5?" hal_says(20) no # :- ^D
Hints:
How much is the sum of 3, and 4 ?I let the grammar accept the above, but used a flag to let the prolog rules detect that the list `3,' was too short for there to be a `,'.