Monday, September 22, 2008

Creating a parser with F#

I want to write my own html-parser. That is one of the reasons I am learning F#. I have read all the documentation that is available in the three published F# books and tried to build some simple parsers myself and downloaded the examples of Chris Smith.

This resulted in a naïve development approach: start with lexer, than create the parser, compose the AST and finally build your application that consumes the AST.

One of the lessons learned: when you want to create a parser you have to start with analyses of the text type. In case you can step through the text and can determine the action after each token a lexer is what you need. In case the action is determined by server tokens you need a parser.

Example of program that needs a lexer:

  • A program that replacing digits by roman numerals.
  • A simple encryptor

Example of program that needs a lexer and a parser:

  • Xml-parser
  • Code

No comments:

Total Pageviews