This is an age-old question, one that I have never really seen a clear cut answer to. I think there are many possibilities: they like the taste of grass, they are hungry, they are not feeling well and eating something to see if that helps (kind of like humans do sometimes!).
Grass is also part of a carnivore's diet -- usually consumed when they feed on smaller prey and consume the entire animal; including grassy stomach contents.
Most dogs do best with 2 or more small feedings a day rather than one large feeding. Cats optimally would feed several small meals throughout the day. Ideally, for both dogs and cats, food should be available at all times. This aids in weight control (food is no longer a "big deal" and helps maintain digestive health. This is not possible in many situations and busy lifestyles, but if possible, my preferred way to feed pets.
A commercial diet or well-prepared home diet should not be lacking in essential nutrients. If they have an empty stomach, bile may reflux (flow back up in to the stomach from the intestine) and this is irritating. This can cause vomiting of clear, yellow fluid.
Any time that your pet experiences lack of appetite, eating odd items (pica), or vomiting, it is always best to check with your vet. Gastrointestinal blockages are emergencies. Changes in appetite or vomiting can also indicate internal disease (kidney failure, hyperthyroidism, etc.), toxin ingestion, or infectious disease, just to name a few possibilities. Always best to check things out with your vet.
By Janet Tobiassen Crosby, DVM, About.com