aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ast/ast.go54
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
+}