Skip to content

cbowdon/TDOP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Top Down Operator Precedence

This is a no-frills Haskell implementation of a Pratt parser, as described by Douglas Crockford. Given a string of code, it tokenizes it, then parses it into an abstract syntax tree. The parser implementation is completely decoupled from the rules for tokenizing and the AST data type, making it generally applicable. I drew upon this excellent example of a monadic Pratt parser in F#, although I think the Haskell solution has less complexity - possibly because the tokens are pre-processed into a list of symbols, rather than looking them up whilst parsing, which greatly simplifies error handling.

Limitations/TODO

  • Handling scope. Crockford's builds a tree of scopes as it goes, so probably will have to add something to InputState. This will make it uglier.
  • Curried functions in the example AST, Expr. I think this should be possible using the App constructor.

About

Monadic Pratt parser

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published