Skip to content

Commit 1fe29c7

Browse files
committed
Classify grammars with cycles as not LL(1)
1 parent 42d1044 commit 1fe29c7

File tree

4 files changed

+554
-1
lines changed

4 files changed

+554
-1
lines changed

src/grammar/calculations/parsing/ll/ll1_classification.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as SetOperations from "../../../../set_operations.js";
22
import { getFirst } from "../helpers.js";
33

44
export default function(calculations) {
5-
const { nullAmbiguity } = calculations;
5+
const { nullAmbiguity, cycle } = calculations;
66

77
var i, k, l, s;
88
var head, body, bodyFirst;
@@ -13,6 +13,12 @@ export default function(calculations) {
1313
return { member: false, reason: "it contains a null ambiguity" };
1414
}
1515

16+
// Also, return immediately if the grammar contains a cycle.
17+
18+
if (typeof cycle !== "undefined") {
19+
return { member: false, reason: "it contains a cycle" };
20+
}
21+
1622
const { productions, first, follow, terminals, nonterminals, nullable } = calculations;
1723

1824
// Check for first set clashes. Instead of checking intersections of

test/fixtures/example_grammars.js

+4
Original file line numberDiff line numberDiff line change
@@ -501,5 +501,9 @@ export default {
501501
["D", "E"],
502502
["T", "X"],
503503
["X"]
504+
],
505+
"issue-41": [
506+
["S", "E"],
507+
["E", "E"]
504508
]
505509
};

0 commit comments

Comments
 (0)