Array - Commands

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > Arrays and Data-Structures > Array -Commands > !FP-Arrays >

Array - Commands

ARR.Parse FP

Previous Top Next


MiniRobotLanguage (MRL)

 

ARR.Parse FP

Parse a String into a Floating-Point Array Using a Delimiter

 

 

Split a source string into floating-point array elements based on a specified or default delimiter.

 

Intention

The ARR.Parse FP command splits a source string (P2) into elements and stores them as extended-precision floating-point numbers (10 bytes, 18 digits of precision) in a specified floating-point array (P1) using a delimiter (P3). If the delimiter is omitted, a comma (",") is used by default. The command is ideal for processing delimited numeric data, such as lists of floating-point values, into an array for tasks like scientific calculations or data processing. The number of successfully parsed elements is returned on the Top of Stack (TOS). Internally, values are stored as strings, consistent with MRL’s array storage mechanism.

Array Number: The array is specified by a number (0–32), which is modified in-place with the parsed floating-point elements.

Delimiter: A string that separates elements in the source string. Defaults to "," if omitted or empty.

Floating-Point Validation: Each element must be a valid floating-point number; non-numeric values are skipped.

Return Value: The number of valid floating-point elements parsed is pushed to the TOS.

Binary Safety: The command is binary-safe for the source string and delimiter, handling special characters or null bytes.

 

Schematic (Floating-Point Array Parsing)

Source String: 3.14,2.718,-1.23

Command: ARR.Parse FP|1|3.14,2.718,-1.23|,

Result Array[1]: ["3.14", "2.718", "-1.23"]

TOS: 3 (number of valid floating-point numbers parsed)

 

Syntax

ARR.Parse FP|P1|P2[|P3]

 

Parameter Explanation

 

P1 - Array Number: Specifies the floating-point array number (0–32) to store the parsed elements. Resolved to an integer.

P2 - Source String: The string containing delimited floating-point values. Can be a variable or literal.

P3 - Delimiter (Optional): The string used to split P2. Defaults to "," if omitted or empty.

 

Speed in Ticks:

This command typically uses between 200 to 400 ticks, depending on the string length and number of elements parsed.

 

Examples

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

' Example 1: Parse with default delimiter

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

VAR.$$SRC=3.14,2.718,-1.23

ARR.Parse FP|1|$$SRC

' Array 1 contains: ["3.14", "2.718", "-1.23"]

ARR.Get FP Array|1|1|$$RET

MBX.$$RET

ENR.

 

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

' Example 2: Parse with custom delimiter

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

VAR.$$SRC=1.5;2.0;3.14159

ARR.Parse FP|2|$$SRC|;

' Array 2 contains: ["1.5", "2.0", "3.14159"]

ARR.Get FP Array|2|2|$$RET

MBX.$$RET

ENR.

 

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

' Example 3: Parse empty string

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

VAR.$$SRC=

ARR.Parse FP|3|$$SRC

' Array 3 contains: []

POP.$$CNT

MBX.$$CNT

ENR.

 

'============================================================

' SELF-VALIDATING TEST SCRIPT for ARR.Parse FP

' Purpose: Verify functionality with JIV. for automated checks.

' Tests default delimiter, custom delimiter, empty string, invalid parameters, and non-numeric values.

'============================================================

' Initialize counters

$$PAS=0

$$FAI=0

STS.CLEAR

PRT. ===================================================

PRT. Test 1.1: Parse with default delimiter

STS.CLEAR

ARR.Clr|1

VAR.$$SRC=3.14,2.718,-1.23

ARR.Parse FP|1|$$SRC

ARR.Get FP Array|1|1|$$RET

$$EXP=2.718

JIV.$$RET!$$EXP|Lab_Error1

PRT. -> PASS

VIC.$$PAS

JMP.Lab_Next1

:Lab_Error1

GSB.Test

'-----------------------------------------------------------

:Lab_Next1

PRT. Test 1.2: Parse with custom delimiter

STS.CLEAR

ARR.Clr|2

VAR.$$SRC=1.5;2.0;3.14159

ARR.Parse FP|2|$$SRC|;

ARR.Get FP Array|2|2|$$RET

$$EXP=3.14159

JIV.$$RET!$$EXP|Lab_Error2

PRT. -> PASS

VIC.$$PAS

JMP.Lab_Next2

:Lab_Error2

GSB.Test

'-----------------------------------------------------------

:Lab_Next2

PRT. Test 1.3: Parse empty string

STS.CLEAR

ARR.Clr|3

VAR.$$SRC=

ARR.Parse FP|3|$$SRC

POP.$$CNT

$$EXP=0

JIV.$$CNT!$$EXP|Lab_Error3

PRT. -> PASS

VIC.$$PAS

JMP.Lab_Next3

:Lab_Error3

GSB.Test

'-----------------------------------------------------------

:Lab_Next3

PRT. Test 1.4: Invalid array number (negative)

STS.CLEAR

ARR.Clr|4

VAR.$$SRC=1.5,2.0

ARR.Parse FP|-1|$$SRC

ARR.Get FP Array|4|0|$$RET

$$EXP=

JIV.$$RET!$$EXP|Lab_Error4

PRT. -> PASS

VIC.$$PAS

JMP.Lab_Next4

:Lab_Error4

GSB.Test

'-----------------------------------------------------------

:Lab_Next4

PRT. Test 1.5: Invalid parameter count (too few)

STS.CLEAR

ARR.Clr|5

ARR.Parse FP|5

ARR.Get FP Array|5|0|$$RET

$$EXP=

JIV.$$RET!$$EXP|Lab_Error5

PRT. -> PASS

VIC.$$PAS

JMP.Lab_Next5

:Lab_Error5

GSB.Test

'-----------------------------------------------------------

:Lab_Next5

PRT. Test 1.6: Non-numeric values

STS.CLEAR

ARR.Clr|6

VAR.$$SRC=3.14,abc,2.718

ARR.Parse FP|6|$$SRC

ARR.Get FP Array|6|1|$$RET

$$EXP=2.718

JIV.$$RET!$$EXP|Lab_Error6

PRT. -> PASS

VIC.$$PAS

JMP.Lab_Next6

:Lab_Error6

GSB.Test

:Lab_Next6

PRT. ===================================================

PRT. TEST SUMMARY

PRT. ===================================================

CAL.$$TOT=$$PAS+$$FAI

$$MSG=Total Tests: $$TOT

PRT.$$MSG

$$MSG=Passed: $$PAS

PRT.$$MSG

$$MSG=Failed: $$FAI

PRT.$$MSG

JIV.$$FAI=0|Lab_Success

$$MSG=FAILURE: $$FAI of $$TOT tests failed.

MBX.$$MSG|Test Result|16

JMP.Lab_End

:Lab_Success

MBX.SUCCESS: All tests passed!|Test Result|64

:Lab_End

ENR.

:Test

$$MSG= -> FAIL - Result: $$RET (exp: $$EXP)

PRT.$$MSG

VIC.$$FAI

RET.

 

 

Remarks

- The command is binary-safe, handling special characters or null bytes in the source string or delimiter.

- P1 is resolved to an integer; non-integer values are rounded down.

- If P3 is empty or omitted, the default comma (",") is used as the delimiter.

- Non-numeric elements in the source string are skipped, and the TOS reflects only valid floating-point elements parsed.

- The array is cleared before parsing, ensuring no residual elements remain.

 

Limitations

- Array numbers are limited to 0–32, consistent with other MRL array commands.

- Invalid array numbers (e.g., negative or >32) result in no operation.

- Requires 2 or 3 parameters; fewer or more parameters result in no operation.

- Non-numeric values in the source string are skipped, potentially reducing the number of elements parsed.

- No support for multidimensional arrays or complex parsing patterns.

 

See also:

    Set FP Array

    Get FP Array

    Clm Array

    Clr Array

    Dim Array

    Parse

    Unpack Array from Var