compiler-in-go/pkg/ast/ast.go
jmug 0acd1d41e8 Add all the files from the interpreter repo
Signed-off-by: jmug <u.g.a.mariano@gmail.com>
2025-01-13 19:51:49 -08:00

39 lines
537 B
Go

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()
}