Simple but Powerful Pratt Parsing › 介绍 Introduction [#263]

解析 ( parsing ) 是编译器将一系列 标记 ( token ) 转换为树状表示的过程:
Parsing is the process by which a compiler turns a sequence of tokens into a tree representation:

                            Add
                 Parser     / \
 "1 + 2 * 3"    ------->   1  Mul
                              / \
                             2   3

有许多方法可以完成这个任务,这些方法大致可以归为以下两类:
There are many approaches to this task, which roughly fall into one of the broad two categories:

  • 使用 DSL 来指定语言的抽象文法
  • 手写解析器
Using a DSL to specify an abstract grammar of the language
Hand-writing the parser

Pratt 解析是手写解析最常用的技术之一。
Pratt parsing is one of the most frequently used techniques for hand-written parsing.