Created
February 19, 2014 06:05
-
-
Save forestbelton/9086832 to your computer and use it in GitHub Desktop.
remove left recursion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var rm_lr = function(name, grammar) { | |
var p_with = grammar[name].filter(function(x) { return x[0] == name; }), | |
p_wo = grammar[name].filter(function(x) { return x[0] != name; }); | |
grammar[name] = p_wo.concat(p_wo.map(function(wo) { | |
return wo.concat([name + "'"]); | |
})); | |
grammar[name + "'"] = [['e']].concat(p_with.map(function(x) { | |
return x.slice(1).concat([name + "'"]); | |
})); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment