monna/ast/ast.go
tijani cf651aa1b8 ast and parser
git-svn-id: https://svn.tlawal.org/svn/monkey@7 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
2022-05-22 06:51:19 +00:00

51 lines
805 B
Go

package ast
import "monkey/token"
type Node interface {
TokenLiteral() string
}
type Statement interface {
Node
statementNode()
}
type Expression interface {
Node
expressionNode()
}
type Identifier struct {
Token token.Token // the token.IDENT token
Value string
}
type Program struct {
Statements []Statement
}
type LetStatement struct {
Token token.Token // the token.LET token
Name *Identifier
Value Expression
}
func (ls *LetStatement) stamementNode() {}
func (ls *LetStatement) TokenLiteral() string {
return ls.Token.Literal
}
func (i *Identifier) expressionNode() {}
func (i *Identifier) TokenLiteral() string {
return i.Token.Literal
}
func (p *Program) TokenLiteral() string {
if len(p.Statements) > 0 {
return p.Statements[0].TokenLiteral()
} else {
return ""
}
}