diff options
| author | Michael Tews <git@tews.dev> | 2024-06-19 06:07:54 +0200 |
|---|---|---|
| committer | Michael Tews <michael@tews.dev> | 2026-04-12 11:11:02 +0200 |
| commit | 88a76bb57b07cb15e546f787d4a63dad75106c10 (patch) | |
| tree | c669fede2b5e135b275b6667d0e8ec753a672ca1 /ast | |
| parent | ac4b6cd3d5a9ae58134a160671ae0730104ec62d (diff) | |
feat(lexer): added new tokens
added == and !=
Diffstat (limited to 'ast')
| -rw-r--r-- | ast/ast.go | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/ast/ast.go b/ast/ast.go new file mode 100644 index 0000000..033005f --- /dev/null +++ b/ast/ast.go @@ -0,0 +1,48 @@ +package ast + +import ( + "github.com/mewsen/interpreter/token" +) + +type Node interface { + TokenLiteral() 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() + } else { + return "" + } +} + +type LetStatement struct { + Token token.Token + Name *Identifier + Value Expression +} + +func (ls *LetStatement) statementNode() {} +func (ls *LetStatement) TokenLiteral() string { return ls.Token.Literal } + +type Identifier struct { + Token token.Token + Value string +} + +func (i *Identifier) expressionNode() {} +func (i *Identifier) TokenLiteral() string { return i.Token.Literal } |
