Skip to content

Tips on Using pgen2

andychu edited this page Aug 30, 2019 · 1 revision

Back: Implementing the Oil Expression Language

pgen2 is the LL parser generator borrowed from Python, used for recognizing the Oil expression language (which is based on Python). Caveat: it's a bit hard to use!!!

Tips:

  1. Print out the parse tree with print_parse_tree in frontend/parse_lib.py. The structured of the parse tree depends on the exact structure of the grammar's rules.
  2. In oil_lang/expr_to_ast.py, make sure you copy the relevant productions into comments. That will make it easier to write the "transformer".
  3. See opy/compiler2/transformer.py for "tips" on transforming rules to AST nodes. However, note that we have the "singleton-collapse" rule which OPy doesn't have. Ping me for details if you don't understand this.
Clone this wiki locally