syntax

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2022 License: BSD-3-Clause Imports: 4 Imported by: 1

Documentation

Index

Constants

View Source
const (
	App    = "gscript"
	Indent = "├"

)

Variables

This section is empty.

Functions

func ArithmeticOperators

func ArithmeticOperators(script string) interface{}

func EvaluateWithRuntime

func EvaluateWithRuntime(node *ASTNode, indent string) interface{}

EvaluateWithRuntime deep recursion loop AST

func InitRuntime

func InitRuntime(verbose bool)

Types

type ASTNode

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

ASTNode AST tree

func AdditiveLoop

func AdditiveLoop(tokenReader *TokenReader) (*ASTNode, error)

AdditiveLoop Additive -> Multiplicative ( (+ | -) Multiplicative)*

func AssignmentStatement

func AssignmentStatement(reader *TokenReader) (*ASTNode, error)

AssignmentStatement -> Identifier = Additive parse: a = 10*2,

func ExpressionStatement

func ExpressionStatement(reader *TokenReader) (*ASTNode, error)

ExpressionStatement -> 1+2*3 '\n'

func IntDeclare

func IntDeclare(tokenReader *TokenReader) (*ASTNode, error)

IntDeclare int a=10+1*2

func MultiplicativeLoop

func MultiplicativeLoop(tokenReader *TokenReader) (*ASTNode, error)

MultiplicativeLoop Multiplicative -> Primary ((* | /) Primary)*

func NewASTNode

func NewASTNode(nodeType ASTNodeType, text string) *ASTNode

func Parse

func Parse(script string) (*ASTNode, error)

Parse syntax parsing. Program -> IntDeclaration | ExpressionStatement | AssignmentStatement IntDeclaration -> 'int' Id ( = Additive) '\n' ExpressionStatement -> Additive '\n' Additive -> Multiplicative ( (+ | -) Multiplicative)* Multiplicative -> Primary ((* | /) Primary)* Primary -> IntLiteral | Id | Additive AssignmentStatement -> Identifier = Additive

func Primary

func Primary(tokenReader *TokenReader) (*ASTNode, error)

Primary Analyze primary 1+2->1; IntLiteral | Id | Additive

func (*ASTNode) AddChild

func (a *ASTNode) AddChild(child *ASTNode)

func (*ASTNode) GetChildren

func (a *ASTNode) GetChildren() []*ASTNode

func (*ASTNode) GetNodeType

func (a *ASTNode) GetNodeType() ASTNodeType

func (*ASTNode) GetText

func (a *ASTNode) GetText() string

func (*ASTNode) Print

func (a *ASTNode) Print(indent string)

type ASTNodeType

type ASTNodeType string
const (
	Program            ASTNodeType = "Program"
	IntDeclaration     ASTNodeType = "IntDeclaration"
	AssignmentStmt     ASTNodeType = "AssignmentStmt"
	PrimaryType        ASTNodeType = "Primary"
	MultiplicativeType ASTNodeType = "Multiplicative"
	AdditiveType       ASTNodeType = "Additive"
	IdentifierType     ASTNodeType = "Identifier"
	FloatType          ASTNodeType = "FloatType"
	IntLiteralType     ASTNodeType = "IntLiteral"
)

AST tree: node type.

type Runtime

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

func GetRuntime

func GetRuntime() *Runtime

func NewRuntime

func NewRuntime(verbose bool) *Runtime

func (*Runtime) Vars

func (r *Runtime) Vars() map[string]interface{}

func (*Runtime) Verbose

func (r *Runtime) Verbose() bool

type TokenReader

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

TokenReader simulate token reader stream.

func NewTokenReader

func NewTokenReader(tokens []*token.TokenType) *TokenReader

func (*TokenReader) GetPos

func (t *TokenReader) GetPos() uint64

func (*TokenReader) Peek

func (t *TokenReader) Peek() *token.TokenType

Peek Pre read.

func (*TokenReader) Read

func (t *TokenReader) Read() *token.TokenType

Read read from token stream.

func (*TokenReader) SetPos

func (t *TokenReader) SetPos(pos uint64)

func (*TokenReader) UnRead

func (t *TokenReader) UnRead()

Jump to

Keyboard shortcuts

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