Documentation
¶
Overview ¶
Package eval contains the evaluator which executes the BASIC programs.
The interpreter is intentionally simple:
1. The input program is parsed into a series of tokens.
2. Each token is executed sequentially.
There are distinct handlers for each kind of built-in primitive such as REM, DATA, READ, etc. Things that could be pushed outside the core, such as the maths-primitives (SIN, COS, TAN, etc) have been moved into their own package to keep this as simple and readable as possible.
Index ¶
- type ForLoop
- type Interpreter
- func (e *Interpreter) Data() interface{}
- func (e *Interpreter) GetArrayVariable(id string, index []int) object.Object
- func (e *Interpreter) GetTrace() bool
- func (e *Interpreter) GetVariable(id string) object.Object
- func (e *Interpreter) LineEnding() string
- func (e *Interpreter) RegisterBuiltin(name string, nArgs int, ft builtin.Signature)
- func (e *Interpreter) Run() error
- func (e *Interpreter) RunOnce() error
- func (e *Interpreter) SetArrayVariable(id string, index []int, val object.Object) error
- func (e *Interpreter) SetTrace(val bool)
- func (e *Interpreter) SetVariable(id string, val object.Object)
- func (e *Interpreter) StdError() *bufio.Writer
- func (e *Interpreter) StdInput() *bufio.Reader
- func (e *Interpreter) StdOutput() *bufio.Writer
- type Loops
- type Stack
- type Variables
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ForLoop ¶
type ForLoop struct {
// contains filtered or unexported fields
}
ForLoop is the structure used to record a for-loop
type Interpreter ¶
type Interpreter struct { // STDIN is an input-reader used for the INPUT statement STDIN *bufio.Reader // STDOUT is the writer used for PRINT and DUMP statements STDOUT *bufio.Writer // STDERR is the writer used for user facing errors during program execution STDERR *bufio.Writer // LINEEND defines any additional characters to output when printing // to the output or error streams. LINEEND string // contains filtered or unexported fields }
Interpreter holds our state.
func FromString ¶
func FromString(input string) (*Interpreter, error)
FromString is a constructor which takes a string, and constructs an Interpreter from it - rather than requiring the use of the tokenizer.
func New ¶
func New(stream *tokenizer.Tokenizer) (*Interpreter, error)
New is our constructor.
Given a lexer we store all the tokens it produced in our array, and initialise some other state.
func NewWithContext ¶
NewWithContext is a constructor which allows a context to be specified.
It will defer to New for the basic constructor behaviour.
func (*Interpreter) Data ¶
func (e *Interpreter) Data() interface{}
Data returns a reference to this underlying Interpreter
func (*Interpreter) GetArrayVariable ¶
func (e *Interpreter) GetArrayVariable(id string, index []int) object.Object
GetArrayVariable gets the contents of the specified array value.
Useful for testing/embedding
func (*Interpreter) GetTrace ¶
func (e *Interpreter) GetTrace() bool
GetTrace returns a boolean result indicating whether debugging information is output to STDOUT during the course of execution.
func (*Interpreter) GetVariable ¶
func (e *Interpreter) GetVariable(id string) object.Object
GetVariable returns the contents of the given variable.
Useful for testing/embedding.
func (*Interpreter) LineEnding ¶
func (e *Interpreter) LineEnding() string
LineEnding defines an additional characters to write after PRINT commands
func (*Interpreter) RegisterBuiltin ¶
func (e *Interpreter) RegisterBuiltin(name string, nArgs int, ft builtin.Signature)
RegisterBuiltin registers a function as a built-in, so that it can be called from the users' BASIC program.
Useful for embedding.
func (*Interpreter) Run ¶
func (e *Interpreter) Run() error
Run launches the program, and does not return until it is over.
A program will terminate when the control reaches the end of the final-line, or when the "END" token is encountered.
func (*Interpreter) RunOnce ¶
func (e *Interpreter) RunOnce() error
RunOnce executes a single statement.
func (*Interpreter) SetArrayVariable ¶
SetArrayVariable sets the contents of the specified array value.
Useful for testing/embedding
func (*Interpreter) SetTrace ¶
func (e *Interpreter) SetTrace(val bool)
SetTrace allows the user to enable output of debugging-information to STDOUT when the intepreter is running.
func (*Interpreter) SetVariable ¶
func (e *Interpreter) SetVariable(id string, val object.Object)
SetVariable sets the contents of a variable in the interpreter environment.
Useful for testing/embedding.
func (*Interpreter) StdError ¶
func (e *Interpreter) StdError() *bufio.Writer
StdError allows access to the error-writing object.
func (*Interpreter) StdInput ¶
func (e *Interpreter) StdInput() *bufio.Reader
StdInput allows access to the input-reading object.
func (*Interpreter) StdOutput ¶
func (e *Interpreter) StdOutput() *bufio.Writer
StdOutput allows access to the output-writing object.
type Loops ¶
type Loops struct {
// contains filtered or unexported fields
}
Loops is the structure which holds ForLoop entries
type Stack ¶
type Stack struct {
// contains filtered or unexported fields
}
Stack holds the stack-data, protected by a mutex