refactored ast tables, added eval method
This commit is contained in:
parent
cf3255f015
commit
78973ac067
4 changed files with 100 additions and 29 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue