script

package
v0.0.17 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TokenPlus         = "+"
	TokenMinus        = "-"
	TokenMultiply     = "*"
	TokenFloatDiv     = "/"
	TokenLParen       = "("
	TokenRParen       = ")"
	TokenLSquare      = "["
	TokenRSquare      = "]"
	TokenLCurly       = "{"
	TokenRCurly       = "}"
	TokenSemi         = ";"
	TokenDot          = "."
	TokenColon        = ":"
	TokenComma        = ","
	TokenWorkflow     = "WORKFLOW"
	TokenNode         = "NODE"
	TokenWith         = "WITH"
	TokenSecret       = "SECRET"
	TokenInteger      = "INTEGER"
	TokenFloat        = "FLOAT"
	TokenString       = "STRING"
	TokenBoolean      = "BOOLEAN"
	TokenList         = "LIST"
	TokenDict         = "DICT"
	TokenMessage      = "MESSAGE"
	TokenIntegerDiv   = "DIV"
	TokenVar          = "VAR"
	TokenEnd          = "END"
	TokenPrint        = "PRINT"
	TokenID           = "ID"
	TokenIntegerConst = "INTEGER_CONST"
	TokenFloatConst   = "FLOAT_CONST"
	TokenStringConst  = "STRING_CONST"
	TokenMessageConst = "MESSAGE_CONST"
	TokenNodeConst    = "NODE_CONST"
	TokenAssign       = ":="
	TokenEOF          = "EOF"
	TokenIf           = "IF"
	TokenElse         = "ELSE"
	TokenWhile        = "WHILE"
	TokenOr           = "OR"
	TokenAnd          = "AND"
	TokenTrue         = "TRUE"
	TokenFalse        = "FALSE"
	TokenEqual        = "=="
	TokenNotEqual     = "!="
	TokenGreater      = ">"
	TokenGreaterEqual = ">="
	TokenLess         = "<"
	TokenLessEqual    = "<="
	TokenAt           = "@"
	TokenFlow         = "<-"
	TokenHash         = "#"
)

Variables

View Source
var Debug bool
View Source
var ReservedKeywords = map[string]Token{
	"WORKFLOW": {Type: TokenWorkflow, Value: TokenWorkflow},
	"NODE":     {Type: TokenNode, Value: TokenNode},
	"WITH":     {Type: TokenWith, Value: TokenWith},
	"SECRET":   {Type: TokenSecret, Value: TokenSecret},
	"VAR":      {Type: TokenVar, Value: TokenVar},
	"DIV":      {Type: TokenIntegerDiv, Value: TokenIntegerDiv},
	"INT":      {Type: TokenInteger, Value: TokenInteger},
	"FLOAT":    {Type: TokenFloat, Value: TokenFloat},
	"STRING":   {Type: TokenString, Value: TokenString},
	"BOOL":     {Type: TokenBoolean, Value: TokenBoolean},
	"END":      {Type: TokenEnd, Value: TokenEnd},
	"IF":       {Type: TokenIf, Value: TokenIf},
	"ELSE":     {Type: TokenElse, Value: TokenElse},
	"WHILE":    {Type: TokenWhile, Value: TokenWhile},
	"OR":       {Type: TokenOr, Value: TokenOr},
	"AND":      {Type: TokenAnd, Value: TokenAnd},
	"TRUE":     {Type: TokenTrue, Value: true},
	"FALSE":    {Type: TokenFalse, Value: false},
	"PRINT":    {Type: TokenPrint, Value: TokenPrint},
	"LIST":     {Type: TokenList, Value: TokenList},
	"DICT":     {Type: TokenDict, Value: TokenDict},
	"MESSAGE":  {Type: TokenMessage, Value: TokenMessage},
}

Functions

This section is empty.

Types

type ARType

type ARType string
const (
	ARTypeWorkflow ARType = "WORKFLOW"
)

type ActivationRecord

type ActivationRecord struct {
	Name         string
	Type         ARType
	NestingLevel int
	Members      map[string]interface{}
	ReturnValue  interface{}
}

func NewActivationRecord

func NewActivationRecord(name string, t ARType, nestingLevel int) *ActivationRecord

func (*ActivationRecord) Get

func (r *ActivationRecord) Get(key string) interface{}

func (*ActivationRecord) Set

func (r *ActivationRecord) Set(key string, value interface{})

func (*ActivationRecord) String

func (r *ActivationRecord) String() string

type Assign

type Assign struct {
	Left  Ast
	Op    *Token
	Right Ast
}

func NewAssign

func NewAssign(left Ast, op *Token, right Ast) *Assign

type Ast

type Ast interface{}

type BinOp

type BinOp struct {
	Left  Ast
	Token *Token
	Op    *Token
	Right Ast
}

func NewBinOp

func NewBinOp(left Ast, op *Token, right Ast) *BinOp

type Block

type Block struct {
	Declarations      [][]Ast
	CompoundStatement Ast
}

func NewBlock

func NewBlock(declarations [][]Ast, compoundStatement Ast) *Block

type BooleanConst

type BooleanConst struct {
	Token *Token
	Value bool
}

func NewBooleanConst

func NewBooleanConst(token *Token) *BooleanConst

type BuiltinTypeSymbol

type BuiltinTypeSymbol struct {
	Name       string
	Type       Symbol
	ScopeLevel int
}

func NewBuiltinTypeSymbol

func NewBuiltinTypeSymbol(name string) *BuiltinTypeSymbol

func (*BuiltinTypeSymbol) String

func (s *BuiltinTypeSymbol) String() string

type CallStack

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

func NewCallStack

func NewCallStack() *CallStack

func (*CallStack) Peek

func (s *CallStack) Peek() *ActivationRecord

func (*CallStack) Pop

func (s *CallStack) Pop() *ActivationRecord

func (*CallStack) Push

func (s *CallStack) Push(ar *ActivationRecord)

func (*CallStack) String

func (s *CallStack) String() string

type Compound

type Compound struct {
	Children []Ast
}

func NewCompound

func NewCompound() *Compound

type Dict

type Dict struct {
	Token *Token
	Value map[string]Ast
}

func NewDict

func NewDict(token *Token) *Dict

type Error

type Error struct {
	ErrorCode ErrorCode
	Token     *Token
	Message   string
	Type      ErrorType
}

func (Error) Error

func (e Error) Error() string

type ErrorCode

type ErrorCode string
const (
	UnexpectedToken   ErrorCode = "Unexpected token"
	IdNotFound        ErrorCode = "Identifier not found"
	DuplicateId       ErrorCode = "Duplicate id found"
	NoMainWorkflow    ErrorCode = "No main workflow"
	WrongParamsNum    ErrorCode = "Wrong number of arguments"
	UndefinedFunction ErrorCode = "Undefined function"
)

type ErrorType

type ErrorType string
const (
	LexerErrorType    ErrorType = "LexerError"
	ParserErrorType   ErrorType = "ParserError"
	SemanticErrorType ErrorType = "SemanticError"
)

type Flow

type Flow struct {
	Nodes []Ast
}

func NewFlow

func NewFlow(nodes []Ast) *Flow

type If

type If struct {
	Condition  Ast
	ThenBranch []Ast
	ElseBranch []Ast
}

func NewIf

func NewIf(condition Ast, thenBranch []Ast, elseBranch []Ast) *If

type Interpreter

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

func NewInterpreter

func NewInterpreter(tree Ast) *Interpreter

func (*Interpreter) Interpret

func (i *Interpreter) Interpret() (float64, error)

func (*Interpreter) SetClient

func (i *Interpreter) SetClient(midClient pb.MiddleClient)

func (*Interpreter) Stdout

func (i *Interpreter) Stdout() string

func (*Interpreter) Visit

func (i *Interpreter) Visit(node Ast) interface{}

func (*Interpreter) VisitAssign

func (i *Interpreter) VisitAssign(node *Assign) float64

func (*Interpreter) VisitBinOp

func (i *Interpreter) VisitBinOp(node *BinOp) float64

func (*Interpreter) VisitBlock

func (i *Interpreter) VisitBlock(node *Block) float64

func (*Interpreter) VisitBooleanConst

func (i *Interpreter) VisitBooleanConst(node *BooleanConst) bool

func (*Interpreter) VisitCompound

func (i *Interpreter) VisitCompound(node *Compound) float64

func (*Interpreter) VisitDict

func (i *Interpreter) VisitDict(node *Dict) map[string]interface{}

func (*Interpreter) VisitFlow

func (i *Interpreter) VisitFlow(node *Flow) float64

func (*Interpreter) VisitIf

func (i *Interpreter) VisitIf(node *If) interface{}

func (*Interpreter) VisitList

func (i *Interpreter) VisitList(node *List) []interface{}

func (*Interpreter) VisitLogical

func (i *Interpreter) VisitLogical(node *Logical) bool

func (*Interpreter) VisitMessageConst

func (i *Interpreter) VisitMessageConst(node *MessageConst) interface{}

func (*Interpreter) VisitNoOp

func (i *Interpreter) VisitNoOp(_ *NoOp) float64

func (*Interpreter) VisitNode

func (i *Interpreter) VisitNode(node *Node) map[string]interface{}

func (*Interpreter) VisitNodeConst

func (i *Interpreter) VisitNodeConst(node *NodeConst) interface{}

func (*Interpreter) VisitNumberConst

func (i *Interpreter) VisitNumberConst(node *NumberConst) float64

func (*Interpreter) VisitPrint

func (i *Interpreter) VisitPrint(node *Print) interface{}

func (*Interpreter) VisitProgram

func (i *Interpreter) VisitProgram(node *Program) float64

func (*Interpreter) VisitStringConst

func (i *Interpreter) VisitStringConst(node *StringConst) string

func (*Interpreter) VisitType

func (i *Interpreter) VisitType(_ *Type) float64

func (*Interpreter) VisitUnaryOp

func (i *Interpreter) VisitUnaryOp(node *UnaryOp) float64

func (*Interpreter) VisitVar

func (i *Interpreter) VisitVar(node *Var) interface{}

func (*Interpreter) VisitVarDecl

func (i *Interpreter) VisitVarDecl(_ *VarDecl) float64

func (*Interpreter) VisitWhile

func (i *Interpreter) VisitWhile(node *While) float64

func (*Interpreter) VisitWorkflow

func (i *Interpreter) VisitWorkflow(node *Workflow) float64

type Lexer

type Lexer struct {
	Text        []rune
	Pos         int
	CurrentChar rune
	LineNo      int
	Column      int
}

func NewLexer

func NewLexer(text []rune) *Lexer

func (*Lexer) Advance

func (l *Lexer) Advance()

func (*Lexer) GetNextToken

func (l *Lexer) GetNextToken() (*Token, error)

func (*Lexer) Id

func (l *Lexer) Id() (*Token, error)

func (*Lexer) Message

func (l *Lexer) Message() (*Token, error)

func (*Lexer) Node

func (l *Lexer) Node() (*Token, error)

func (*Lexer) Number

func (l *Lexer) Number() (*Token, error)

func (*Lexer) Peek

func (l *Lexer) Peek() rune

func (*Lexer) SkipComment

func (l *Lexer) SkipComment()

func (*Lexer) SkipWhitespace

func (l *Lexer) SkipWhitespace()

func (*Lexer) String

func (l *Lexer) String() (*Token, error)

type List

type List struct {
	Token *Token
	Value []Ast
}

func NewList

func NewList(token *Token) *List

type Logical

type Logical struct {
	Left  Ast
	Op    *Token
	Right Ast
}

func NewLogical

func NewLogical(left Ast, op *Token, right Ast) *Logical

type MessageConst

type MessageConst struct {
	Token *Token
	Value interface{}
}

func NewMessageConst

func NewMessageConst(token *Token) *MessageConst

type NoOp

type NoOp struct{}

func NewNoOp

func NewNoOp() *NoOp

type Node

type Node struct {
	Name       string
	Regular    string
	With       Ast
	Parameters map[string]interface{}
	Secret     string
}

func NewNode

func NewNode(name string, regular string, with Ast, secret string) *Node

type NodeConst

type NodeConst struct {
	Token *Token
	Value interface{}
}

func NewNodeConst

func NewNodeConst(token *Token) *NodeConst

type NodeSymbol

type NodeSymbol struct {
	Name       string
	Parameters []Ast
	BlockAst   Ast
	ScopeLevel int
}

func NewNodeSymbol

func NewNodeSymbol(name string) *NodeSymbol

func (*NodeSymbol) String

func (s *NodeSymbol) String() string

type NumberConst

type NumberConst struct {
	Token *Token
	Value float64
}

func NewNumberConst

func NewNumberConst(token *Token) *NumberConst

type Param

type Param struct {
	VarNode  Ast
	TypeNode Ast
}

func NewParam

func NewParam(varNode Ast, typeNode Ast) *Param

type Parser

type Parser struct {
	Lexer        *Lexer
	CurrentToken *Token
}

func NewParser

func NewParser(lexer *Lexer) (*Parser, error)

func (*Parser) AssignmentStatement

func (p *Parser) AssignmentStatement() (Ast, error)

func (*Parser) Block

func (p *Parser) Block() (Ast, error)

func (*Parser) Comparison

func (p *Parser) Comparison() (Ast, error)

func (*Parser) CompoundStatement

func (p *Parser) CompoundStatement() (Ast, error)

func (*Parser) Declarations

func (p *Parser) Declarations() ([][]Ast, error)

func (*Parser) Dict

func (p *Parser) Dict() (Ast, error)

func (*Parser) Eat

func (p *Parser) Eat(tokenType TokenType) (err error)

func (*Parser) Empty

func (p *Parser) Empty() (Ast, error)

func (*Parser) Equality

func (p *Parser) Equality() (Ast, error)

func (*Parser) Expr

func (p *Parser) Expr() (Ast, error)

func (*Parser) Expression

func (p *Parser) Expression() (Ast, error)

func (*Parser) Factor

func (p *Parser) Factor() (Ast, error)

func (*Parser) FlowStatement

func (p *Parser) FlowStatement() (Ast, error)

func (*Parser) FormalParameters

func (p *Parser) FormalParameters() ([]Ast, error)

func (*Parser) IfStatement

func (p *Parser) IfStatement() (Ast, error)

func (*Parser) List

func (p *Parser) List() (Ast, error)

func (*Parser) LogicAnd

func (p *Parser) LogicAnd() (Ast, error)

func (*Parser) LogicOr

func (p *Parser) LogicOr() (Ast, error)

func (*Parser) Node

func (p *Parser) Node() (map[string]Ast, error)

func (*Parser) Parse

func (p *Parser) Parse() (Ast, error)

func (*Parser) PrintStatement

func (p *Parser) PrintStatement() (Ast, error)

func (*Parser) Program

func (p *Parser) Program() (Ast, error)

func (*Parser) Statement

func (p *Parser) Statement() (Ast, error)

func (*Parser) StatementList

func (p *Parser) StatementList() ([]Ast, error)

func (*Parser) Term

func (p *Parser) Term() (Ast, error)

func (*Parser) TypeSpec

func (p *Parser) TypeSpec() (Ast, error)

func (*Parser) Variable

func (p *Parser) Variable() (Ast, error)

func (*Parser) VariableDeclaration

func (p *Parser) VariableDeclaration() ([]Ast, error)

func (*Parser) WhileStatement

func (p *Parser) WhileStatement() (Ast, error)

func (*Parser) Workflow

func (p *Parser) Workflow() (map[string]Ast, error)

type Print

type Print struct {
	Statement Ast
}

func NewPrint

func NewPrint(statement Ast) *Print

type Program

type Program struct {
	Name      string
	Nodes     map[string]Ast
	Workflows map[string]Ast
}

func NewProgram

func NewProgram(name string, nodes map[string]Ast, workflows map[string]Ast) *Program

type ScopedSymbolTable

type ScopedSymbolTable struct {
	ScopeName      string
	ScopeLevel     int
	EnclosingScope *ScopedSymbolTable
	// contains filtered or unexported fields
}

func NewScopedSymbolTable

func NewScopedSymbolTable(scopeName string, scopeLevel int, enclosingScope *ScopedSymbolTable) *ScopedSymbolTable

func (*ScopedSymbolTable) Insert

func (t *ScopedSymbolTable) Insert(symbol Symbol)

func (*ScopedSymbolTable) Lookup

func (t *ScopedSymbolTable) Lookup(name string, currentScopeOnly bool) Symbol

func (*ScopedSymbolTable) String

func (t *ScopedSymbolTable) String() string

type SemanticAnalyzer

type SemanticAnalyzer struct {
	CurrentScope *ScopedSymbolTable
}

func NewSemanticAnalyzer

func NewSemanticAnalyzer() *SemanticAnalyzer

func (*SemanticAnalyzer) Visit

func (b *SemanticAnalyzer) Visit(node Ast)

func (*SemanticAnalyzer) VisitAssign

func (b *SemanticAnalyzer) VisitAssign(node *Assign)

func (*SemanticAnalyzer) VisitBinOp

func (b *SemanticAnalyzer) VisitBinOp(node *BinOp)

func (*SemanticAnalyzer) VisitBlock

func (b *SemanticAnalyzer) VisitBlock(node *Block)

func (*SemanticAnalyzer) VisitBooleanConst

func (b *SemanticAnalyzer) VisitBooleanConst(_ *BooleanConst)

func (*SemanticAnalyzer) VisitCompound

func (b *SemanticAnalyzer) VisitCompound(node *Compound)

func (*SemanticAnalyzer) VisitDict

func (b *SemanticAnalyzer) VisitDict(node *Dict)

func (*SemanticAnalyzer) VisitFlow

func (b *SemanticAnalyzer) VisitFlow(node *Flow)

func (*SemanticAnalyzer) VisitIf

func (b *SemanticAnalyzer) VisitIf(node *If)

func (*SemanticAnalyzer) VisitList

func (b *SemanticAnalyzer) VisitList(node *List)

func (*SemanticAnalyzer) VisitLogical

func (b *SemanticAnalyzer) VisitLogical(node *Logical)

func (*SemanticAnalyzer) VisitMessageConst

func (b *SemanticAnalyzer) VisitMessageConst(_ *MessageConst)

func (*SemanticAnalyzer) VisitNoOp

func (b *SemanticAnalyzer) VisitNoOp(_ *NoOp)

func (*SemanticAnalyzer) VisitNode

func (b *SemanticAnalyzer) VisitNode(node *Node)

func (*SemanticAnalyzer) VisitNodeConst

func (b *SemanticAnalyzer) VisitNodeConst(_ *NodeConst)

func (*SemanticAnalyzer) VisitNumberConst

func (b *SemanticAnalyzer) VisitNumberConst(_ *NumberConst)

func (*SemanticAnalyzer) VisitPrint

func (b *SemanticAnalyzer) VisitPrint(node *Print)

func (*SemanticAnalyzer) VisitProgram

func (b *SemanticAnalyzer) VisitProgram(node *Program)

func (*SemanticAnalyzer) VisitStringConst

func (b *SemanticAnalyzer) VisitStringConst(_ *StringConst)

func (*SemanticAnalyzer) VisitType

func (b *SemanticAnalyzer) VisitType(_ *Type)

func (*SemanticAnalyzer) VisitUnaryOp

func (b *SemanticAnalyzer) VisitUnaryOp(_ *UnaryOp)

func (*SemanticAnalyzer) VisitVar

func (b *SemanticAnalyzer) VisitVar(node *Var)

func (*SemanticAnalyzer) VisitVarDecl

func (b *SemanticAnalyzer) VisitVarDecl(node *VarDecl)

func (*SemanticAnalyzer) VisitWhile

func (b *SemanticAnalyzer) VisitWhile(node *While)

func (*SemanticAnalyzer) VisitWorkflow

func (b *SemanticAnalyzer) VisitWorkflow(node *Workflow)

type StringConst

type StringConst struct {
	Token *Token
	Value string
}

func NewStringConst

func NewStringConst(token *Token) *StringConst

type Symbol

type Symbol interface{}

type Token

type Token struct {
	Type   TokenType
	Value  interface{}
	LineNo int
	Column int
}

func (*Token) String

func (t *Token) String() string

type TokenType

type TokenType string

type Type

type Type struct {
	Token *Token
	Value interface{}
}

func NewType

func NewType(token *Token) *Type

type UnaryOp

type UnaryOp struct {
	Op   *Token
	Expr Ast
}

func NewUnaryOp

func NewUnaryOp(op *Token, expr Ast) *UnaryOp

type Var

type Var struct {
	Token *Token
	Value interface{}
}

func NewVar

func NewVar(token *Token) *Var

type VarDecl

type VarDecl struct {
	VarNode  Ast
	TypeNode Ast
}

func NewVarDecl

func NewVarDecl(varNode Ast, typeNode Ast) *VarDecl

type VarSymbol

type VarSymbol struct {
	Name       string
	Type       Symbol
	ScopeLevel int
}

func NewVarSymbol

func NewVarSymbol(name string, t Symbol) *VarSymbol

func (*VarSymbol) String

func (s *VarSymbol) String() string

type While

type While struct {
	Condition Ast
	DoBranch  []Ast
}

func NewWhile

func NewWhile(condition Ast, doBranch []Ast) *While

type Workflow

type Workflow struct {
	Name      string
	Scenarios Ast
}

func NewWorkflow

func NewWorkflow(name string, scenarios Ast) *Workflow

type WorkflowSymbol

type WorkflowSymbol struct {
	Name       string
	Scenarios  Ast
	ScopeLevel int
}

func NewWorkflowSymbol

func NewWorkflowSymbol(name string) *WorkflowSymbol

func (*WorkflowSymbol) String

func (s *WorkflowSymbol) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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