This excerpt is from Pete Shotton's excellent book 'The Beatles, Lennon And Me' (originally published as "John Lennon In My Life", 1983, Stein and Day Publishers... not to be confused with "In My Life - John Lennon Remembered" by Kevin Howlett and Mark Lewisohn).
(If you're not familiar, Pete Shotton was Lennon's closest boyhood pal, an original member of the Quarrymen (until John broke the washboard over Pete's head!), and a close friend and confidant of John's to the very end.)
From page 217:
"One afternoon, while taking "lucky dips" into the day's sack of fan mail, John, much to both our amusement, chanced to pull out a letter from a student at Quarry Bank. Following the usual expressions of adoration, this lad revealed that his literature master was playing Beatles songs in class; after the boys all took their turns analyzing the lyrics, the teacher would weigh in with his own interpretation of what the Beatles were really talking about. (This, of course, was the same institution of learning whose headmaster had summed up young Lennon's prospects with the words: "This boy is bound to fail.")
"John and I howled in laughter over the absurdity of it all. "Pete," he said, "what's that 'Dead Dog's Eye' song we used to sing when we were at Quarry Bank?" I thought for a moment and it all came back to me:
Yellow matter custard, green slop pie,
All mixed together with a dead dog's eye,
Slap it on a butty, ten foot thick,
Then wash it all down with a cup of cold sick.
"That's it!" said John. "Fantastic!" He found a pen commenved scribbling: "Yellow matter custard dripping from a dead dog's eye...." Such was the genisis of "I Am the Walrus" (The Walrus itself was to materialize alter, almost literally stepping out of a page in Lewis Carroll's 'Through the Looking Glass')
Inspired by the picture of that Quarry Bank literature master pontificating about the symbolism of Lennon-McCartney, John threw in the most ludicrous images his imagination could conjure. He thought of "semolina" (an insipid pudding we'd been forced to eat as kids) and "pilchard" (a sardine we often fed to our cats). Semolina pilchard climbing up the Eiffel Tower....," John intoned, writing it down with considerable relish.
He turned to me, smiling. "let the f*ckers work THAT one out, Pete."