From 626e90d54c7c6493601ba5a7a14961ecc7f57fc8 Mon Sep 17 00:00:00 2001 From: David Ashby Date: Sun, 14 Feb 2021 14:30:15 -0500 Subject: [PATCH] parser location doesn't need to be in the context, does it? --- eval.go | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/eval.go b/eval.go index 4dc5f75..af03d4c 100644 --- a/eval.go +++ b/eval.go @@ -11,7 +11,6 @@ type Context struct { Dictionary Dictionary Stack *Stack RStack *Stack - I int // current parser location } // Eval evaulates a given line, recursively descending into given words as needed @@ -22,30 +21,30 @@ func (c *Context) Eval(line string) error { var comment bool immediate := true - for c.I = 0; c.I < len(line); c.I = c.I + 1 { - switch line[c.I] { + for i := 0; i < len(line); i = i + 1 { + switch line[i] { case '(', ')': // comments if len(word) == 0 { - if line[c.I] == '(' { + if line[i] == '(' { comment = true continue } comment = false continue } else { - word = append(word, line[c.I]) + word = append(word, line[i]) } case ':', ';': // COMPILE/IMMEDIATE mode swapping if len(word) == 0 { - if line[c.I] == ':' { + if line[i] == ':' { immediate = false - } else if line[c.I-1] == ' ' && line[c.I] == ';' { + } else if line[i-1] == ' ' && line[i] == ';' { c.Dictionary.AddWord(words[0], nil, words[1:]) word = []byte{} immediate = true } } else { - word = append(word, line[c.I]) + word = append(word, line[i]) } case ' ': if !immediate { // continue building our subroutine if we're not in immediate mode... @@ -82,12 +81,12 @@ func (c *Context) Eval(line string) error { word = []byte{} } else if len(w.Source) != 0 { // user-defined word; let's descend... - c.RStack.Push(c.I) + c.RStack.Push(i) err := c.Eval(strings.Join(w.Source, " ") + " ") if err != nil { return err } - c.I, err = c.RStack.Pop() + i, err = c.RStack.Pop() if err != nil { return fmt.Errorf("error while popping from return stack: %v", err) } @@ -95,7 +94,7 @@ func (c *Context) Eval(line string) error { } default: if !comment { - word = append(word, line[c.I]) + word = append(word, line[i]) } } }