diff --git a/DNCL3.js b/DNCL3.js index 8c6cbe8..cabee0a 100644 --- a/DNCL3.js +++ b/DNCL3.js @@ -37,9 +37,9 @@ class Break { export class DNCL3 { constructor(s, callbackoutput) { this.s = s.replaceAll("\r", ""); - this.p = 0; this.vars = {}; this.callbackoutput = callbackoutput; + //this.parseTokens(); this.parse(); } output(s) { @@ -448,17 +448,23 @@ export class DNCL3 { } if (token.type == "print") { const res = []; - for (;;) { - res.push(this.getExpression()); - const op = this.getToken(); - if (op.type == "eol" || op.type == "eof" || op.type == "else") { - this.backToken(op); - break; - } - if (op.operator != ",") { - this.backToken(op); - break; - //throw new Error("表示はコンマ区切りのみ対応しています"); + const chk = this.getToken(true); + if (chk.type == "eol" || chk.type == "eof") { + this.backToken(chk); + } else { + this.backToken(chk); + for (;;) { + res.push(this.getExpression()); + const op = this.getToken(); + if (op.type == "eol" || op.type == "eof") { + this.backToken(op); + break; + } + if (op.operator != ",") { + this.backToken(op); + break; + //throw new Error("表示はコンマ区切りのみ対応しています"); + } } } body.push({ @@ -787,11 +793,20 @@ export class DNCL3 { return true; } parse() { + this.p = 0; const body = []; while (this.parseCommand(body)); const ast = { "type": "Program", body }; this.ast = ast; } + parseTokens() { + this.p = 0; + for (;;) { + const c = this.getToken(true); + console.log(c); + if (c.type == "eof") break; + } + } getArrayIndex(ast) { const prop = this.calcExpression(ast); if (prop < 0 || typeof prop == "string" && parseInt(prop).toString() != prop) { diff --git a/dncl2js.html b/dncl2js.html index 41845fc..6a98dd2 100644 --- a/dncl2js.html +++ b/dncl2js.html @@ -115,7 +115,8 @@

DNCL3 → AST → like JavaScript → output

//const fn = "dowhile"; //const fn = "comment"; //const fn = "input"; -const fn = "test"; +//const fn = "test"; +const fn = "print"; const fn0 = location.hash.substring(1) || fn; const firstprog = await (await fetch("examples/" + fn0 + ".dncl")).text(); diff --git a/examples/print.dncl b/examples/print.dncl index 34fdfbc..6384a13 100644 --- a/examples/print.dncl +++ b/examples/print.dncl @@ -1,5 +1,6 @@ # 1. 値の表示 print print 15 #コメント +print print "a" + (3 + 5) + "b" print 10 // 3 + "kg" -print 1, "abc", 30 \ No newline at end of file +print 1, "abc", 30