A simple interpreted programming language. The reason behind the name is the language's methodology, "One step at a time". Lots of things that would be one line in other languages are seperated into multiple lines for clarity. There should only be one operation, or something happening, per line, although technically there can be more. Also, Slug has a lot less characters used for proccesses, like declaring a variable. For example, int num 5
is used instead of int num = 5
, as the equal sign is assumed.
Take a look at some Examples
I released a slug extension on the VSCode marketplace for syntax hilighting. So far it is updated for version 1.0. To find it, just search SLUG in the extensions searchbar.
A brief overview on how to use the slug programming language
Declaring variables is technically calling a function, but I will seperate it for clarity. There are three base datatypes in Slug, int
, float
, and string
.
int
is used for whole numbers, or integers.
float
is used for numbers with fractional components.
string
is used for words or letters.
Here is the code used to declare these three datatypes.
There is another, more complicated datatype to declare, the bool
. Intead of passing in true or false as most other languages, there is a different way of doing it in slug. First, you pass in the name of the bool
, Next, you put in the first value/variable to be compared. Then, you put in the boolean operator, like ==
or >
. Lastly you put in the second value/variable to be compared. Here is an example.
bool myBool 3 > 0
print
is the function that outputs to the console. It can either output a string literal, an int
, a float
, and a string
. It does not add a newline after what you give it.
println
is the same as print but it adds a newline at the end.
Output: Hello World! (With a newline)
printf
is the preferred way of outputting to the console. It takes in a varied amount of arguments, and prints them.
For getting user input, there are three main functions. readInt
, readFloat
, and readStr
. These are pretty self-explanatory, so I won't go in depth. These functions take input in the forms of the three main datatypes. The only parameter they take is the name of the variable to put the input in.
Next are the main conditional functions if
, elseif
, else
. They are basically the same as other languages, but they are technically functions. They take one parameter, a boolean operation. To tell what is under the if statements, the slug language uses 4 spaces for indentation, like a tab in python.
An example of a full if statement is in Examples.
Here is an example program that greets the user.
The first line starts with a hashtag/octothorpe. This indicates a comment, similar to python.
Then, a line is printed with a newline at the end using the println
function. This takes in a string literal or a variable.
Next, the program takes input in the form of a string using the readStr
function. This puts the user input into the string var specified.
Finally, the printf
statement is used to output the string literal "Hi "
then the variable name
, and finally the string literal "!"
.
File:
Variables do not have to be declared before use. This is because of how variables are stored in the interpreter.
The interpreter uses a map that uses a std::string
key and whatever type the dev specifies as the value type. So whenever the developer sets a variable, the value in the dictionary corresponding to the key (variable name) is set to the value the dev provides. This way, all variables are global, but I might change this later.
Here is an example of an if statement.
First, the program declares an int
called age
. Although unneccesary, this shows how to properly declare a variable in slug. Then the program prompts the user for their age, which is stored in the variable age
. Then, two bools are created for the if statements in the program. The first, over18
is the bool that represents if the user is >= 18 years old. Secondly, the bool
is17
tells if the user is 17 years old. Then the program moves onto the if statements. If over18
is true, then the user is prompted to vote for either apples or cheese. Their input is tested into bools that check if they voted for apples or cheese. If they voted apple, the program says. else if they voted for cheese, the program says. If over18
is false and is17
is true (elseif), It says "So close". Else, it says they are too young.