It's pretty simple really ...
AF - Auto-focus. Uses a motor mounted in the camera; unsuitable for AF use on a D40
AF-S - Auto-focus with a silent wave motor. The motor is mounted in the lens.
AI - Aperture Index (now basically obsolete)
D - Can report focus distance to the camera CPU
G - No aperture ring. Many newer lenses have this designation.
DX - Made for crop sensor cameras.
ED - Contains extra low dispersion glass elements. These elements help to reduce optical aberrations of various types.
IF - Internal focusing.
PC - Perspective control.
DF - (I think) Defocus - Throws certain areas of the projected image out of sharp focus.
What have I forgotten?