Reductions need to be performed in a careful order in GLR parser, to make sure we gather all alternatives before creating an ambigous forest node. This patch encodes the nonterminal order into the rule id, so that we can efficiently to determinal ordering of reductions in GLR parser. This patch also abstracts to a TestGrammar, which is shared among tests. This is a part of the GLR parser, https://reviews.llvm.org/D121368, https://reviews.llvm.org/D121150 Differential Revision: https://reviews.llvm.org/D122303
30 lines
909 B
Plaintext
30 lines
909 B
Plaintext
_ := expr
|
|
expr := id
|
|
id := IDENTIFIER
|
|
|
|
# RUN: clang-pseudo -grammar %s -print-graph | FileCheck %s --check-prefix=GRAPH
|
|
# GRAPH: States:
|
|
# GRAPH-NEXT: State 0
|
|
# GRAPH-NEXT: _ := • expr
|
|
# GRAPH-NEXT: expr := • id
|
|
# GRAPH-NEXT: id := • IDENTIFIER
|
|
# GRAPH-NEXT: State 1
|
|
# GRAPH-NEXT: _ := expr •
|
|
# GRAPH-NEXT: State 2
|
|
# GRAPH-NEXT: expr := id •
|
|
# GRAPH-NEXT: State 3
|
|
# GRAPH-NEXT: id := IDENTIFIER •
|
|
|
|
# RUN: clang-pseudo -grammar %s -print-table | FileCheck %s --check-prefix=TABLE
|
|
# TABLE: LRTable:
|
|
# TABLE-NEXT: State 0
|
|
# TABLE-NEXT: 'IDENTIFIER': shift state 3
|
|
# TABLE-NEXT: 'expr': go to state 1
|
|
# TABLE-NEXT: 'id': go to state 2
|
|
# TABLE-NEXT: State 1
|
|
# TABLE-NEXT: 'EOF': accept
|
|
# TABLE-NEXT: State 2
|
|
# TABLE-NEXT: 'EOF': reduce by rule 1 'expr := id'
|
|
# TABLE-NEXT: State 3
|
|
# TABLE-NEXT: 'EOF': reduce by rule 0 'id := IDENTIFIER'
|