Welcome to Lazylang's documentation, an interpreter built in java, aiming to build a new language. Here you'll find out hout to use Lazylang.
Lazylang's syntax was herded from Java, with blocks of code starting with "{" and ending with "}", also all functions must have their parameters inside parenthesis. Every command that doesn't start a new block of code must end with ";", strings must be between " " and chars between ' '.
The language has 6 data types and one pseudo data type, those being: integer(int), floating point number(float), boolean(bool), vector(vector), string(str), character(char) and automatic (auto), and they are used in variable declarations.
This data type definition will try to deduce which type the user wants to use.
auto variable;
They are the positive and negative numbers without floating point, and they must be declared using:
int variable;
they can also receive an value at declaration, e.g.:
int variable = 5;
They are the positive and negative numbers with floating point, and they must be declared using:
float variable;
they can also receive an value at declaration, e.g.:
float variable = 5.0;
They are the boolean values true and false, and they must be declared using:
bool variable;
they can also receive an value at declaration, e.g.:
bool variable = true;
A vector is a list type, and there's no need to specify the container type at creation time, i.e., it accepts different data types in the same vector, and they must be declared using:
vector v;
Vectors have the built in functions:
Appends elements to the end of the vector. The parameter between parenthesis is the element being added.
v.append(5);
Retrieves a copy of the vector.
v.copy();
Returns what's at the specified position. Can be replaced using the brackets [] operator.
Take a vector with 2 positions, [1,3]:
v.get(0);
Output
1
v[1];
Output
3
Removes the element at the given position:
v.pop(0);
If nothing's passed, it removes the last element:
v.pop();
Clears the vector's elements:
v.clear();
Adds an element to a specific position, the position is the first parameter, and the element to be inserted is the second parameter:
v.insert(2,"abc");
Searches the vector counting the occurences of a element given as the parameter:
v.count(2);
Special variables of a single character, and it must be between ' '. They must be declared using:
char variable;
they can also receive an value at declaration, e.g.:
char variable = 'c';
They are sequences of characters, that must be between " ". They must be declared using:
str variavel;
they can also receive an value at declaration, e.g.:
str variable = "string";
Despite being a basic language, Lazylang has everything that's necessary to the programmer: conditional blocks, loops, and input/output.
Lazylang has logical, arithmetic, comparison and cast operators.
Operator | Function |
---|---|
% | modulo |
/ | division |
* | multiplication |
+ | addition |
- | subtraction |
Operator | Function |
---|---|
! | Not |
&& | And |
|| | Or |
Operator | Function |
---|---|
== | equal |
<= | lesser/equal |
>= | greater/equal |
< | lesser |
> | greater |
!= | not equal |
Forces a data type to become another data type. casts exists for int, float and bool.
int(variavel);
float(variavel);
bool(variavel);
Operators have the following precedence order, 1 being the highest and 7 the lowest.
Operator | Precedence |
---|---|
% | 1 |
/ | 1 |
* | 1 |
+ | 2 |
- | 2 |
== | 3 |
<= | 3 |
>= | 3 |
< | 3 |
> | 3 |
!= | 3 |
! | 4 |
&& | 5 |
|| | 6 |
= | 7 |
+= | 7 |
-= | 7 |
*= | 7 |
/= | 7 |
%= | 7 |
Conditional structures on lazylang are basically the same as in java, being:
The function receives a condition as the parameter, and if the condition is true, the block of code will be executed, else, the block will be ignored. The function has the following syntax:
if(condition) {
command;
command;
}
Working similarly to if, the elif block takes a condition, and if it's true, the whole block will be executed. The elif block can only be used after an "if", and will only be executed if the preceding conditional was false. The function has the following syntax:
elif(condition) {
command;
command;
}
Just like elif, the else block needs to have a preceding conditional, and it needs to be false, but else doesn't need a condition, i.e., it executes the block if the preceding condition was false. The function has the following syntax:
else {
command;
command;
}
Lazylang has two looping structures, for and while.
The loop has the following syntax:
for(int i = 0;i <= 10;i += 1){
comando;
comando;
}
Inside the parenthesis we have the loop conditions, the first being the beggining assignment, defined as:
int i = 0;
The second one is the end condition,
i <= 10;
The third one is the loop step assignment:
i += 1
While loops work only with a conditional on its argument.
The loop has the following syntax:
int a = 0;
while(a < 10){
a += 1;
}
The loop will repeat until the condition tests false.
Lazylang has input and output commands:
For output, lazylang has print and println.
Outputs to stdout the elements passed as parameters. Print doesn't automaticly line break. Separators are spaces.
The syntax is as follows:
print(variable);
or
print("message1","message 2");
Outputs to stdout just like print, but println does a line break at the end.
The syntax is as follows:
println(variable);
or
println("message1","message 2");
For input, we have input, readInt, readFloat and readBool.
Used to input strings from stdin. Optional parameter is a message to be printed:
variable = input();
Used to input integers from stdin. Optional parameter is a message to be printed:
variable = readInt();
Used to input floating point numbers from stdin. Optional parameter is a message to be printed:
variable = readFloat();
Used to input booleans from stdin. Optional parameter is a message to be printed:
variable = readBool();