Started working on a JavaScript translator.

This commit is contained in:
bringert
2008-08-12 15:56:24 +00:00
parent b99256ca9a
commit 24e609189f
2 changed files with 40 additions and 0 deletions

View File

@@ -4,6 +4,30 @@ function GFGrammar(abstract, concretes) {
this.concretes = concretes;
}
/* Translates a string from any concrete syntax to all concrete syntaxes.
Uses the start category of the grammar.
*/
GFGrammar.prototype.translate = function (input) {
var outputs = new Array();
for (var c1 in this.concretes) {
var p = this.concretes[c1].parser;
if (p) {
var trees = p.parseString(input, this.abstract.startcat);
if (trees.length > 0) {
outputs[c1] = new Array();
for (var c2 in this.concretes) {
outputs[c1][c2] = new Array();
for (var i in trees) {
outputs[c1][c2][i] = this.concretes[c2].linearize(trees[i]);
}
}
}
}
}
return outputs;
}
/* ------------------------------------------------------------------------- */
/* ----------------------------- LINEARIZATION ----------------------------- */
/* ------------------------------------------------------------------------- */