Skip to content

Commit

Permalink
support multi-line comment
Browse files Browse the repository at this point in the history
  • Loading branch information
taisukef committed Jan 3, 2025
1 parent d32a76f commit 3412953
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
24 changes: 22 additions & 2 deletions DNCL3.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,11 @@ export class DNCL3 {
const STATE_WORD = 1;
const STATE_STRING = 2;
const STATE_COMMENT = 3;
const STATE_NUMBER = 4;
const STATE_OPERATOR = 5;
const STATE_COMMENT_SINGLE = 4;
const STATE_COMMENT_MULTI = 5;
const STATE_COMMENT_MULTI2 = 6;
const STATE_NUMBER = 7;
const STATE_OPERATOR = 8;
let state = STATE_FIRST;
const res = [];
const pos = this.p;
Expand Down Expand Up @@ -110,11 +113,28 @@ export class DNCL3 {
res.push(c);
}
} else if (state == STATE_COMMENT) {
if (c == "=") {
state = STATE_COMMENT_MULTI;
} else {
this.p--;
state = STATE_COMMENT_SINGLE;
}
} else if (state == STATE_COMMENT_SINGLE) {
if (c == "\n") {
return { pos, type: "eol" };
} else if (c === undefined) {
return { pos, type: "eof" };
}
} else if (state == STATE_COMMENT_MULTI) {
if (c == "=") {
state = STATE_COMMENT_MULTI2;
}
} else if (state == STATE_COMMENT_MULTI2) {
if (c == "#") {
return { pos, type: "eol" };
} else {
state = STATE_COMMENT_MULTI;
}
} else if (state == STATE_NUMBER) {
if (isNumber(c) || c == ".") {
res.push(c);
Expand Down
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ deno run -A DNCL3.example.js bmi
- ブラウザで動作するテスト環境 [dncl2js](https://code4fukui.github.io/DNCL3/dncl2js.html)

※ TODO: 下記は未実装です
- [二次元以上の配列](https://github.com/code4fukui/DNCL3/issues/2) / [配列のすべてを初期化](https://github.com/code4fukui/DNCL3/issues/3) / [input](https://github.com/code4fukui/DNCL3/issues/7) / [変数のスコープ](https://github.com/code4fukui/DNCL3/issues/13) / [複数行コメント](https://github.com/code4fukui/DNCL3/issues/14)
- [二次元以上の配列](https://github.com/code4fukui/DNCL3/issues/2) / [配列のすべてを初期化](https://github.com/code4fukui/DNCL3/issues/3) / [input](https://github.com/code4fukui/DNCL3/issues/7) / [変数のスコープ](https://github.com/code4fukui/DNCL3/issues/13)

## 1 変数と値

Expand Down Expand Up @@ -380,6 +380,15 @@ atai = 乱数() # 0以上1未満のランダムな小数をataiに代入する
```
- ※1行内において#以降の記述は処理の対象とならない

```
#=
複数行に渡る
コメントの記述方法
=#
```

- #= から =# までの記述は処理の対象とならない

## reference

- [共通テスト手順記述標準言語 (DNCL) の説明 独立行政法人大学入試センター 2022年1月](https://www.dnc.ac.jp/albums/abm.php?d=67&f=abm00000819.pdf&n=R4_%E5%85%B1%E9%80%9A%E3%83%86%E3%82%B9%E3%83%88%E6%89%8B%E9%A0%86%E8%A8%98%E8%BF%B0%E6%A8%99%E6%BA%96%E8%A8%80%E8%AA%9E%EF%BC%88DNCL%EF%BC%89%E3%81%AE%E8%AA%AC%E6%98%8E.pdf)
Expand Down
6 changes: 4 additions & 2 deletions dncl2js.html
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,11 @@ <h1>DNCL3 → AST → like JavaScript → output</h1>
//const fn = "geo3x3";
//const fn = "varja";
//const fn = "funcja";
const fn = "dowhile";
//const fn = "dowhile";
const fn = "comment";

const firstprog = await (await fetch("examples/" + fn + ".dncl")).text();
const fn0 = location.hash.substring(1) || fn;
const firstprog = await (await fetch("examples/" + fn0 + ".dncl")).text();

prog.setValue(firstprog);
onchange();
Expand Down
5 changes: 5 additions & 0 deletions examples/comment.dncl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
a = 10 #=
複数行に渡る
コメント
=#
print a

0 comments on commit 3412953

Please sign in to comment.