From 2019a495893f138f70e189483f36b219eabe20e2 Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Mon, 10 Nov 2025 00:06:09 +0100 Subject: feat(calc): supports unary minus --- README.md | 2 +- example/input.txt | 2 +- src/elixir_math_parser.yrl | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 65f2454..ea7d98c 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,4 @@ A math script parser in Elixir. -Using leex, yecc and ratio. +Using leex, yecc and a modified version of Ratio from hexpm. diff --git a/example/input.txt b/example/input.txt index 8cb02c5..32146f2 100644 --- a/example/input.txt +++ b/example/input.txt @@ -6,4 +6,4 @@ y = 2! z = y/2 10 + 4(z / y)(x / 4) -x^(0-y) +x^(-y) diff --git a/src/elixir_math_parser.yrl b/src/elixir_math_parser.yrl index 006c768..f8de916 100644 --- a/src/elixir_math_parser.yrl +++ b/src/elixir_math_parser.yrl @@ -50,6 +50,7 @@ expr -> exprs '/' exprs : {div_op, '$1', '$3'}. expr -> expr '!' : {factor_op, '$1'}. expr -> exprs '^' exprs : {exp_op, '$1', '$3'}. expr -> '(' exprs ')' : '$2'. +expr -> '-' exprs : {sub_op, {int, 0, 0}, '$2'}. Erlang code. -- cgit v1.2.3