// Package saccharine defines the AST for the Saccharine language, a sugared // lambda calculus with let bindings and multi-statement clauses. package saccharine // An Expression is a node in the Saccharine abstract syntax tree. // It is a sealed interface; only types in this package may implement it. type Expression interface { expression() } // An Abstraction is a lambda expression with zero or more parameters. // A zero-parameter abstraction is treated as a thunk. type Abstraction struct { Parameters []string Body Expression } // An Application applies an expression to zero or more arguments. type Application struct { Abstraction Expression Arguments []Expression } // An Atom is a named variable. type Atom struct { Name string } // A Clause is a sequence of statements followed by a return expression. type Clause struct { Statements []Statement Returns Expression } func (Abstraction) expression() {} func (Application) expression() {} func (Atom) expression() {} func (Clause) expression() {} // A Statement is a declaration within a Clause. // It is a sealed interface; only types in this package may implement it. type Statement interface { statement() } // A LetStatement binds a name (with optional parameters) to an expression. type LetStatement struct { Name string Parameters []string Body Expression } // A DeclareStatement evaluates an expression for its side effects within a // clause. type DeclareStatement struct { Value Expression } func (LetStatement) statement() {} func (DeclareStatement) statement() {}