[PATCH] D121368: [pseudo][WIP] Build Ambiguous forest node in the GLR Parser.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 10 03:07:03 PST 2022


hokein created this revision.
hokein added a reviewer: sammccall.
Herald added a project: All.
hokein requested review of this revision.
Herald added a subscriber: alextsao1999.
Herald added a project: clang.

Forest node by design is unmutable. To create an ambiguous node, we have
to know all alternatives in advance.

In order to achieve that, we must perform all reductions in a careful
order (see code comments for details), so that we can gather completed
alternatives as a batch, and process them in a single pass.

E.g. considering the following grammar:

  bnf
  TU := stmt
  TU := expr
  stmt := expr
  expr := ID
  stmt := ID
  
  // Ambiguous stmt forest node:
  //     stmt (ambiguous)
  //    /     \
  //   /      stmt
  //   |       |
  //  stmt   expr
  //    \     /
  //       ID

The ambiguous Stmt node is built in a single section where we perform three reductions:

1. expr := ID
2. stmt := ID
3. stmt := expr (enabled after 1 is performed)

We expect to perform them in a batch way with the order {1}, {2, 3}.
When processing the batch {2, 3} where ambiguity happens, we build an
ambiguous node for stmt.

Based on https://reviews.llvm.org/D121150


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121368

Files:
  clang/include/clang/Tooling/Syntax/Pseudo/Forest.h
  clang/include/clang/Tooling/Syntax/Pseudo/GLRParser.h
  clang/include/clang/Tooling/Syntax/Pseudo/Grammar.h
  clang/lib/Tooling/Syntax/Pseudo/GLRParser.cpp
  clang/lib/Tooling/Syntax/Pseudo/GrammarBNF.cpp
  clang/tools/clang-pseudo/ClangPseudo.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D121368.414327.patch
Type: text/x-patch
Size: 20603 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220310/37c9d151/attachment-0001.bin>


More information about the cfe-commits mailing list