ast

package
v0.0.0-...-c85daa3 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NodeIsVariable

func NodeIsVariable(node Node) bool

NodeIsVariable allows for nice statements like if NodeIsVariable(node) {}

Types

type BoolLit

type BoolLit struct {
	Value string
}

BoolLit represents a boolean litteral being either "True" or "False"

func (BoolLit) GetNodeName

func (bm BoolLit) GetNodeName() string

type DirectOperation

type DirectOperation struct {
	Variable  Node
	Operation string
}

func (DirectOperation) GetNodeName

func (do DirectOperation) GetNodeName() string

type Eos

type Eos struct {
	Body []Node
}

Eos is a special node in a switch statement that is called if defined when no cases match the given value

func (Eos) GetNodeName

func (eos Eos) GetNodeName() string

type Expression

type Expression struct {
	Tokens []lexer.Token
}

Expression contains nodes in RPN form

func (Expression) GetNodeName

func (e Expression) GetNodeName() string

GetNodeName so its valid on the node interface and we can ask what type it is later

type FreeStatement

type FreeStatement struct {
	Variable Node
}

FreeStatement is an instruction that frees a variable from the stack

func (FreeStatement) GetNodeName

func (r FreeStatement) GetNodeName() string

type Function

type Function struct {
	Name   string
	Params []string
	Body   []Node
}

Function is a standard function definition containing the name, parameters and body of the function

func (Function) GetNodeName

func (f Function) GetNodeName() string

type FunctionCall

type FunctionCall struct {
	Name string
	Args []Node
}

FunctionCall specifies a function call and the arguments given

func (FunctionCall) GetNodeName

func (fc FunctionCall) GetNodeName() string

type IfStatement

type IfStatement struct {
	Condition Node
	Body      []Node
}

IfStatement is a conditional block that has an expression and a body

func (IfStatement) GetNodeName

func (i IfStatement) GetNodeName() string

type Litteral

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

Litteral is a node type for static values such as integers and string litterals

func CreateLitteral

func CreateLitteral(value string, ltype string) Litteral

CreateLitteral creates a new Litteral struct

func (Litteral) GetNodeName

func (l Litteral) GetNodeName() string

GetNodeName is a generic function that allows subtypes of a node in the AST

type Node

type Node interface {
	GetNodeName() string //GetNodeName Gets the identifier of a AST node describing what it is
}

Node is a wrapper interface that AST nodes can implement

type NumLit

type NumLit struct {
	Value string
}

NumLit represents a numeric litteral.

func (NumLit) GetNodeName

func (nm NumLit) GetNodeName() string

type Operator

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

Operator is a symbol that operates on one or more sides

func (Operator) GetNodeName

func (o Operator) GetNodeName() string

GetNodeName is a generic function that allows subtypes of a node in the AST

type Parser

type Parser struct {
	Tokens         []lexer.Token
	Ast            []Node
	Filename       string
	TokensConsumed int
}

Parser contains the final AST and forms a base for all ast generating functions

func NewParser

func NewParser(filename string, tokens []lexer.Token) *Parser

NewParser returns a new Parser instance with the given file

func (*Parser) Parse

func (p *Parser) Parse(delim string) ([]Node, int)

Parse takes a set of tokens and generates an AST from them

type PlotStatement

type PlotStatement struct {
	X, Y Node
}

PlotStatement is a statement that contains all info needed to draw a pixel to the screen

func (PlotStatement) GetNodeName

func (p PlotStatement) GetNodeName() string

type PrintCall

type PrintCall struct {
	Printable Node
}

PrintCall specifies a call to the inbuilt print function

func (PrintCall) GetNodeName

func (pc PrintCall) GetNodeName() string

type SetStatement

type SetStatement struct {
	MHS Node
	RHS Node
}

SetStatement is used when a value needs to be set to a variable. Instructions that could make use of this are SET

func (SetStatement) GetNodeName

func (ss SetStatement) GetNodeName() string

type StatVar

type StatVar struct {
	Value string
}

StatVar contains the value of a static variable. These statVars are used when a variable is being referenced where the Value is the name of the variable referenced

func (StatVar) GetNodeName

func (sv StatVar) GetNodeName() string

type Statement

type Statement struct {
	LHS string
	RHS Node
}

Statement is a general statement container for all other statements that do not fall under math and logic for example MEM

func (Statement) GetNodeName

func (s Statement) GetNodeName() string

type StringLit

type StringLit struct {
	Value string
}

StringLit represents a string litteral

func (StringLit) GetNodeName

func (sl StringLit) GetNodeName() string

type SwitchCase

type SwitchCase struct {
	MatchValue Node
	Body       []Node
}

SwitchCase is a block definiton that is run when the MatchValue is matched

func (SwitchCase) GetNodeName

func (sc SwitchCase) GetNodeName() string

type SwitchStatement

type SwitchStatement struct {
	MatchValue Node
	Cases      []Node
}

SwitchStatement matches the Matchcase against all cases defined in Cases of the switchcase if one matches, the body of that case will be executed. if a EOS is defined within the body, the EOS body will be run if no case matches the matchvalue

func (SwitchStatement) GetNodeName

func (st SwitchStatement) GetNodeName() string

type Symbol

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

Symbol is a character that is not and operator or a latin character / numeral

func CreateSymbol

func CreateSymbol(value string) Symbol

CreateSymbol takes a string and returns it wrapped in a node like

func (Symbol) GetNodeName

func (s Symbol) GetNodeName() string

GetNodeName is a generic function that allows subtypes of a node in the AST

type Variable

type Variable struct {
	Name            string
	Type            string
	Value           Node
	ValueExpression Expression
}

Variable is a construct used to create a new variable. This is the struct that will be pushed to the stack

func (*Variable) GetAllocationType

func (v *Variable) GetAllocationType() string

GetAllocationType determines if a type must be stack or heap allocated

func (Variable) GetNodeName

func (v Variable) GetNodeName() string

type VariableReference

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

VariableReference contains the name of a referenced variable during AST generation

func (VariableReference) GetNodeName

func (vr VariableReference) GetNodeName() string

GetNodeName so its valid on the node interface and we can ask what type it is later

Jump to

Keyboard shortcuts

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