123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- package ast
- import "code.osinet.fr/fgm/waiig15/token"
- // Every node in the AST implements Node.
- type Node interface {
- // TokenLiteral returns the literal value of the token it's associated to.
- TokenLiteral() string
- }
- type Statement interface {
- // Expression extends Node.
- Node
- statementNode()
- }
- type Expression interface {
- // Expression extends Node.
- Node
- expressionNode()
- }
- type Program struct {
- Statements []Statement
- }
- func (p *Program) TokenLiteral() string {
- if len(p.Statements) > 0 {
- return p.Statements[0].TokenLiteral()
- } else {
- return ""
- }
- }
- type LetStatement struct {
- Token token.Token // the token.LET token. Why do we need it ?
- Name *Identifier
- Value Expression
- }
- func (ls *LetStatement) statementNode() {}
- func (ls *LetStatement) TokenLiteral() string {
- return ls.Token.Literal
- }
- type Identifier struct {
- Token token.Token // the token.IDENT token. Why do we need it ?
- Value string // The identifier string.
- }
- func (i *Identifier) expressionNode() {}
- func (i *Identifier) TokenLiteral() string {
- return i.Token.Literal
- }
|