feat: expression
This commit is contained in:
9
Makefile
9
Makefile
@@ -4,8 +4,11 @@ it:
|
|||||||
@ go build -o ${BINARY_NAME} ./cmd/lambda
|
@ go build -o ${BINARY_NAME} ./cmd/lambda
|
||||||
@ chmod +x ${BINARY_NAME}
|
@ chmod +x ${BINARY_NAME}
|
||||||
|
|
||||||
ex: it
|
simple: it
|
||||||
@ ./lambda.exe - < ./samples/simple.txt
|
@ ./lambda.exe - < ./samples/simple.txt
|
||||||
|
|
||||||
v: it
|
thunk: it
|
||||||
@ ./lambda.exe -v - < ./samples/simple.txt
|
@ ./lambda.exe - < ./samples/thunk.txt
|
||||||
|
|
||||||
|
saccharine: it
|
||||||
|
@ ./lambda.exe - < ./samples/saccharine.txt
|
||||||
@@ -20,6 +20,10 @@ type Atom struct {
|
|||||||
Name string
|
Name string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (Abstraction) IsExpression() {}
|
||||||
|
func (Application) IsExpression() {}
|
||||||
|
func (Atom) IsExpression() {}
|
||||||
|
|
||||||
/** ------------------------------------------------------------------------- */
|
/** ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
func NewAbstraction(parameter []string, body Expression) *Abstraction {
|
func NewAbstraction(parameter []string, body Expression) *Abstraction {
|
||||||
@@ -33,9 +37,3 @@ func NewApplication(abstraction Expression, arguments []Expression) *Application
|
|||||||
func NewAtom(name string) *Atom {
|
func NewAtom(name string) *Atom {
|
||||||
return &Atom{Name: name}
|
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 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.
|
// Parses a list of runes into tokens. All error encountered are returned, as well.
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
0 := \f x.x
|
0 := \f x.x
|
||||||
inc n := \f x.f (n f x)
|
(inc n) := \f x.(f (n f x))
|
||||||
add n m := m inc n
|
(add n m) := (m inc n)
|
||||||
mult n m := m (n f)
|
(mult n m) := (m (n f))
|
||||||
exp m n := m n
|
(exp m n) := (m n)
|
||||||
|
|
||||||
# This is the final output.
|
# This is the final output.
|
||||||
5 := (inc (inc (inc (inc (inc 0)))))
|
5 := (inc (inc (inc (inc (inc 0)))))
|
||||||
exp 5 5
|
(exp 5 5)
|
||||||
|
|||||||
1
samples/thunk.txt
Normal file
1
samples/thunk.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
(\.VALUE anything)
|
||||||
Reference in New Issue
Block a user