Introduced the evaluator (and integrated it with the REPL)
It supports integer and boolean literals, prefix expressions and infix expressions with integer operands. Signed-off-by: jmug <u.g.a.mariano@gmail.com>
This commit is contained in:
parent
acc6707740
commit
cf8b0033c9
4 changed files with 265 additions and 2 deletions
47
pkg/object/object.go
Normal file
47
pkg/object/object.go
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
package object
|
||||
|
||||
import "fmt"
|
||||
|
||||
type ObjectType string
|
||||
|
||||
const (
|
||||
INTEGER_OBJ = "INTEGER"
|
||||
BOOLEAN_OBJ = "BOOLEAN"
|
||||
NULL_OBJ = "NULL"
|
||||
)
|
||||
|
||||
type Object interface {
|
||||
Type() ObjectType
|
||||
Inspect() string
|
||||
}
|
||||
|
||||
type Integer struct {
|
||||
Value int64
|
||||
}
|
||||
|
||||
func (i *Integer) Type() ObjectType {
|
||||
return INTEGER_OBJ
|
||||
}
|
||||
func (i *Integer) Inspect() string {
|
||||
return fmt.Sprintf("%d", i.Value)
|
||||
}
|
||||
|
||||
type Boolean struct {
|
||||
Value bool
|
||||
}
|
||||
|
||||
func (b *Boolean) Type() ObjectType {
|
||||
return BOOLEAN_OBJ
|
||||
}
|
||||
func (b *Boolean) Inspect() string {
|
||||
return fmt.Sprintf("%t", b.Value)
|
||||
}
|
||||
|
||||
type Null struct{}
|
||||
|
||||
func (n *Null) Type() ObjectType {
|
||||
return NULL_OBJ
|
||||
}
|
||||
func (n *Null) Inspect() string {
|
||||
return "null"
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue