Permalink
Browse files

finished runtime

  • Loading branch information...
1 parent b3922a9 commit e7e1da303d343d1799c9141dc54d201492761c00 @peterolson committed Mar 2, 2012
Showing with 553 additions and 367 deletions.
  1. +68 −54 Tester.html
  2. +164 −106 compiler.js
  3. +1 −1 error.js
  4. +19 −0 lib.js
  5. +57 −23 parser.js
  6. +243 −182 runtime.js
  7. +1 −1 tokenizer.js
View
@@ -32,21 +32,30 @@
</head>
<body>
<pre id="input" contenteditable="true">
-a: b: c: d: 5
-
-f:: (){
+a: {
+ name: 'john'
+ age: 12
+ occupation: 'programmer'
+ getDescription:: (){
+ name & " is a " & age & " year old person who is a " & occupation
+ }
}
+a.name: 'peter'
+alert| a.name
+
-;m!: 4
</pre>
<br />
<button id="tokenizer">Tokenize</button>
<button id="parser">Parse</button>
<button id="compiler">Compile</button><br />
+ <button id="runner">Run</button><br />
Output:<br />
<pre id="output">
</pre>
+<iframe id="runframe" style="visibility:hidden;"></iframe>
</body>
+<script src="lib.js"></script>
<script src="error.js"></script>
<script src="tokenizer.js"></script>
<script src="parser.js"></script>
@@ -64,63 +73,68 @@
ce.find("br").replaceWith("\n");
return ce.text();
- };
-
- $(function () {
+ };
- var getTokens = function () {
- var t, text = $("#input").getPreText(),
+ var getTokens = function () {
+ var t, text = $("#input").getPreText(),
error;
- try {
- t = tokenize(text);
- }
- catch (e) {
- t = e;
- error = true;
- }
- text = text.split("");
- for (var i = 0; i < t.length; i++) {
- var token = t[i];
- text[token.from] = "<span class=\"" + token.type + "\">" + text[token.from];
- text[token.to - 1] += "</span>";
- }
- $("#input").html(text.join(""));
- return t;
- };
+ try {
+ t = tokenize(text);
+ }
+ catch (e) {
+ t = e;
+ error = true;
+ }
+ text = text.split("");
+ for (var i = 0; i < t.length; i++) {
+ var token = t[i];
+ text[token.from] = "<span class=\"" + token.type + "\">" + text[token.from];
+ text[token.to - 1] += "</span>";
+ }
+ $("#input").html(text.join(""));
+ return t;
+ };
+
+ var getStatements = function () {
+ var tokens = getTokens(), statements;
+ try {
+ statements = parse(tokens);
+ }
+ catch (e) {
+ statements = e;
+ var text = text = $("#input").getPreText().split("");
+ for (var i = 0; i < e.length; i++) {
+ var token = e[i];
+ text[token.from] = "<span class=\"" + token.type + "\">" + text[token.from];
+ text[token.to - 1] += "</span>";
+ }
+ $("#input").html(text.join(""));
+ }
+ return statements;
+ };
+
+ $(function () {
- var getStatements = function () {
- var tokens = getTokens(), statements;
- //try {
- statements = parse(tokens);
-// }
-// catch (e) {
-// statements = e;
-// var text = text = $("#input").getPreText().split("");
-// for (var i = 0; i < e.length; i++) {
-// var token = e[i];
-// text[token.from] = "<span class=\"" + token.type + "\">" + text[token.from];
-// text[token.to - 1] += "</span>";
-// }
-// $("#input").html(text.join(""));
-// }
- return statements;
- };
+ $("#tokenizer").click(function () {
+ var t = getTokens();
+ $("#output").html(JSON.stringify(t, ["type", "value", "from", "to", "line", "message"], 4));
+ });
- $("#tokenizer").click(function () {
- var t = getTokens();
- $("#output").html(JSON.stringify(t, ["type", "value", "from", "to", "line", "message"], 4));
- });
+ $("#parser").click(function () {
+ var statements = getStatements();
+ $("#output").html(JSON.stringify(statements, ["id", "type", "value", "arguments", "arity", "first", "second", "args", "from", "to", "message"], 4));
+ });
- $("#parser").click(function () {
- var statements = getStatements();
- $("#output").html(JSON.stringify(statements, ["id", "type", "value", "arguments", "arity", "first", "second", "args", "from", "to", "message"], 4));
- });
+ $("#compiler").click(function () {
+ $("#output").html(compile(getStatements(), "javascript"));
+ });
- $("#compiler").click(function () {
- $("#output").html(compile(getStatements(), "javascript"));
- });
+ $("#runner").click(function () {
+ $("#runframe").attr("src", "");
+ $("#runframe").attr("src", "Runner.htm");
+ });
- getTokens();
+ getTokens();
});
</script>
</html>
Oops, something went wrong.

0 comments on commit e7e1da3

Please sign in to comment.