Formal grammar is heavily based in syntax. It is possible to generate sentences by using word lists and rules in a computer program, but the output rarely makes much sense and can be exceedingly funny.
By ignoring syntax whilst chaining words together based on the frequency with which words follow one another, one can build an interesting 'sentence'. The most famous such chain is Noam Chomsky's 'colorless green ideas sleep furiously'. It obeys the rules of syntax but it makes no sense.
The reason it makes no sense is that it has consistently been taken out of context. It is not a sentence. It is part of a greater whole, and when restored to its rightful place as a string of words within a sentence, it makes perfectly good sense.
"The environmentalists, having caught malaria whilst on a field trip abroad to try to inform their colorless green ideas sleep furiously with much sweating and throwing off of blankets."
Context counts for much in linguistics.