Start here, but it is basic: http://pear.php.net/manual/en/package.php.php-codesniffer.coding-standard-tutorial.php
PHP_CodeSniffer comes with quite a lot of sniffs that do a lot of different things. It might be worth looking through some of those to see how they make use of the token stack.
Using the -vv command line argument is also a really good way to see how a file is converted into tokens. This will help you register to look for the correct token types and make use of the $phpcsFile->findNext() and $phpcsFile->findPrevious() methods that many sniffs use.
Here is a small sniff that might be worth looking at: https://github.com/squizlabs/PHP_CodeSniffer/blob/master/CodeSniffer/Standards/PSR2/Sniffs/ControlStructures/ElseIfDeclarationSniff.php
And another that shows the usage of additional indexes in the token stack: https://github.com/squizlabs/PHP_CodeSniffer/blob/master/CodeSniffer/Standards/PSR2/Sniffs/ControlStructures/ControlStructureSpacingSniff.php