String literals
Hybrix represents text as strings made of characters. A character is a single letter or digit or punctuation mark or graphical glyph. Each character is represented by a single byte, forming an array of bytes. The system definition for STRING therefore looks like this:
TYPE STRING IS BYTE[]
Recall that a BYTE is an integer number between 0 and 255. Hybrix provides a standard mapping of characters for each number, called HASCII. It is based on the ASCII (American Standard Code for Information Interchange) and ISO/IEC 8859-1 standards, but with some differences for control characters and graphical glyphs.
NOTE: Some programming languages use a zero byte to indicate the end of the string, however this is NOT needed in Hybrix, because arrays already track their size.
Escape sequences
Hybrix text strings are enclosed in double quotes, for example:
MODULE MAIN
FUNC START()
VAR S: STRING
"HELLO, WORLD!" --> S
END FUNC
END MODULE
Using your keyboard, it can be difficult to type certain characters such as ¢ or ★. Control codes such as green or clear screen do not have a standard glyph that we can show in the code. To handle these cases, string literals can include escape sequences enclosed in { } curly braces.
For example:
MODULE MAIN
FUNC START()
VAR S: STRING
CONSOLE::INIT()
"{STAR} THE COST IS 50{CENT}" --> S
# THE PRINTED OUTPUT WILL LOOK LIKE:
#
# ★ THE COST IS 50¢
#
CONSOLE::PRINT(S)
# SKIP TWO LINES
CONSOLE::PRINT("{N}{N}")
# THE PRINTED OUTPUT WILL LOOK LIKE:
#
# THIS "WORD" IS IN QUOTES
#
CONSOLE::PRINT("THIS {QUOTE}WORD{QUOTE} IS IN QUOTES")
END FUNC
END MODULE
You can also escape any character by using its hex value. For example, "{$41}{$42}{$43}" is equivalent to "ABC".
The full list of escape sequences can be found in the HASCII table reference sheet.