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 ----------------------------- */
/* ------------------------------------------------------------------------- */

View File

@@ -0,0 +1,16 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript" src="gflib.js"></script>
<script type="text/javascript" src="grammar.js"></script>
<title>Web-based GF Translator</title>
</head>
<body>
<form>
<input type="text" name="inputText" />
<input type="button" value="Translate" onclick="alert(Literals.translate(this.form.inputText.value).length)" />
</form>
</body>
</html>