Lexing and Parsing with F# – Part I

logicboost's avatarLogicBoost blog

September 10th 2010 | David Cooksey

Lexing and Parsing with F# – Part 1

FsLex and FsYacc are F# implementations of Ocaml’s Lex and Yacc. They are part of the F# Powerpack released for Visual Studio 2010. Used together, they take an input string and create a parse tree of typed objects. Once you have the parse tree, you can do anything with it—generate code for another language, interpret it directly, etc. If you’d like to jump right into the code, scroll to the bottom of the post. Note that the code includes a small test project using FsUnit.


FsLex is the lexer part of the lexer-parser pair
. It converts an input string or stream into a series of tokens. A token is simply a string labeled so that the parser knows how to handle it. For example, ‘92’ might be within a token labeled DIGIT. Simply put, the…

View original post 606 more words


Discover more from Sergey Tihon's Blog

Subscribe to get the latest posts sent to your email.

Leave a comment