fixpoint algorithm: parameterize the Map to use
This commit is contained in:
parent
ea878975be
commit
47786ae792
3 changed files with 58 additions and 10 deletions
|
|
@ -1,4 +1,6 @@
|
|||
import { compareStrings } from "../lib/compare/primitives.js";
|
||||
import { fixer } from "../lib/util/fixpoint.js";
|
||||
import { MutableRBTree } from "../lib/util/rbtree_wrapper.js";
|
||||
|
||||
const booleanLattice = {
|
||||
isMaximal: (value) => value,
|
||||
|
|
@ -7,7 +9,7 @@ const booleanLattice = {
|
|||
};
|
||||
|
||||
const nullable = grammar => nonterminal => request => {
|
||||
console.log(nonterminal);
|
||||
console.log(nonterminal);
|
||||
const f = nt => {
|
||||
return {
|
||||
Epsilon: () => true,
|
||||
|
|
@ -15,7 +17,7 @@ const nullable = grammar => nonterminal => request => {
|
|||
NT: () => request(nt.nt),
|
||||
Seq: () => f(nt.l) && f(nt.r),
|
||||
Alt: () => f(nt.l) || f(nt.r),
|
||||
}[nt.kind]();
|
||||
}[nt.kind]();
|
||||
}
|
||||
return f(grammar[nonterminal]);
|
||||
}
|
||||
|
|
@ -65,8 +67,10 @@ const exampleGrammar = {
|
|||
// B is nullable because B → A C, and both A and C are nullable.
|
||||
// S is nullable because S → A B C, and A, B, and C are all nullable.
|
||||
|
||||
|
||||
const isNullable = fixer(nullable(exampleGrammar), booleanLattice);
|
||||
const isNullable = fixer(
|
||||
nullable(exampleGrammar), // eqs
|
||||
() => MutableRBTree.new((a,b) => compareStrings(a)(b)), // dict to use
|
||||
booleanLattice);
|
||||
|
||||
console.log(isNullable("S"));
|
||||
console.log(isNullable("A"));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue