What is the best way to use F# to parse an AST to build an interpreter? There are plenty of F# examples for trivial syntax (basic arithmatical operations) but I can't seem to find anything for languages with much larger ranges of features.
Discriminated unions look to be incrediably useful but how would you go about constructing one with large number of options? Is it better to define the types (say addition, subtraction, conditionals, control flow) elsewhere and just bring them together as predefined types in the union?
Or have I missed some far more effective means of writing interpreters? Is having an eval function for each type more effective, or perhaps using monads?
Thanks in advance
How to get facebook data from app?
Anyone have more details on a XBox 360 Console History Export Project?
Discriminated unions look to be incrediably useful but how would you go about constructing one with large number of options? Is it better to define the types (say addition, subtraction, conditionals, control flow) elsewhere and just bring them together as predefined types in the union?.I am not sure what you are asking here; even with a large number of options, DUs still are simple to define.
Facebook API - Feed.registerTemplateBundle issues
Facebook user has no avatar, but the default blank avatar isn't showing either in my web app
Experience as a Facebook Software Engineering Intern
this blog entry for a tiny language's DU structure (as well as a more general discussion about writing tree transforms).
What web APIs would you most want to replicate or are the most popular?
It's fine to have a DU with many more cases, and common in compilers/interpreters to use such a representation..
acegi + facebook / myspace / google
As for parsing, I prefer monadic parser combinators; check out FParsec or see this old blog entry.
Can I use Facebook's fb:friend-selector in an iframe?
After using such parser combinators, I can never go back to anything like lex/yacc/ANTLR - external DSLs seem so primitive in comparison.. (EDIT: The 'tiny arithmetic examples' you have found are probably pretty much representative of what larger solutions looks like as well.
The 'toy' examples usually show off the right architecture.).
The most important part is what you are looking for: the AST parser.. Good luck..
If you're interested in doing things the old-school way with FsLex and FsYacc, one place to look for how to parse a non-trivial language is the F# source itself.
source\fsharp\FSharp.Compilerdirectory in the distribution..
The F# PowerPack library contains the FsLex and FsYacc tools, which asssist greatly with this.
The WikiBook guide is a good way to get started with this.. Beyond that, you will need to think about how you actually want to execute the code from the AST form, which is common the design of both compilers and interpreters.
This is generally considered the easier part however, and there are lots of general resources on compilers/interpreter out there that should provide information on this..
Hope the following helps:). Here's a compiler course taught at Yale using ML, which you might find useful.
The lecture notes are very concise (short) and informative.
You can follow the first few lecture notes and the assignments.
As you know F#, you won't have problem reading ML programs.
. Btw, the professor was a student of A.
Appel, who is the creator of SML implementation.
So from these notes, you also get the most natural way to write a compiler/interpreter in ML family language.
It includes even IL compiler.
The whole code is very accessible and is accompanied by a series of blog post from the author at http://trelford.com/blog/.