node

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

node is an abstract syntax tree (AST) node

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ByteCode added in v1.3.0

func ByteCode(bc ByteCoder, cr compResult)

func ByteCodeNoStck added in v1.3.0

func ByteCodeNoStck(bc ByteCoder, cr compResult)

func Graphviz added in v1.3.0

func Graphviz(top graphvizzer)

Graphviz writes dot format graphviz output of AST to stdout

print function for debugging calc. It prints an AST transforming it into a graphviz dotfile. One can convert the resulting file into an svg or other image formats.

% ./cmd --ast ../examples/euler_35.calc > x.dot
% gvpack -u x.dot > packed.dot
% dot -Tsvg packed.dot -o x.svg

func Loop added in v1.3.0

func Loop(r lineReader, p Parser, vm *vm.Type, doOut bool)

Types

type Assign added in v1.3.0

type Assign struct {
	VarRef Type // VarRef is variable reference
	Value  Type // Value is assigned value
}

func (Assign) STRewrite added in v1.3.0

func (a Assign) STRewrite(symTbl SymTbl) Type

type Aton

type Aton struct{ Value Type }

Aton converts a string to a number type.

func (Aton) STRewrite added in v1.3.0

func (a Aton) STRewrite(symTbl SymTbl) Type

type BinOp

type BinOp struct {
	Op    string // Op is the operator string
	Left  Type   // Left operand
	Right Type   // Right operand
}

BinOp is a binary operator of any kind, anything from "=", etc.

func (BinOp) STRewrite added in v1.3.0

func (b BinOp) STRewrite(symTbl SymTbl) Type

type Block

type Block struct {
	Body []Type // Body is the block body
}

Block is a code block / sequence that was in '{', '}'.

func (Block) STRewrite added in v1.3.0

func (b Block) STRewrite(symTbl SymTbl) Type

type Bool added in v1.3.0

type Bool bool

Bool is boolean literal.

func (Bool) STRewrite added in v1.3.0

func (b Bool) STRewrite(_ SymTbl) Type

type ByteCoder added in v1.3.0

type ByteCoder interface {
	// contains filtered or unexported methods
}

type Call

type Call struct {
	Name      Type // Variable referencing function
	Arguments List // Arguments passed to the function
}

Call is function call.

func (Call) STRewrite added in v1.3.0

func (c Call) STRewrite(symTbl SymTbl) Type

type Closure added in v1.3.0

type Closure struct {
	Ix      int    // Ix is the index in the call frame
	VarName string // VarName is variable name
}

Closure variable reference.

func (Closure) Name added in v1.4.0

func (c Closure) Name() string

func (Closure) STRewrite added in v1.3.0

func (c Closure) STRewrite(_ SymTbl) Type

type Exit added in v1.3.0

type Exit struct{ Value Type }

Exit exits the interpreter with an os exit code.

func (Exit) STRewrite added in v1.3.0

func (e Exit) STRewrite(symTbl SymTbl) Type

type FReader added in v1.4.0

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

func NewFReader added in v1.3.0

func NewFReader(fn string) FReader

func (FReader) Close added in v1.4.0

func (f FReader) Close() error

type Float

type Float float64

Float is float literal.

func (Float) STRewrite added in v1.3.0

func (f Float) STRewrite(_ SymTbl) Type

type For added in v1.3.0

type For struct {
	VarRef   Type // VarRef is variable reference
	Iterator Type // Value is assigned value
	Body     Type // Body is the loop body
}

For is a loop for iterators ans generators.

func (For) STRewrite added in v1.3.0

func (f For) STRewrite(symTbl SymTbl) Type

type Function

type Function struct {
	Parameters List // Parameters of the function
	Body       Type // Body of the function
	LocalCnt   int  // count of local variables
}

Function is a function definition.

func (Function) STRewrite added in v1.3.0

func (f Function) STRewrite(symTbl SymTbl) Type

type If

type If struct {
	Condition Type // Condition is the condition for the if statement
	TrueCase  Type // TrueCase is executed if condition evaluates to true
}

If is a conditional construct without an else case.

func (If) STRewrite added in v1.3.0

func (i If) STRewrite(symTbl SymTbl) Type

type IfElse

type IfElse struct {
	Condition Type // Condition is the condition for the if statement
	TrueCase  Type // TrueCase is executed if condition evaluates to true
	FalseCase Type // FalseCase is executed if condition evaluates to false
}

IfElse is a conditional construct.

func (IfElse) STRewrite added in v1.3.0

func (i IfElse) STRewrite(symTbl SymTbl) Type

type IndexAt

type IndexAt struct {
	Ary Type // Ary is the indexed node
	At  Type // At is the index
}

func (IndexAt) STRewrite added in v1.3.0

func (i IndexAt) STRewrite(symTbl SymTbl) Type

type IndexFromTo

type IndexFromTo struct {
	Ary  Type // Ary is the indexed node
	From Type // From is the start of the range
	To   Type // To is the end of the range
}

func (IndexFromTo) STRewrite added in v1.3.0

func (i IndexFromTo) STRewrite(symTbl SymTbl) Type

type Int

type Int int

Int is integer literal.

func (Int) STRewrite added in v1.3.0

func (i Int) STRewrite(_ SymTbl) Type

type Invalid

type Invalid struct{}

Invalid is an invalid AST node.

type List

type List struct {
	Elems []Type // Elems are the parameters or arguments
}

List is a list of arguments or parameters depending on whether it's a function call or definition.

func (List) STRewrite added in v1.3.0

func (l List) STRewrite(symTbl SymTbl) Type

type Local added in v1.3.0

type Local struct {
	Ix      int    // Ix is the index in the call frame
	VarName string // VarName is variable name
}

Local variable reference.

func (Local) Name added in v1.4.0

func (l Local) Name() string

func (Local) STRewrite added in v1.3.0

func (l Local) STRewrite(_ SymTbl) Type

type Name

type Name string

Variable name.

func (Name) Name added in v1.4.0

func (n Name) Name() string

func (Name) STRewrite added in v1.3.0

func (n Name) STRewrite(symTbl SymTbl) Type

type Namer added in v1.4.0

type Namer interface {
	Name() string
}

type Parser added in v1.3.0

type Parser interface {
	Parse(string) ([]Type, ParserError)
}

type ParserError added in v1.4.0

type ParserError = *combinator.Error

type RLReader added in v1.4.0

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

func NewRLReader added in v1.3.0

func NewRLReader() RLReader

func (RLReader) Close added in v1.4.0

func (rl RLReader) Close() error

type Read

type Read struct{}

Read reads a string from stdin.

func (Read) STRewrite added in v1.3.0

func (r Read) STRewrite(_ SymTbl) Type

type Return

type Return struct {
	Target Type // Target is the returned value
}

Return is a return statement.

func (Return) STRewrite added in v1.3.0

func (r Return) STRewrite(symTbl SymTbl) Type

type STRewriter added in v1.3.0

type STRewriter interface {
	STRewrite(symTbl SymTbl) Type
}

STRewriter is a recursive node transformation that resolves local and closure variable names to indices into the call frame

It is not idempotent. It is supposed to be called after the parser produced the AST and before evaluation. Global variables are untouched. Local variables are changed from Name nodes to either Local or Closure nodes.

type String

type String string

String is string literal.

func (String) STRewrite added in v1.3.0

func (s String) STRewrite(_ SymTbl) Type

type SymTbl added in v1.3.0

type SymTbl []map[string]int

type Toa added in v1.3.0

type Toa struct{ Value Type }

Toa converts a valye to a string.

func (Toa) STRewrite added in v1.3.0

func (t Toa) STRewrite(symTbl SymTbl) Type

type Type

type Type interface {
	STRewriter

	ByteCoder
	// contains filtered or unexported methods
}

Type is AST node type.

type UnOp

type UnOp struct {
	Op     string // Op is the operator string
	Target Type   // Target is the operand
}

UnOp is a unary operator of any kind, ie. '-'.

func (UnOp) STRewrite added in v1.3.0

func (u UnOp) STRewrite(symTbl SymTbl) Type

type While

type While struct {
	Condition Type // Condition is the condition for the loop
	Body      Type // Body is the loop body
}

While is a loop construct.

func (While) STRewrite added in v1.3.0

func (w While) STRewrite(symTbl SymTbl) Type

type Write

type Write struct{ Value Type }

Write writes a value to stdout.

func (Write) STRewrite added in v1.3.0

func (w Write) STRewrite(symTbl SymTbl) Type

type Yield added in v1.3.0

type Yield struct {
	Target Type // Target is the yielded value
}

Yield statement.

func (Yield) STRewrite added in v1.3.0

func (y Yield) STRewrite(symTbl SymTbl) Type

Jump to

Keyboard shortcuts

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