refactored ast tables, added eval method

This commit is contained in:
Aidan 2020-06-20 20:59:52 -07:00
parent cf3255f015
commit 78973ac067
No known key found for this signature in database
GPG key ID: 327711E983899316
4 changed files with 100 additions and 29 deletions

View file

@ -19,21 +19,27 @@ package ast
type VarTable map[string]*Token
var (
GlobalVarTable *VarTable
)
func (VarTable vt) GetVar(arg string) *Token {
val, ok := vt[arg]
if !ok {
return nil
}
return val
}
// Library represents variables defined in inner scope
// It is assumed library is ordered from innermost scope to outermost scope
func GetVar(arg string, library []VarTable) *Token {
for scope, dict := range library {
val, ok := dict[arg]
if ok {
scope = scope // TEMP LINE
// TODO: maybe log which scope it was found in?
return val
var res *Token
res = nil
for i := 0; i < len(library); i += 1 {
res = library[i].GetVar(arg)
if res != nil {
// TODO: Log scope res was found in?
break
}
}
return nil
return res
}