Ugh, something like that happened to me before.  I had been studying a bunch of equations for p-chem.  I woke up in the middle of the night (well, I was still half asleep) and could only think in equations.  I kept trying to snap my self out of it and think normally but I couldn't.  It was very annoying, especially considering they weren't even valid equations.  At least I don't think they were...
My dream last night was sort of interesting, although it ended rather horridly.  It started out that I was in a corn maze, but that eventually changed into a very elaborate building.  I discovered stairs and realized I had to go up to the very top of the building, so I ran up the stairs.  By this time, the building was more like a museum and there were a bunch of other people around.  I reached the top room and found the stuffed chicken there (which naturally was what I had been looking for all along!).  I took a picture of the chicken to prove it had been found and started back down a gravel road, since the building was no longer a building, but some sort of park.  Then I saw two squirrels fighting, so I went to get a closer look because squirrels are cute.  One of them had a tiny baby squirrel under it.  As I knelt down to take a picture, the squirrel suddenly squashed the baby, bursting it in a mini explosion of squirrel guts.  Apparently the baby had been the other squirrel's, killed out of spite.  Then I woke up.
Dreams are weird.