Grammar consists of many things, and one of the more important is punctuation. It is like the Rosetta Stone, providing the key to how writers want a reader to interpret what they wrote.
Punctuation is even present when we speak. A slight pause is similar to a comma, a longer pause akin to a semicolon, and a stop equals a period. Question marks and exclamation points can be heard in the cadence of a person's speech pattern and where the emphasis is placed and on which words.
Almost all punctuation marks are represented in everyday speech and therein lies the key to great dialogue-knowing how to use punctuation correctly with dialogue.
There are some writers who are masters at it. Elmore Leonard was one of the best. Read his books, or listen to a few of the movies made from his books, and you'll see a genius's work.
This book explains how to use punctuation in an easy-to-grasp manner.