mirror of
https://github.com/jamiebuilds/the-super-tiny-compiler.git
synced 2024-10-27 20:34:08 +00:00
Add debug printer
This commit is contained in:
parent
b14161b025
commit
81b5f5d8c0
@ -5,7 +5,6 @@ var List = require("bs-platform/lib/js/list.js");
|
||||
var Block = require("bs-platform/lib/js/block.js");
|
||||
var $$String = require("bs-platform/lib/js/string.js");
|
||||
var Caml_string = require("bs-platform/lib/js/caml_string.js");
|
||||
var Js_primitive = require("bs-platform/lib/js/js_primitive.js");
|
||||
|
||||
function explode(s) {
|
||||
var _i = s.length - 1 | 0;
|
||||
@ -269,7 +268,30 @@ function tokenizer(input) {
|
||||
};
|
||||
}
|
||||
|
||||
console.log(Js_primitive.undefined_to_opt(JSON.stringify(tokenizer("(add 2 (subtract 4 2))"))));
|
||||
function printToken(token) {
|
||||
if (typeof token === "number") {
|
||||
if (token) {
|
||||
return "CloseParen";
|
||||
} else {
|
||||
return "OpenParen";
|
||||
}
|
||||
} else {
|
||||
switch (token.tag | 0) {
|
||||
case 0 :
|
||||
return "Number " + token[0];
|
||||
case 1 :
|
||||
return "String " + token[0];
|
||||
case 2 :
|
||||
return "Name " + token[0];
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List.iter((function (k) {
|
||||
console.log(printToken(k));
|
||||
return /* () */0;
|
||||
}), tokenizer("(add 2 (subtract 4 2))"));
|
||||
|
||||
var machine = /* record */[
|
||||
/* current : None */0,
|
||||
@ -279,4 +301,5 @@ var machine = /* record */[
|
||||
exports.machine = machine;
|
||||
exports.explode = explode;
|
||||
exports.tokenizer = tokenizer;
|
||||
exports.printToken = printToken;
|
||||
/* Not a pure module */
|
||||
|
@ -56,4 +56,13 @@ let tokenizer input => {
|
||||
tok (explode input) machine.current machine.parsed
|
||||
};
|
||||
|
||||
Js.log @@ Js.Json.stringifyAny (tokenizer "(add 2 (subtract 4 2))");
|
||||
let printToken token =>
|
||||
switch token {
|
||||
| OpenParen => "OpenParen"
|
||||
| CloseParen => "CloseParen"
|
||||
| Number s => "Number " ^ s
|
||||
| String s => "String " ^ s
|
||||
| Name s => "Name " ^ s
|
||||
};
|
||||
|
||||
List.iter (fun k => Js.log (printToken k)) (tokenizer "(add 2 (subtract 4 2))");
|
Loading…
Reference in New Issue
Block a user