Firstly, get the Compilers book that Fred recommended -- Its great!
If you want real world examples, Microsoft open sources most of C#...
Follow the link to
(if it doesnt work search for Shared Source Common Language
Infrastructure 2.0 Release). That should contain the code for the
CSharp lexer and parser.
You don't want to write these by hand. Look at the tool "lex" for
writing the lexer. It's mature and from the 70's... and its been
ported to modern languages like Java and C#.
Try the tool "yaac" to write the parser. It takes in a grammar and
generates the rest... I've only seen it in C++, but there might be a
similiar tool for C#. Keep in mind that certain grammars only work
with certain parsing strategies, for instance the Grammar S - > S a |
b would fall into an infinite loop in a recursive decent parser.