Skip to content

Commit

Permalink
wip semantic scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
gravataLonga committed Jul 18, 2022
1 parent 54a77d9 commit 119353e
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions semantic/semantic.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,20 @@ import (
// using visitor pattern
type Semantic struct {
scopeStack Stack
globalVariables []string
globalVariables Scope
localVariables map[ast.Node]int
errors []string
}

func New() *Semantic {
return &Semantic{
localVariables: make(map[ast.Node]int),
s := &Semantic{
scopeStack: make(Stack, 1, 8),
localVariables: make(map[ast.Node]int),
globalVariables: Scope{},
}

s.scopeStack[0] = &s.globalVariables
return s
}

func (s *Semantic) Errors() []string {
Expand Down Expand Up @@ -45,7 +50,7 @@ func (s *Semantic) exitScope() {
// declare will keep track of declare variables
func (s *Semantic) declare(name string) {
if s.scopeStack.IsEmpty() {
s.globalVariables = append(s.globalVariables, name)
s.globalVariables[name] = true
return
}

Expand Down

0 comments on commit 119353e

Please sign in to comment.