From 4bf5d97f08e9371c99b4d7fdff16e52c82a79530 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 21 Apr 2026 08:39:56 +0000 Subject: [PATCH 01/30] Initial plan From 3ccc55b51e9484e022ec5463794bbcc62d1d4298 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 21 Apr 2026 08:48:13 +0000 Subject: [PATCH 02/30] feat: add unary function parsing and tree rendering support Agent-Logs-Url: https://github.com/psaegert/expression-tree-gen/sessions/1b9ad718-258f-4142-ba5d-146b7d889d15 Co-authored-by: psaegert <36567814+psaegert@users.noreply.github.com> --- README.md | 12 +++++ canvas.js | 8 +-- index.html | 4 +- infixToPostfix.js | 130 +++++++++++++++++++++++++++++++++++++++++----- tree.js | 74 +++++++++++++++++--------- 5 files changed, 185 insertions(+), 43 deletions(-) diff --git a/README.md b/README.md index 56d4f59..eb66e8d 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,18 @@ With that in mind, and inspired on my lectures on the tree data structure I deci Visit this [website](https://lnogueir.github.io/expression-tree-gen/) to simulate an expression yourself. +Supported syntax includes: +- Binary operators: `+`, `-`, `*`, `/` +- Single-letter variables: `a`-`z` +- Unary functions: `sin`, `cos`, `tan`, `log`, `ln`, `sqrt`, `exp`, `abs` + +Examples: +- `a+b` +- `sin(a)` +- `sin(a)+cos(b)` +- `sin(cos(a))` +- `sin(a+b)*cos(c)` + ## Credits: * This [article](https://llimllib.github.io/pymag-trees/) which helped me a lot introducing me to Knuth's algorithm for the layout of the tree. diff --git a/canvas.js b/canvas.js index adebbfe..9f9cd42 100644 --- a/canvas.js +++ b/canvas.js @@ -5,10 +5,11 @@ const SAMPLE_EXPRESSIONS = [ '(a + b)*c - (x - y)/z', '(a * b) - c + z / x', + 'sin(a)+cos(b)', + 'sin(a+b)*cos(c)', 'x - y + (c / (a + b))', '(a / y) + b - (c * x)', - '(a - b) * (c + d) / z', - '(a * b) - (x / y)' + '(a - b) * (c + d) / z' ] var canvas = document.querySelector('canvas') var c = canvas.getContext('2d') @@ -61,10 +62,11 @@ function displayErrorMessage() {