user13744: I want to build a program that makes and reads PGNs. What is valid PGN? What arguments are valid in the header?
What values are mandatory, what can be omitted?
Can I find somewhere rules for composing PGNs?

user29: The PGN (Portable Game Notation) format has its origins in a text document from 1994. It contains a specification and copious examples.
The best location to read the original text transformed into a web-optimized format is at this link. The Colophon near the beginning discusses the different iterations the original text went through before finding its way to that website.
Different PGN readers have implemented various aspects of this format and taken liberties of their own. Still, this is the closest you'll find to an official standard.

user825: PGN is not a rigorous file format. Everything in the wikipedia link (posted by @Ghotir) applies, but nothing is "mandatory".
The most common headers are:

Event
Site
Date
Round
White
Black
Result

But they are not mandatory. For example, you can get away by not specifying the player names.
Most chess programs only require you to define a header, but it can be anything. You have to define something because that's how chess programs parse the file - it expects the [ character.
Your PGN parser must be robust and handle invalid PGN scenarios. I personally deliver PGN softwares, and I know what I'm talking about. Common PGN errors:

"o", '0' in castling (e.g: "o-o", "0-0"). Correct is "O-O", but many people confuse the letters.
"{" instead of "["
"1-o" or "1-O" instead of "1-0"


13744: <p>I want to build a program that makes and reads PGNs. What is valid PGN? What arguments are valid in the header?
What values are mandatory, what can be omitted?</p>

<p>Can I find somewhere rules for composing PGNs?</p>
 29: <p>The PGN (Portable Game Notation) format has its origins in a text document from 1994. It contains a specification and copious examples.</p>

<p>The best location to read the original text transformed into a web-optimized format is at <a href="http://www.saremba.de/chessgml/standards/pgn/pgn-complete.htm" rel="nofollow noreferrer">this link</a>. The Colophon near the beginning discusses the different iterations the original text went through before finding its way to that website.</p>

<p>Different PGN readers have implemented various aspects of this format and taken liberties of their own. Still, this is the closest you'll find to an official standard.</p>
 825: <p>PGN is not a rigorous file format. Everything in the wikipedia link (posted by @Ghotir) applies, but nothing is "mandatory".</p>

<p>The most common headers are:</p>

<ul>
<li>Event</li>
<li>Site</li>
<li>Date</li>
<li>Round</li>
<li>White</li>
<li>Black</li>
<li>Result</li>
</ul>

<p>But they are not mandatory. For example, you can get away by not specifying the player names.</p>

<p>Most chess programs only require you to define a header, but it can be anything. You have to define something because that's how chess programs parse the file - it expects the <code>[</code> character.</p>

<p>Your PGN parser <strong>must</strong> be robust and handle invalid PGN scenarios. I personally deliver PGN softwares, and I know what I'm talking about. Common PGN errors:</p>

<ul>
<li>"o", '0' in castling (e.g: "o-o", "0-0"). Correct is "O-O", but many people confuse the letters.</li>
<li>"{" instead of "["</li>
<li>"1-o" or "1-O" instead of "1-0"</li>
</ul>
