RiLOLCODE

From Esolang
Jump to navigation Jump to search

RiLOLCODE is designed by PSTF. It is LOLCODE but even more formal than FLOLCODE by mihai Popa.

Keywords

These are the main keywords. All LOLCODE keywords are written in uppercase.

Code Comment
START WITH [version] In all RiLOLCODE programs, START WITH introduces the program and specifies the version (although it isn't used yet).
P.S.: Comment Introduces a single line comment.
#--- Comment

---#

Introduces a multi line comment.
USE [library] Includes a library.
PRINT [string] Prints STRING to the standard output stream. If "INLINELY" is added outside the string, no newline will be printed.
INPUT [var] Reads a string from the standard input stream into the variable.
GET [var] Reads a thing that same as the type of var from the standard input stream into the variable.
DEFINE [var] Declares a variable without a value. Its type will be NIL.
DEFINE [var] AND INITIALIZE IT TO [value] Declares a variable and assigns a value to it.
DEFINE [var] AND SET ITS TYPE TO [type] Declares a variable of the specified type and assigns the initial value of that type to it.
DEFINE AN OBJECT [obj] AND SET ITS TYPE TO THE TYPE OF [other obj] Declares a variable and copies the contents of the other variable into the newly created variable. This is only valid if the other variable is a STRUCT.
SET [var] TO [value] Assigns a value to a variable.
[expression] IS EQUAL TO [expression] Compares two expressions (a variable, a value or another comparison). Returns TRUE if both expressions have the same value.
[expression] IS NOT EQUAL [expression] Compares two expressions (a variable, a value or another comparison). Returns FALSE if both expressions have the same value.
[expression] IS GREATER THAN [expression] Compares two expressions (a variable, a value or another comparison). Returns TRUE if exp1>exp2.
[expression] IS LESS THAN [expression] Compares two expressions (a variable, a value or another comparison). Returns TRUE if exp1<exp2.
[expression] IS GREATER OR EQUAL [expression] Compares two expressions (a variable, a value or another comparison). Returns TRUE if exp1≥exp2.
[expression] IS LESS OR EQUAL [expression] Compares two expressions (a variable, a value or another comparison). Returns TRUE if exp1≤exp2.
MAXIMA IN[expression] AND [expression] Returns the bigger of the two given expressions.
MINIMA IN [expression] AND [expression] Returns the smaller of the two given expressions.
[expression] PLUS [expression] Calculates [expression1] + [expression2]
[expression] MINUS [expression] Calculates [expression1] - [expression2]
[expression] MULTIPLY BY [expression] Calculates [expression1] * [expression2]
[expression] INTEGER DIVIDED BY [expression] Calculates [expression1] / [expression2]
[expression] DIVIDED BY [expression] Calculates [expression1] ÷ [expression2]
[expression] MODULO [expression] Calculates [expression1] modulo [expression2]
LINK [argument1] AND [argument2] (AND [argument3] (AND [argument4] ...)) TOGETHER Concatenates the given STRINGs.
FORCIBLY CHANGE THE VALUE OF [expression] TO [type] Explicitly casts the expression to the given type. If the expression is a variable it is not changed. To also change a variable use SET [var] TO (FORCIBLY[var] A [type]).
CHANGE THE TYPE OF [variable] TO [type] FOREVER Explicitly casts a variable to the given type. The value of the variable is changed to the new type. This is equivalent to SET [var] TO (FORCIBLY[var] A [type]).
INTERPRET [var] Interprets a STRING variable as an identifier.
IF [expression] IS TRUE: 
	...SOMECODE
(
OTHERWISE IF [expression2] IS TRUE: 
	...SOMECODE
...
)
OTHERWISE: 
	...SOMECODE
ENDIF
An if statement. If the expression can be evaluated to TRUE (equivalent of true) the IF branch is executed, otherwise the OTHERWISE branch is executed.
SWITCH [expression]
	IF RETURNS [value] THEN
		[code]
	IF RETURNS [value] THEN
		[code]
	DEFAULT
		[code]
	HCTIWS
The SWITCH-statement compares the expression to the values of the RETURNS-THEN-statements. The values must be distinct and literal, i.e. they mustn't contain any variables or expressions which have to be evaluated at runtime. The RETURNTHEN block can be followed by any number of statements and can be terminated with BREAK. If an RETURNTHEN-block is not terminated with BREAK the next RETURNTHEN will be executed too, regardless of the comparison value. The default case (DEFAULT) is executed when no value matches the expression.
LOOP THE CODES FOR x TIMES:
	code
ENDLOOP.
Do the code for x times.
LOOP THE CODES UNTIL [expr] IS TRUE:
	code
ENDLOOP.
Do the code until expr returns TRUE.
LOOP THE CODES UNTIL [expr] IS NOT TRUE:
	code
ENDLOOP.
Do the code until expr returns FALSE. BREAK can break the loops.
END END terminates the program.

Types

VOID

The VOID type is an empty type that undefined. It is the most basic type when defining variables. It can be converted to a boolean value and return FALSE, or an integer value and return zero.

BOOLEAN

A BOOLEAN is a logical variable that has both TRUE and FALSE properties (either TRUE or FALSE). 0, 0.0000000000, 0j, empty strings, NUL characters(its ASCII is zero), empty lists, empty tuples, empty dictionaries, empty objects (meaning objects that only have __init__ methods, and the only way is an empty function), and blank variables will all return FALSE. All other values return TRUE. The initialized value is FALSE.

Numeric Variable

INTEGER

In this programming language, there is no upper and lower bound for integer types. This is the default integer type. The short integer type is from -32768 to 32767. The medium integer type is from -2147483648 to 2147483647, just like the int type in C++. The long integer type is from -9223372036854775808 to 9223372036854775807. There are also longer integer types, which are equivalent to __int128 types in C++. The initialized value is 0.

FLOAT

Like integer types, decimal types have no upper and lower bounds. The upper and lower bounds of a single-precision decimal type are equal to the upper and lower bounds of medium integers, and there are 6 to 7 significant decimal places. The upper and lower limits of the double decimal type are equal to the upper and lower limits of the long integer type, and the effective decimal places have reached 13 to 14 digits. There are also even more bizarre types of long double-precision decimals, with upper and lower bounds equal to those of 128-bit long integer types, with 20 to 21 significant decimal places. The initialized value is 0.0 .

COMPLEX

A complex number consists of its real and imaginary parts, usually in the form m+nj. If you only want to express imaginary numbers, omit m+. If you want to express the imaginary number 1, just use j. The initialized value is 0+0j.

What they all have in common

If you converts 0, 0.0000000000000000000000000000000000, 0.0, 0+0j, 0j to BOOLEAN, you will get a FALSE, otherwise you will get a TRUE. When you try to convert BOOLEAN to INTEGER, FLOAT or COMPLEX, it will be:

  1. FALSE to INTEGER: 0
  2. FALSE to FLOAT: 0.0
  3. FALSE to COMPLEX: 0+0j
  4. TRUE to INTEGER: 1
  5. TRUE to FLOAT: 1.0
  6. TRUE to COMPLEX: 1+j

CHARACTER

Variables of character type are enclosed by single quotation marks. Its value range is limited to 256 characters in ASCII. There is also a double-byte character type, which is equivalent to the wchar_t of C++, and supports plane 0 of the entire Unicode.

STRING

A string, as the name suggests, is made up of many characters. Both the string type and the character type support escaping characters, which are escaped by backslashes. In particular, lowercase n means new, lowercase t means horizontal tab, lowercase a means character 7 (BEL character), lowercase b means character 127 (DEL character), the number zero represents character 0 (NUL character), uppercase Q means double-quote, lowercase q means single-quote, variable wrap in a brace means output this variable(Only support by f string).

The STRING can only convert to INTEGER or FLOAT, such as, "24" to be 24, "53.2" to be 53.2, but "0x10" to be an error instead of 16.

  1. \n ---- newline
  2. \t ---- horizontal tabulation
  3. \b ---- backspace
  4. \a ---- alarm
  5. \0 ---- NULL
  6. \x[hhhh] ---- Hexadecimal character
  7. \[ddddd] ---- Decimal character
  8. {var} ---- output the variable
  9. \Q ---- double quote
  10. \q ---- single quote
  11. \N[character name] ---- output the character named [character name]. For example, Cyrillic capital letter El outputs Л, Sinhala letter Kantaja Naasikyaya outputs ඞ, CJKV Unified Ideogram 0x3400 outputs 㐀, and so on.
  12. \v ---- vertical tabulation

Functions

Functions are defined by the following commands:

DEFINE A FUNCTION NAMED YourFunctionName. THE FOLLOWING ARGUMENTS ARE ACCEPTED: *args, **kwargs
{
    EXEGESIS: CodeCodeCodeCodeCodeCodeCodeCodeCodeCodeCodeCodeCodeCodeCodeCodeCodeCodeCodeCode
}

BITSET

A bitset is a serie of bits.

Objects

Objects are defined by the following commands:

DEFINE A CLASS NAMED YourClassName.
{
    EXEGESIS: Define an attribute in the object.
    DECLARE AN ATTRIBUTE attr_1 AND SET ITS TYPE TO INTEGER
    
    EXEGESIS: Define some inits in the object.
    DEFINE A INIT NAMED __init__. THE FOLLOWING ARGUMENTS ARE ACCEPTED: SELF
    {
        EXEGESIS: CodeCodeCodeCodeCodeCodeCodeCodeCodeCodeCodeCodeCodeCodeCodeCodeCodeCodeCodeCode
    }
    DEFINE A INIT NAMED func1. THE FOLLOWING ARGUMENTS ARE ACCEPTED: SELF
    {
        EXEGESIS: CodeCodeCodeCodeCodeCodeCodeCodeCodeCodeCodeCodeCodeCodeCodeCodeCodeCodeCodeCode
    }
}

A variable inside an OBJECT can be used with [object_name].[variable_name].

A function inside an OBJECT can be used with [object_name].[function_name]((self), *args, **kwargs).

Definition of constants

Constants are defined by the following commands:

DECLARE A CONSTANT [const]

Examples

Determine how many "1" bits there are in a binary number

START WITH 1.0
DEFINE 啷 AND SET ITS TYPE TO BITSET<8>
GET 啷
DEFINE w AND INITIALIZE IT TO 0
LOOP THE CODES FOR (I IN RANGE(0, 7)) TIMES:
	IF 啷[I].POSITIVE IS TRUE:
		INCREASES w
	OTHERWISE:
		PASS
	ENDIF
ENDLOOP.
PRINT (FORCIBLY CHANGE THE VALUE OF w TO STRING)

Categories