started work on assignment operators
This commit is contained in:
70
README.md
70
README.md
@@ -1,3 +1,71 @@
|
||||
# Plasma
|
||||
|
||||
The Plasma programming language.
|
||||
The Plasma programming language.
|
||||
|
||||
# Syntax Guide
|
||||
## Functions
|
||||
All your logic must be contained in the "main" function, which looks like this:
|
||||
```cpp
|
||||
main = Func(): Int {
|
||||
|
||||
}
|
||||
```
|
||||
This is how you define functions. In this example, "main" is the name of the function, and `Int` is the return type. My function takes no arguments.
|
||||
If I wanted to make a function that takes arguments, it might look like this:
|
||||
```cpp
|
||||
add = Func(number1: Int, number2: Int): Int {
|
||||
return number1 + number2
|
||||
}
|
||||
```
|
||||
This is a function that adds two numbers together, here's the same function in Python:
|
||||
```py
|
||||
def add(number1: int, number2: int) -> int:
|
||||
return number1 + number2
|
||||
```
|
||||
|
||||
### Calling Functions
|
||||
To call a function, you type a dollar sign (the $ symbol), then the name of the function, and then you pass any of your arguments inbetween paranthesis, like this:
|
||||
```cpp
|
||||
add = Func(number1: Int, number2: Int): Int {
|
||||
return number1 + number2
|
||||
}
|
||||
...
|
||||
later in my code...
|
||||
...
|
||||
$add(9, 10);
|
||||
```
|
||||
|
||||
Here's a "Hello, World!" program in Plasma:
|
||||
```cpp
|
||||
main = Func(): Int {
|
||||
$print("Hello, World!\n");
|
||||
}
|
||||
```
|
||||
`print` is a builtin function, it's defined in every piece of code you write. It has the same formatting as the `printf` function in C, so if I wanted to print an integer I could do it like so:
|
||||
```cpp
|
||||
$print("%i\n", 123);
|
||||
```
|
||||
|
||||
|
||||
## Variables
|
||||
To create a variable, it's as simple as:
|
||||
```cpp
|
||||
name: Type = value;
|
||||
```
|
||||
|
||||
There are several types in Plasma, which are: `Int`, `Float`, `Bool`, `String`
|
||||
|
||||
Here's another example:
|
||||
```cpp
|
||||
name: String = "bob";
|
||||
age: Int = 23;
|
||||
```
|
||||
|
||||
To change the value of an already defined variable, you just have to provide the name, and then write an equals sign, like this:
|
||||
```cpp
|
||||
-- defining the variable
|
||||
age: Int = 23;
|
||||
|
||||
-- changing it later
|
||||
age = age + 1;
|
||||
```
|
||||
Reference in New Issue
Block a user