+1  A: 

Well, you could start with a big if-else statement just looking for keywords, like Eliza.

When that is not enough then you could move to pairs of ordered keywords and keyword modifiers , like NOT, MY, etc.

When that's not enough then you get in to grammars. You start with simple grammars like the ones used in the old infocom text-based games.

When that's still not enough then you enter the realm of natural language processing. You pick up Russel&Norvig's intro to AI book and then pickup a recent textbook from MIT Press on NLP and go to town on those algorithms.

Jose M Vidal
A: 

If you want to know what already exists, take a look at "chatterbot" on delicious.

Maybe you could begin with AIML (ALICE).

I personally wrote such a chatterbot in C, but it was first hard-coded, and then I used a small table of stimuli-responses (Achille was the name of this software): http://francois.parmentier.free.fr/irc/achille_e.html (look at vlad-ons.c). Hum! I realize now that it is an old program, mainly hard-coded for French keywords :/

H_I