Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidCommand = errors.New("invalid command")
ErrInvalidCommand is an error represenitng a command is invalid.
Functions ¶
This section is empty.
Types ¶
type CommandType ¶
type CommandType int
CommandType represents a type of VM command.
const ( Arithmetic CommandType Push Pop Label Goto If Function Return Call )
A list of command types.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser is a parser for VM code. Parser is not thread safe, so it should NOT be used in multiple goroutines.
func (*Parser) Advance ¶
Advance reads next command from source and set the command to current one. If the next command is invalid, it returns an error. This method should be called only if HasMoreCommands() returns true.
func (*Parser) Arg1 ¶
Arg1 returns the first argument in a current command. If a type of the current command is Arithmetic, it returns the command itself. This method should NOT be called if CommandType() returns Return.
func (*Parser) Arg2 ¶
Arg2 returns the second argument in a current command. This method should be called only if CommandType() returns Push, Pop, Function or Call.
func (*Parser) CommandType ¶
func (p *Parser) CommandType() CommandType
CommandType returns a type of a current VM command. In all arithmetic commands it returns Arithmetic.
func (*Parser) HasMoreCommands ¶
HasMoreCommands reports whether there exist more commands in input.