BubbleLang
BubbleLang is designed by PSTF.
Name
I don't know why, but I like this name because I like the shape of circle and sphere.
Sources of inspiration
I let my 文心一言 to generate an Esolang, and I inspired from that.
I'm also inspired from Python and C++.
Syntax
Basic Commands
CMD | Meaning |
---|---|
print(*args(, end='\n')) |
Print something with the end symbol. If you didn't define the end symbol, then it will end with \n. |
input(__prompt) |
This didn't be an isolated command. Get user input and then assign to a variable. The prompt of input will be __prompt. Every input occupies one line. Inputed things will store into a string. |
var name(: type) (= value) |
This defines a variable called name and assign value to it. If you omitted the type, then you must assign something to the variable. If you ommited the value, then you must indicates its type. |
var = value |
Simple Variable Assign. |
type(var) |
Change the variable to the "type". |
# |
Inline comment. |
from lib import module_name |
Import module_name from lib. Use * replace module_name to import everything. |
Advanced commands
Multiline comment
<? This is a comment, any text goes here Bla bla bla Lorem ipsum dolor sit amet, consectetur adipiscing elit. The quick brown fox jumps over the lazy dog. 山不在高,有仙则名。 Nested annotations are allowed in this programming language, but it is not recommended! ?>
Conditional statement
if expr1: code1 ( elif expr2: code2 elif... elif exprN: codeN else codeSUCC_N )
Bracketed things can be omitted.
An if-elif-else statement can has 114514 "elif"-s, but can only has ONE "else".
Both of elif and else must pair with if.
Function defination
function your_function_name(*args, **kwargs): somecode (return (somereturnvalues))
Object defination
class your_class_name var attr_1: type function __init__(self): initialization funtion func1(self, *args, **kwargs): code var object: your_class_name
Types
nil
This type is the blank type. When you want to define a blank variable, you can use this.
bool
A logical value which has only 2 states: True and False.
Every zero-value(such as 0, 0.0, 0j, "", [], {}) will return False, otherwise return True.
False will convert to 0, and True will convert to 1.
Numeric Variables
int
Simply an integer, range is ℤ.
float
Simply a decimal, range is ℝ.
comp
Simply a complex number, range is ℂ.
Format: real+imagj
Character variables
char
A single character. It is quoted by single quotation mark.
str
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).
- \n ---- newline
- \t ---- horizontal tabulation
- \b ---- backspace
- \a ---- alarm
- \0 ---- NULL
- \x[hhhh] ---- Hexadecimal character
- \[ddddd] ---- Decimal character
- {var} ---- output the variable
- \Q ---- double quote
- \q ---- single quote
- \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.
You can also add f in front of the string to make a formatted string.
When you try to int-ize a string, then you'll get the integer that is the string, except there are something invalid for integer.
Multiline String
Multiline String is quoted by sextuple quote("""). It didn't need the escape character.
Constants
They're defined by const name = value
. Once they're defined, they can't change unless delete it then redefine it.
Pointer
Add asterisk after the type.
Hexadecimal, Octal and Binary
Use X(xxxx)16, O(oooo)8, B(bbbb)2.
Loop
forloop
for element in list: code
whileloop
while expr: code
Error Handle
try: Code_that_may_throw_an_error except Exception: Code1 ( else: Code2 finally: Code3 )
Exception | Causing |
---|---|
SyntaxError |
Syntax is not standardized |
NameError |
Referenced on an undefined thing |
TypeError |
An incompatible method that works for another type is used for a variable of one type |
CalculationError |
Division with a divisor of 0, functions that use out-of-range parameters (e.g., arcsin(2)) |
ValueError |
The value passed in may be invalid or illegal |
FileError |
Trying to read the file that didn't there |
Example
More examples are available at /Algorithm and /Examples.
Hello, world!
print("Hello, world!")
A+B Problem
var a = input() var b = input() a = int(a) b = int(b) var c: int c = a + b print(c)
Truth Machine
<? This is the Truth Machine. It requires a programming language that can input, output, judge, terminate, and loop. Generally speaking, if a programming language can write a the Truth Machine, it can already be a TCPL. ?> var a = input() a = bool(int(a)) if a: while a: print("1\n") print("0")
Disan Count 2.0
<? This is the Disan Count. It requires a programming language that can input, output, judge, arithmetic, and loop. Generally speaking, if a programming language can write a the Disan Count, it can already be a TCPL. ?> var a = input() a = int(a) for i in range(1, a + 1, 1): if i % 2 == 0: print(f"{i} is even!") else: print(f"{i} is odd!")
Fixed Repeating Output
var a = input() a = int(a) for i in range(1, a + 1): print("1") print("0")