VeryBASIC

From TheAlmightyGuru
Jump to: navigation, search

VeryBASIC is a version of the BASIC computer language I've been designing with the hope of eventually programming it. The goal is to expand on the original BASIC formula by adding a lot of additional commands and features that aren't part of the original specifications, but are often desired by programmers. For example, there are great modern BASIC adaptions like FreeBASIC, however, they were meant primarily to allow simple porting of QuickBASIC to 32 and 64-bit operating systems, and only extend the language a little relying on libraries from other languages to advance it further. VeryBASIC is meant to expand on the language to give it a lot of new built-in commands and features, putting it more in-line with the functionality of modern languages.

Variables

Variables can optionally be defined with a value. Constants must be defined with a value, but that value may be a variable. Variables can be manually cleared.

  • Var [static] [global] [type] name [= value] - Used to define a variable.
  • Const [global] type name = value - Used to define a variable whose value, once set, can never change.
  • Clear - Clears the specified variable from memory.

Allocation

By default, variables are allocated automatically, but they can be allocated as static. Constants are always static.

Scope

By default, variables are scoped locally, but can be scoped globally.

Pointers

All variables can be accessed by their memory pointer.

Numericals

Integers

All integers are signed by default, but can be declared as unsigned. All 16-bit or higher integers use the endianess of their native platform, but can be defined differently.

  • Byte - 8-bit integer.
  • Short - 16-bit integer.
  • Integer - 32-bit integer.
  • Long - 64-bit integer.
  • Great - 128-bit integer (if hardware allows).

Floats

  • Single - 32-bit float.
  • Double - 64-bit float.
  • Quad - 128-bit float (if hardware allows).

General

A general number is built more like a string than a binary number. Because of this, you can't perform CPU-level math on it, making calculations particularly slow, but, it can be any size a string can support.

Strings

  • String - 8-bit characters.
  • WString - 16-bit characters.
  • UniString - UTF-8 Unicode characters.

Time

  • Date - A date value stored as signed 32-bit integer.
  • Time - A date and time value stored as a signed 64-bit integer.
  • TimeStamp - A time value with time zone.

Logical

  • Boolean - A true or false value stored as an 8-bit integer.

String Manipulation

StrLeft

result = STRLEFT(source, length, [reverse])

Returns a string containing the leftmost number of characters of the specified string.

  • result - string
  • source - string - The string to read.
  • length - long - The number of characters you wish to read.
  • reverse - boolean - Optional. If true, searches from right to left.

Examples

StrLeft("This is a test.", 7)

"This is"

StrLeft("This is a test.", 7, true)

"a test."

StrSub

result = STRSUB(source, start, [length], [reverse])

Returns a portion of the specified string staring from a position and going to a length.

  • result - string
  • source - string - The string to be read.
  • start - long - The left-most character position of the string to start (1-based).
  • length - long - Optional. The number of characters to return. If not specified, the remaining length of the we returned.
  • reverse - boolean - Optional. If true, searches from right to left.

Examples

StrSub("This is a test.", 6, 4)

"is a"

StrSub("This is a test.", 6)

"is a test."

StrSub("This is a test.", 2, 4, true)

"test"

StrSub("This is a test.", 8, , true)

"This is"

StrReplace

result = REPLACE(source, search, replace)

Replaces all instances of the replace string in the search string.

  • result - string
  • source - string - The string to be read.
  • search - string - The string to search for to be replaced.
  • replace - string - The string with which the search string will be replaced.

Examples

StrReplace("This is a test.", "test", "drill")

"This is a drill."

More

  • StrSplit - Returns an array of the string split on the specified strings.
  • StrReplicate - Returns a string of the replicated character the specified number of times.
  • StrUpper - Returns the string with all lower case letters converted to upper case.
  • StrLower - Returns the string with all upper case letters converted to lower case.
  • StrTrimAll - Removes white space or specified characters from both sides of the string.
  • StrTrim - Removes white space or specified characters from the left side of the string (reversible).
  • StrPad - Adds a specified number of white space or specified characters to the left of the string and returns the result (reversible).
  • StrStuff - Injects the specified string into another at a starting point and returns the result.
  • StrExtract - Returns the extracted string between the specified start and end strings (reversible).
  • StrJoin - Returns a formatted string from an array of strings with the specified delimiter between each element (reverse of split).
  • StrReverse - Returns the reverse of the specified string.
  • StrLength (len) - Returns the length of the string.
  • StrFind - Returns the leftmost position of the sub string within the specified string (reversible).
  • StrOccurs - Returns the number of times the search string occurs in the specified string.
  • StrFormat - Returns the specified string formatted by the format string.

Flow

  • For...Next
  • Do...Loop
  • While...Wend

Conditionals

  • If

Bit Manipulation

  • BitSet - Sets the specified bit of the specified value and returns the result.
  • BitGet - Returns true or false based on the specified bit in the specified value.
  • BitShiftLeft - Shifts the bits left of the specified value and returns the result.
  • BitShiftRight - Shifts the bits right of the specified value and returns the result.
  • BitAnd - Performs a bitwise AND on the specified value with a number and returns the result.
  • BitOr - Performs a bitwise OR on the specified value with a number and returns the result.
  • BitXor - Performs a bitwise XOR on the specified value with a number and returns the result.
  • BitNor - Performs a bitwise NOR on the specified value with a number and returns the result.
  • BitXnor - Performs a bitwise XNOR on the specified value with a number and returns the result.
  • BitNand - Performs a bitwise NAND on the specified value with a number and returns the result.