diff options
| author | Bobby <[email protected]> | 2023-11-02 21:29:15 -0400 |
|---|---|---|
| committer | Bobby <[email protected]> | 2023-11-02 21:29:15 -0400 |
| commit | 195c72b225c6f171011dfdde550f63cb409b7249 (patch) | |
| tree | b65218ec452f810b3d8cc0e017717613243a8e9e /ast | |
| parent | e2049d8b44ac97d3a47f8de8ad89f473214938d1 (diff) | |
| download | mana-195c72b225c6f171011dfdde550f63cb409b7249.tar.xz mana-195c72b225c6f171011dfdde550f63cb409b7249.zip | |
base:ast
Diffstat (limited to 'ast')
| -rw-r--r-- | ast/ast.go | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/ast/ast.go b/ast/ast.go new file mode 100644 index 0000000..7b75d35 --- /dev/null +++ b/ast/ast.go @@ -0,0 +1,54 @@ +package ast + +import "mana/tokens" + +type Node interface { + TokenLiteral() string +} + +type Statement interface { + Node + statementNode() +} + +type Expression interface { + Node + expressionNode() +} + +type Program struct { + Statements []Statement +} + +// TokenLiteral returns the literal value of the token associated with this +// node. This is used only for debugging and testing. + +func (p *Program) TokenLiteral() string { + if len(p.Statements) > 0 { + return p.Statements[0].TokenLiteral() + } + return "" +} + +// LetStatement represents a let statement. +type LetStatement struct { + Token tokens.Token // the token.LET token + Name *Identifier + Value Expression +} + +func (ls *LetStatement) statementNode() {} +func (ls *LetStatement) TokenLiteral() string { + return ls.Token.Literal +} + +// Identifier represents an identifier. +type Identifier struct { + Token tokens.Token // the token.IDENT token + Value string +} + +func (i *Identifier) expressionNode() {} +func (i *Identifier) TokenLiteral() string { + return i.Token.Literal +} |
