summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-20 21:55:57 +0200
committerPaul Buetow <paul@buetow.org>2026-03-20 21:55:57 +0200
commit15b87ea17d96856d3ed9f2dbfbc80343b01b78df (patch)
treecc5b1fbbb722ddbab49450d308d6945d99f3c01c /internal
parent9a282b74a179517c009f855c14d3fa63ad805871 (diff)
cmd/perc/main.go: try RPN parsing before percentage calculation in command mode
- Bare expressions like '1 2 +' now work without 'calc' prefix - Assignment format 'name value =' requires 'calc' subcommand prefix
Diffstat (limited to 'internal')
-rw-r--r--internal/repl/repl.go10
1 files changed, 9 insertions, 1 deletions
diff --git a/internal/repl/repl.go b/internal/repl/repl.go
index 79a94f4..ed39755 100644
--- a/internal/repl/repl.go
+++ b/internal/repl/repl.go
@@ -51,7 +51,15 @@ func executor(input string) {
return
}
- // Run the calculation
+ // Try RPN parsing first (for bare RPN expressions like "3 4 +")
+ rpnResult, rpnErr := runRPN(input)
+ if rpnErr == nil {
+ // Valid RPN expression - print result
+ fmt.Println(rpnResult)
+ return
+ }
+
+ // Run the percentage calculation
result, err := calculator.Parse(input)
if err != nil {
fmt.Printf("Error: %v\n", err)