Add all the files from the interpreter repo

Signed-off-by: jmug <u.g.a.mariano@gmail.com>
This commit is contained in:
Mariano Uvalle 2025-01-13 19:51:49 -08:00
parent 230fe61b12
commit 0acd1d41e8
34 changed files with 3784 additions and 0 deletions

39
pkg/ast/ast.go Normal file
View file

@ -0,0 +1,39 @@
package ast
import (
"bytes"
)
type Node interface {
TokenLiteral() string
String() string
}
type Statement interface {
Node
statementNode()
}
type Expression interface {
Node
expressionNode()
}
type Program struct {
Statements []Statement
}
func (p *Program) TokenLiteral() string {
if len(p.Statements) > 0 {
return p.Statements[0].TokenLiteral()
}
return ""
}
func (p *Program) String() string {
var out bytes.Buffer
for _, stmt := range p.Statements {
out.WriteString(stmt.String())
}
return out.String()
}