2022-05-23 09:26:34 -05:00
|
|
|
package ast
|
|
|
|
|
|
|
|
import "monkey/token"
|
|
|
|
|
|
|
|
type Node interface {
|
2022-05-23 12:35:55 -05:00
|
|
|
TokenLiteral() string
|
2022-05-23 09:26:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
type Statement interface {
|
|
|
|
Node
|
|
|
|
statement_node()
|
|
|
|
}
|
|
|
|
|
|
|
|
type Expression interface {
|
|
|
|
Node
|
|
|
|
expression_node()
|
|
|
|
}
|
|
|
|
|
|
|
|
type Program struct {
|
|
|
|
Statements []Statement
|
|
|
|
}
|
|
|
|
|
|
|
|
type Identifier struct {
|
|
|
|
Token token.Token // the token.IDENT token
|
|
|
|
Value string
|
|
|
|
}
|
|
|
|
|
|
|
|
type LetStatement struct {
|
|
|
|
Token token.Token // the token.LET token
|
|
|
|
Name *Identifier
|
|
|
|
Value Expression
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ls *LetStatement) statement_node() {}
|
|
|
|
|
|
|
|
func (ls *LetStatement) TokenLiteral() string {
|
|
|
|
return ls.Token.Literal
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *Identifier) expression_node() {}
|
|
|
|
|
|
|
|
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 ""
|
|
|
|
}
|
|
|
|
}
|