Skip to content

Commit

Permalink
fix print without params
Browse files Browse the repository at this point in the history
  • Loading branch information
taisukef committed Jan 5, 2025
1 parent e602fce commit 861ed6b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
39 changes: 27 additions & 12 deletions DNCL3.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion dncl2js.html
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ <h1>DNCL3 → AST → like JavaScript → output</h1>
//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();
Expand Down
3 changes: 2 additions & 1 deletion examples/print.dncl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# 1. 値の表示 print
print 15 #コメント
print
print "a" + (3 + 5) + "b"
print 10 // 3 + "kg"
print 1, "abc", 30
print 1, "abc", 30

0 comments on commit 861ed6b

Please sign in to comment.