Treetop: Syntactic Analysis with Ruby
summary
Treetop presents a Ruby grammar engine that uses parsing expression grammars and packrat parsing so code parses without a separate lexer, trading memory for simpler composition. The demo builds an arithmetic parser and a 132-line interpreter for an extended lambda calculus, with unit tests showing the rules evaluate correctly and composition via modules working. Implementation compiles grammars to Ruby modules, instantiates syntax node objects, and accepts the cost of object allocation for clearer, reusable grammars under Treetop.
AI-written summary · about
chapters (18)
- 0:00Start
- 4:52What Is a Context-Free Grammar
- 6:45Context-Free Grammar
- 7:58Context-Free Generative Grammar
- 8:37Dangling Else Problem
- 9:41Parsing Expression Grammars
- 12:00Pumping Lemma
- 13:31Load Grammar Declaration
- 15:44Custom Subclass of Syntax Node
- 17:38Parse the Language of Arithmetic
- 19:28Defining the Arithmetic Grammar
- 21:30Test Variables
- 23:39Multiplication
- 29:35Change the Operator
- 31:22Parentheses That Override the Operator Precedence
- 34:12Packrat Parsing
- 35:59Lambda Calculus
- 37:25Source Code of the Lambda Calculus Interpreter








