STK Commands - Comprehensive Guide

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > Arrays and Data-Structures > STK. - Stack >

STK Commands - Comprehensive Guide

STK Commands

Previous Top Next


MiniRobotLanguage (MRL)

 

STK Commands

Complete List of Stack Operations

 

 

Intention

 

The STK commands provide a comprehensive set of tools for working with stacks in the MiniRobotLanguage (MRL). Stacks are a Last-In-First-Out (LIFO) data structure, where the last element added is the first one to be removed. These commands allow you to create, manipulate, and manage stacks efficiently.

 

 

Basic Concepts

 

Stack Handle: A stack is accessed using a handle, which is a unique identifier returned by STK.New or STK.Clone.

Data Types: Stacks can store three types of data: strings (s), integers (i), and floating-point numbers (f).

Top of Stack (TOS): The most recently added element is referred to as the Top of Stack (TOS). Most operations, such as STK.Push and STK.Pop, work with the TOS.

 

 

Command List

 

STK.New: Allocates a new stack and returns its handle.

STK.New|$$STK[|s/i/f]

STK.End: Frees the allocated stack and returns null.

STK.End|$$STK

STK.Validate: Checks if the stack handle is valid.

STK.Validate|$$STK[|$$RET]

STK.Clear: Deletes all data in the stack.

STK.Clear|$$STK

STK.Count: Returns the number of items in the stack.

STK.Count|$$STK[|$$CNT]

STK.Push: Adds a value to the top of the stack.

STK.Push|$$STK|$$VAL

STK.Peek: Returns the top value without removing it.

STK.Peek|$$STK[|$$RET]

STK.Pop: Removes and returns the top value from the stack.

STK.Pop|$$STK[|$$RET]

STK.Import: Imports a string into the stack using a delimiter.

STK.Import|$$STK|$$STR[|$$DEL]

STK.Export: Exports the stack as a string using a delimiter.

STK.Export|$$STK|$$DEL[|$$STR]

STK.GetType: Returns the data type of the stack.

STK.GetType|$$STK[|$$TYP]

STK.Reverse: Reverses the order of elements in the stack.

STK.Reverse|$$STK

STK.Rotate: Rotates the top $$ANZ elements on the stack.

STK.Rotate|$$STK[|$$ANZ]

STK.InvRotate: Performs an inverse rotation of the top $$ANZ elements.

STK.InvRotate|$$STK[|$$ANZ]

STK.Add: Adds the top $$NUM elements and pushes the result onto the stack.

STK.Add|$$STK[|$$NUM]

STK.Dup: Duplicates the top element $$NUM times.

STK.Dup|$$STK[|$$NUM]

STK.Swap: Swaps the top two elements on the stack.

STK.Swap|$$STK

STK.Clone: Creates a copy of the stack and returns its handle.

STK.Clone|$$STK[|$$CLN]

STK.Swapx: Swaps elements at positions $$ELA and $$ELB.

STK.Swapx|$$STK[|$$ELA][|$$ELB]

STK.Show: Displays the stack contents in a console window.

STK.Show|$$STK

 

 

Data Types

 

1 - String: Text data type.

2 - Integer (Quad): 64-bit integer data type.

3 - Extended (Floating point): Floating-point data type.

 

 

Example

 

'***********************************

' STK Operations - Sample Script

'***********************************

' Create a new stack

STK.New|$$STK|s

' Push values onto the stack

STK.Push|$$STK|Hello

STK.Push|$$STK|World

' Peek at the top value

STK.Peek|$$STK|$$RES

DBP.$$RES

' Pop the top value

STK.Pop|$$STK|$$RES

DBP.$$RES

' Display the stack contents

STK.Show|$$STK

' End the script

ENR.

 

 

Remarks

 

-

 

 

Limitations:

- Ensure the stack is not empty before performing operations like STK.Pop or STK.Peek.

 

See also:

 

STK.New

STK.Clone

STK.End