mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-20 10:19:32 -06:00
Started working on a JavaScript translator.
This commit is contained in:
@@ -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 ----------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
Reference in New Issue
Block a user