[PATCH] D121150: [pseudo][WIP] Implement a GLR parser.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 7 13:03:25 PST 2022


hokein added a comment.

This is an initial version, not unittests yet, but it should be good enough for high-level reviews.

Basically, it contains all key pieces of the GLR parser:

- ForestForest: it is a DAG with compact nodes (8 bytes per node). It is not mutable by design. The code is mostly derived from our prototype, and might need some improvements.

- Graph-structured stack: the GSS is a simple implementation -- only allocation for new nodes, and no deallocation for dead nodes. We should figure out whether it is worth the effort to implement a smart deallocation. The GSS only affects the peak memory usage during parsing, it can be thrown away after we build the forest. In addition, the forest node is stored in the graph node, rather than the edge (per our discussion, it felt more natural and better fit to our mental model to store forest nodes in edges, but I found that the implementation was awkward, and finally abandoned that).

- Core GLR parsing algorithm: it should be in a good state for review, it is missing the bit of producing ambiguous forest-node (as we use a non-mutable forest, this'd require some careful ordering when performing reduce actions, the implementation is tricky and takes some complexity, plan to do it in a follow up patch).

Some misc questions:

- is the current output of the forest ok? (I think in general it is ok)
- Any ideas about testing & debugging? Verifying the output forest is a way to test the GLR parser, but it doesn't seem to be an ideal way if we want to inspect the internal states of the parser during parsing. The alternative is to define a logger interface, the parser can invoke it at some points, so that we can inject some observers into the parser, and can use the log messages for testing and debugging purposes (see the LLVM_DEBUG usage in GLRParser.cpp).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121150/new/

https://reviews.llvm.org/D121150



More information about the cfe-commits mailing list