While I am thrilled about all the new features we've put into the F# CTP, perhaps the thing I'm most excited about are the MSBuild tasks for Lex and Yacc. You heard that right. If you want to use fslex.exe of fsyacc.exe as part of your project, you can now integrate them into your project via MSBuild. And the thing that makes this feature even better is the fact that I wrote the build tasks. (That’s right, testers do write features at Microsoft HUZZAH!)

To wire in fslex and fsyacc files, simply add the following snippet to your .FSPROJ file:

  <!-- Generate the lexer and parser -->
  <ItemGroup>
    <FsYacc Include="Parser.fsy" />
    <FsLex Include="Lexer.fsl" />
  </ItemGroup>

 

And import the F# PowerPack targets file.

<Import Project="$(MSBuildExtensionsPath)\FSharp\1.0\FSharp.PowerPack.Targets" />

And auto-magically Lex and Yacc will be kicked off as part of your build. Even better, is that since they are integrated into MSBuild the files won’t be regenerated unless the lexer or parser has changed. Which for sufficiently advanced parsers is a dramatic time savings.

To demonstrate this I’ve updated my MegaCalc project to the new F# Project System. Which if you recall is a simple four-function calculator written in F#.

clip_image002

Disclaimer: All code samples are provided "AS IS" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. So in other words, if the attached source files cause you any grief whatsoever you can’t blame me or Microsoft.