-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[enhance] 中置演算子式評価時の演算子優先度評価の実装 #135
Conversation
Codecov Report
@@ Coverage Diff @@
## master #135 +/- ##
==========================================
+ Coverage 70.94% 72.11% +1.17%
==========================================
Files 15 16 +1
Lines 2024 2109 +85
Branches 301 304 +3
==========================================
+ Hits 1436 1521 +85
Misses 586 586
Partials 2 2
Continue to review full report at Codecov.
|
src/interpreter/infix-to-fncall.ts
Outdated
for (let i = 2; i < nodes.length; i++) { | ||
tree = insert(infos[i - 1], nodes[i], tree); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
オフセット計算でマイナスするよりは
for (let i = 1; i < infos.length; i++) {
tree = insert(infos[i], tree, nodes[i + 1]);
}
の方が分かりやすい気がした
特に意図がなければ、関数名は動詞から始まるほうが良さそう |
どの演算子がどういう優先度かっていうの暗記するの大変そうだなと思った |
優先度は相対的なものだから「AよりもBが優先される」程度のものでしかないよ |
優先度の振り方は大まかに |
他の言語でいつも計算は括弧で括ってたから意識したことなかった🥴 |
優先度の違う演算子が式に出てきたら、括弧で明示しないといけないことにするとか (実装は結構ややこしそうだけど...) |
単にタイプ数が増えるだけだと思うんだけど ルールとして括弧を強制するほどのものかなあ そのルールにするならやるけど |
方針を決めるならばアンケートとった方がいいかも |
優先度について知らない人が括弧が無い計算式を見たら意図が把握できなくなりそう まあ私がイレギュラーなだけかもしれないんで無視してもらってもOK |
🙏 |
What
中置演算子式 (Infix) の演算子の優先度評価を実装した
優先度を評価し、木を作ることでネストする関数呼び出しに書き換えることで実現
Why
中置演算子式導入時に未実装であった優先度評価を実装した
より直感的に AiScript のコーディングが可能になると考えられる
Additional info (optional)
この PR では優先度や関数への置き換えをインタプリタで行っているが、将来的には意味解析などの段階で行うようにしたい (#124)