interpreter

package
v0.0.0-...-50a66e4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2017 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	INTEGER_TYPE     = "Int"
	FLOAT_TYPE       = "Float"
	STRING_TYPE      = "String"
	ATOM_TYPE        = "Atom"
	BOOLEAN_TYPE     = "Bool"
	ARRAY_TYPE       = "Array"
	DICTIONARY_TYPE  = "Dictionary"
	NIL_TYPE         = "Nil"
	FUNCTION_TYPE    = "Function"
	RETURN_TYPE      = "Return"
	BREAK_TYPE       = "Break"
	CONTINUE_TYPE    = "Continue"
	MODULE_TYPE      = "Module"
	PLACEHOLDER_TYPE = "Placeholder"
)

Data types.

Variables

View Source
var (
	NIL   = &NilType{}
	TRUE  = &BooleanType{Value: true}
	FALSE = &BooleanType{Value: false}
)

A NIL, TRUE or FALSE don't have any literal meaning. A TRUE is always the same instance.

Functions

This section is empty.

Types

type ArrayType

type ArrayType struct {
	Elements []DataType
}

ArrayType for arrays.

func (*ArrayType) Inspect

func (t *ArrayType) Inspect() string

func (*ArrayType) Type

func (t *ArrayType) Type() string

type AtomType

type AtomType struct {
	Value string
}

AtomType for atoms.

func (*AtomType) Inspect

func (t *AtomType) Inspect() string

func (*AtomType) Type

func (t *AtomType) Type() string

type BooleanType

type BooleanType struct {
	Value bool
}

BooleanType for boolean.

func (*BooleanType) Inspect

func (t *BooleanType) Inspect() string

func (*BooleanType) Type

func (t *BooleanType) Type() string

type BreakType

type BreakType struct{}

BreakType for break.

func (*BreakType) Inspect

func (t *BreakType) Inspect() string

func (*BreakType) Type

func (t *BreakType) Type() string

type ContinueType

type ContinueType struct{}

ContinueType for continue.

func (*ContinueType) Inspect

func (t *ContinueType) Inspect() string

func (*ContinueType) Type

func (t *ContinueType) Type() string

type DataType

type DataType interface {
	Type() string
	Inspect() string
}

DataType interface.

type DictionaryType

type DictionaryType struct {
	Pairs map[DataType]DataType
}

DictionaryType for dictionaries.

func (*DictionaryType) Inspect

func (t *DictionaryType) Inspect() string

func (*DictionaryType) Type

func (t *DictionaryType) Type() string

type FloatType

type FloatType struct {
	Value float64
}

FloatType for floating point numbers.

func (*FloatType) Inspect

func (t *FloatType) Inspect() string

func (*FloatType) Type

func (t *FloatType) Type() string

type FunctionType

type FunctionType struct {
	Parameters []*ast.FunctionParameter
	Body       *ast.BlockStatement
	ReturnType *ast.Identifier
	Variadic   bool
	Scope      *Scope
}

FunctionType for functions.

func (*FunctionType) Inspect

func (t *FunctionType) Inspect() string

func (*FunctionType) Type

func (t *FunctionType) Type() string

type IntegerType

type IntegerType struct {
	Value int64
}

IntegerType for integers.

func (*IntegerType) Inspect

func (t *IntegerType) Inspect() string

func (*IntegerType) Type

func (t *IntegerType) Type() string

type Interpreter

type Interpreter struct {
	// contains filtered or unexported fields
}

Interpreter represents the interpreter.

func New

func New() *Interpreter

New initializes an Interpreter.

func (*Interpreter) Interpret

func (i *Interpreter) Interpret(node ast.Node, scope *Scope) DataType

Interpret runs the interpreter.

type ModuleType

type ModuleType struct {
	Name *ast.Identifier
	Body *ast.BlockStatement
}

ModuleType for modules.

func (*ModuleType) Inspect

func (t *ModuleType) Inspect() string

func (*ModuleType) Type

func (t *ModuleType) Type() string

type NilType

type NilType struct{}

NilType for nil.

func (*NilType) Inspect

func (t *NilType) Inspect() string

func (*NilType) Type

func (t *NilType) Type() string

type PlaceholderType

type PlaceholderType struct{}

PlaceholderType for continue.

func (*PlaceholderType) Inspect

func (t *PlaceholderType) Inspect() string

func (*PlaceholderType) Type

func (t *PlaceholderType) Type() string

type ReturnType

type ReturnType struct {
	Value DataType
}

ReturnType for return.

func (*ReturnType) Inspect

func (t *ReturnType) Inspect() string

func (*ReturnType) Type

func (t *ReturnType) Type() string

type Scope

type Scope struct {
	// contains filtered or unexported fields
}

Scope represents the variable scope.

func NewScope

func NewScope() *Scope

NewScope initializes an empty scope.

func NewScopeFrom

func NewScopeFrom(parent *Scope) *Scope

NewScopeFrom initializes a scope by inheriting from a parent.

func (*Scope) Merge

func (s *Scope) Merge(scope *Scope)

Adds scope to the current scope.

func (*Scope) Read

func (s *Scope) Read(name string) (DataType, bool)

Read returns a variable from the scope.

func (*Scope) Update

func (s *Scope) Update(name string, value DataType)

Update a variable that already exists.

func (*Scope) Write

func (s *Scope) Write(name string, value DataType)

Write saves a variable to the scope.

type StringType

type StringType struct {
	Value string
}

StringType for strings.

func (*StringType) Inspect

func (t *StringType) Inspect() string

func (*StringType) Type

func (t *StringType) Type() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL