CS116 - Artificial Intelligence
Spring, 2004
(updated 1/20/2004)

HW 2, Due Mon. Jan. 26 (2:00pm), 2004

For this assignment, submit two lisp files.  Name them "hw2a.lisp" and "hw2b.lisp".  Submit these to the course WebCT site by 2pm on Friday (1/23).  The assignment will be graded on correctness, completeness, and coherence (style and elegance).

1.  Write a pattern-matching function that takes two arguements: a pattern or template expression and an arbitrary s-expression which will be searched for a sub-structure that matches the pattern.  Your patterns will use the asterisk as the wildcard character.  For example, the pattern (a * c) matches all of the lists (a b c), (a (e) c), (a (c (x)) c), and (a anything c), but does not match any of the lists (a c d), (a x c d), or ((a) b c).  Define your functions as "pm-1"; this function should return t if the pattern matches, or nil otherwise.  Note, your function should correctly handle multiple wildcard characters in the pattern.

2.  Write an infix mathematical expression parser.  Your function should take as input (for example), the list '(3 + 4 * (11 - 9)) and return (+ 3 (* 4 (- 11 9))).  You should assume that your inputs are valid infix math expressions and have spaces between numbers and operators (except specifying a negative number is allowed, such as -2.1, which would not have a space between the minus sign and the number).  You need only handle the four operators +, *, -, and /.  Parentheses in the infix expression should be treated appropriately as determining the course of evaluation.  Note, you should apply standard operator precedence in the construction of your returned expression.