Skip to content

A Pratt parser gem for Ruby. Create token objects to define your language.

License

Notifications You must be signed in to change notification settings

tommay/pratt_parser

Repository files navigation

Pratt Parser

Gem Version Build Status

A Pratt Parser. Just a simple parsing engine.

Define tokens that describe your language and combine terms. Write a Lexer (an Enumerator) that produces a stream of tokens. Instantiate a PrattParser and call #eval to parse the stream and return whatever your tokens want.

Pratt parsers are like recursive descent parsers but instead of having to code a function for each production you just code up some token objects which define their own prededence and associativity and how subexpressions to the left and/or right are combined. So it's simple to add new language features/tokens without having to rewrite a bunch of recursive descent functions.

Pratt parsers are also more efficient than recursive descent parsers since they don't need to recurse all the way down to the bottom level to figure out what to do.

Read more:

http://javascript.crockford.com/tdop/tdop.html

http://effbot.org/zone/simple-top-down-parsing.htm

http://journal.stuffwithstuff.com/2011/03/19/pratt-parsers-expression-parsing-made-easy/

About

A Pratt parser gem for Ruby. Create token objects to define your language.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages