diff --git a/README.md b/README.md index e2ceb80..e4b68fb 100644 --- a/README.md +++ b/README.md @@ -170,11 +170,11 @@ Done: - [x] Document parenthesis syntax - [x] Specify number of samples as a command line option - [x] Figure out how to make models executable, by adding a #!/bin/bash-style command at the top? +- [x] Make -n flag work +- [x] Add flag to repeat input lines (useful when reading from files) To (possibly) do: -- [ ] Add flag to repeat input lines (useful when reading from files) -- [ ] Make -n flag work - [ ] Add functions. Now easier to do with an explicit representation of the stakc - [ ] Think about how to draw a histogram from samples - [ ] Dump samples to file diff --git a/fermi.go b/fermi.go index 93a4f3b..c58401b 100644 --- a/fermi.go +++ b/fermi.go @@ -356,10 +356,13 @@ func parseWordsIntoOpAndDist(words []string, vars map[string]Dist) (string, Dist // We want this as a function (rather than just be in main) // to be able to have parenthesis/recusion, possibly functions -func runRepl(stack Stack, reader *bufio.Reader) Stack { +func runRepl(stack Stack, reader *bufio.Reader, echo_flag *bool) Stack { replForLoop: for { new_line, _ := reader.ReadString('\n') + if *echo_flag { + fmt.Printf(new_line) + } new_line_before_comments, _, _ := strings.Cut(new_line, "#") new_line_trimmed := strings.TrimSpace(new_line_before_comments) words := strings.Split(new_line_trimmed, " ") @@ -369,7 +372,7 @@ replForLoop: continue replForLoop /* Parenthesis */ case len(words) == 2 && (words[0] == "*" || words[0] == "+" || words[0] == "-" || words[0] == "/") && words[1] == "(": - new_stack := runRepl(Stack{old_dist: INIT_DIST, vars: stack.vars}, reader) + new_stack := runRepl(Stack{old_dist: INIT_DIST, vars: stack.vars}, reader, echo_flag) combined_dist, err := operateDists(stack.old_dist, new_stack.old_dist, words[0]) if err == nil { stack.old_dist = combined_dist @@ -412,6 +415,7 @@ replForLoop: func main() { num_samples_flag := flag.Int("n", N_SAMPLES, "Specifies the number of samples to draw when using samples") filename := flag.String("f", "", "Specifies a file with a model to run") + echo_flag := flag.Bool("echo", false, "Specifies whether inputs should be echoed back. Useful if reading from a file.") flag.Parse() N_SAMPLES = *num_samples_flag @@ -428,6 +432,6 @@ func main() { reader = bufio.NewReader(os.Stdin) } stack := Stack{old_dist: INIT_DIST, vars: make(map[string]Dist)} - runRepl(stack, reader) + runRepl(stack, reader, echo_flag) }