Skip to content

Commit

Permalink
Adds let statements to AST (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
abasnfarah authored Feb 1, 2024
1 parent d32f6b5 commit 4dd96de
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions go/ast/ast.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package ast

import "github.com/abasnfarah/interpreter/go/token"

type Node interface {
tokenLiteral() string
}
Expand All @@ -18,6 +20,29 @@ type Program struct {
Statements []Statement
}

type Identifier struct {
Token token.Token
Value string
}

func (i *Identifier) expressionNode() {}

func (i *Identifier) tokenLiteral() string {
return i.Token.Literal
}

type LetStatement struct {
Token token.Token
Name *Identifier
Value Expression
}

func (l *LetStatement) statementNode() {}

func (l *LetStatement) tokenLiteral() string {
return l.Token.Literal
}

func (p *Program) tokenLiteral() string {
if len(p.Statements) > 0 {
return p.Statements[0].tokenLiteral()
Expand Down

0 comments on commit 4dd96de

Please sign in to comment.