feat: expression
This commit is contained in:
@@ -20,6 +20,10 @@ type Atom struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
func (Abstraction) IsExpression() {}
|
||||
func (Application) IsExpression() {}
|
||||
func (Atom) IsExpression() {}
|
||||
|
||||
/** ------------------------------------------------------------------------- */
|
||||
|
||||
func NewAbstraction(parameter []string, body Expression) *Abstraction {
|
||||
@@ -33,9 +37,3 @@ func NewApplication(abstraction Expression, arguments []Expression) *Application
|
||||
func NewAtom(name string) *Atom {
|
||||
return &Atom{Name: name}
|
||||
}
|
||||
|
||||
/** ------------------------------------------------------------------------- */
|
||||
|
||||
func (a Abstraction) IsExpression() {}
|
||||
func (a Application) IsExpression() {}
|
||||
func (v Atom) IsExpression() {}
|
||||
5
pkg/saccharine/ast/program.go
Normal file
5
pkg/saccharine/ast/program.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package ast
|
||||
|
||||
type Program struct {
|
||||
Statements []Statement
|
||||
}
|
||||
28
pkg/saccharine/ast/statement.go
Normal file
28
pkg/saccharine/ast/statement.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package ast
|
||||
|
||||
type Statement interface {
|
||||
IsStatement()
|
||||
}
|
||||
|
||||
/** ------------------------------------------------------------------------- */
|
||||
|
||||
type LetStatement struct {
|
||||
Variable string
|
||||
Value Expression
|
||||
}
|
||||
|
||||
type MethodStatement struct {
|
||||
Name string
|
||||
Parameters []string
|
||||
Body Expression
|
||||
}
|
||||
|
||||
type DeclareStatement struct {
|
||||
Value Expression
|
||||
}
|
||||
|
||||
func (LetStatement) IsStatement() {}
|
||||
func (MethodStatement) IsStatement() {}
|
||||
func (DeclareStatement) IsStatement() {}
|
||||
|
||||
/** ------------------------------------------------------------------------- */
|
||||
@@ -69,7 +69,7 @@ func getToken(i *iterator.Iterator[rune]) (*token.Token, error) {
|
||||
return token.NewAtom(string(atom), index), nil
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("unknown character '%v'", letter)
|
||||
return nil, fmt.Errorf("unknown character '%v'", string(letter))
|
||||
}
|
||||
|
||||
// Parses a list of runes into tokens. All error encountered are returned, as well.
|
||||
|
||||
Reference in New Issue
Block a user