commit dfb9f3cc2543ffcda5e661db5be91c114e4d945a
parent 09583a312c149732a21b4df486d1b2efc92252cd
Author: NunoSempere <nuno.semperelh@protonmail.com>
Date: Sun, 9 Jun 2024 12:58:16 +0200
add some notion of what a more powerful parser could look like
Diffstat:
| M | README.md | | | 3 | ++- |
| A | f2.go | | | 60 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 files changed, 62 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
@@ -122,5 +122,6 @@ Some possible syntax for a more expressive stack-based DSL
10 to 100
=: y # content of the stack at this point saved into y
-x - 10B * y # if interpreting x and y as list of samples, you could do - and + operations as well
+x # put x on the stack
+- y # substract y from the content of the stack. Requires interpreting x and y as list of samples
```
diff --git a/f2.go b/f2.go
@@ -0,0 +1,60 @@
+package main
+
+import (
+ "bufio"
+ "fmt"
+ // "math"
+ "os"
+ // "strconv"
+ "strings"
+)
+
+// Actually, I should look up how do do a) enums in go, b) union types
+type Lognormal struct {
+ low float64
+ high float64
+}
+
+type Dist struct {
+ Type string
+ Lognormal Lognormal
+ Samples []float64
+}
+
+func parseLine(line string) (string, Dist, error) {
+
+ words := strings.Split(strings.TrimSpace(line), " ")
+
+ switch {
+ case len(words) == 2 && words[0] == "*":
+ fmt.Printf("Hello world")
+ }
+}
+
+func joinDists(old_dist Dist, new_dist Dist, op string) (Dist, err) {
+ return old_dist, nil
+}
+
+func main() {
+ reader := bufio.NewReader(os.Stdin)
+ old_dist := Dist{Type: "Lognormal", Lognormal: Lognormal{low: 1, high: 1}, Samples: nil} // Could also just be a scalar
+ fmt.Printf("Hello world")
+
+EventForLoop:
+ for {
+ input, _ := reader.ReadString('\n')
+ if strings.TrimSpace(input) == "" {
+ continue EventForLoop
+ }
+
+ op, new_dist, err := parseLine(input)
+ if err != nil {
+
+ }
+ joint_dist, err := joinDists(old_dist, new_dist, op)
+ if err != nil {
+
+ }
+ old_dist = joint_dist
+ }
+}