Parallax Gyroscope Module 3-Axis L3G4200D sample code

I'm looking at using this in a walking robot but completely out of my depth on how to handle it. The first piece of code at a glance look like it will work expcluding the fact that the x/y/z axis remain the same if the robot turns. In other words what is the x-axis when the robot it waling forward becomes the y axis when it turns. I want the robot to be able to recover from a knockdown using this data and not quite sure on how to do it?