mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-11 13:59:31 -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 ----------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
16
lib/javascript/translator.html
Normal file
16
lib/javascript/translator.html
Normal 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>
|
||||
Reference in New Issue
Block a user