Docs

Hello! If you are reading this, this is a special file designed for those who:

Lucky for you, you are in the right place! This also gives documentation for this version, just so you know how everything works.

Part One: Documentation

Of course, if we want to know how Pencilscript works in the inside, we have to know how it works on the outside

Commands:

Write:

The write command is simple. Write text to the terminal. It is similar to python's print() command, Javascript's console.log(), or PHP's echo. Its syntax is:

write "Hello world!"
write 'variable'
write 0011101000101001

Error:

The error command writes to the terminal as well, except in an error.

error "Custom Error: 1 + 1 is actually 11."
error 'err'
error 011011100110111100100001

Ask:

The ask command is the exact opposite of the write command. It gets input from the user. Similar to python's input() command or Node.js' question() method. Its syntax is:

ask "Question"
ask 'query'
ask 00111111

You may also add and save it in after to save the input to a variable.

Clear:

The clear command clears everything from the terminal. It does not accept arguments. Its syntax is:

clear

Wait:

The wait command allows you to pause execution of a Pencilscript program. Its syntax is

wait 1
wait 'time'

Additionally, you may add milliseconds, or its shorthand, ms, seconds, or its shorthand, secs (or sec if the amount of time waited is 1), or minutes, or its shorthand, mins (once again, min if the amount of time waited is 1)

Create:

This command allows you to define something. So far, its only use is for variables. Unlike other coding languages, assigning a value to a variable that doesn't exist does not make a variable. The syntax is:

create var variable

Note: You may just plug the name of the variable in, you do not need to worry about quotes. Additionally, you may add with value to assign a value to a variable on creation. This, however does follow quotation rules.

Delete:

This command allows you to delete a variable. Its syntax is:

delete "variable"
delete 'var'
delete 1

Just to note, when you delete a variable with the name of the contents of a variable (delete 'var' as an example) you are deleting the variable that has the same name as the content of that variable.

Actions

There is a difference between a command and an action. A command is like a structure. It allows you to put actions together to do stuff. Let's take an example.

write 1 + 1

In this scenario, we see write is the command, and 1 + 1 is the action. The command is what does, the action is what it is doing. We also label things like comments an action. After all, it needs to be ignored by the interpreter, and that is something being done. Plus, calling it a command would make not much sense, wouldn't it? Anyhow, the whole point of this section is to describe all the actions in Pencilscript, as of this version. Actions themselves can have 2 different forms. Operators and methods. Operators direct methods or commands into doing specific things. Methods perform specific things based on input. Common structures are:

`command value method`


`command value operator value`


`command value operator value method`

Comment Method:

To leave a comment in Pencilscript, simply start your line with a slash. An example is:

/ `This is a pencilscript comment! Horray!`

Storing Method:

To store a value in a variable (example: x = 1) in Pencilscript, you simply go:

var = "value"

Additon Operator:

The addition operator allows adding numbers or equations together. It is:

write 1 + 1
write 1 + -2 + 1

Subtraction Operator:

The subtraction operator is the opposite of the addition operator, subtracting numbers or equations from eachother. An example is:

write 1 - 1
write 1 - 2 + 1

Multiplication Operator:

The multiplication operator can multiply numbers and equations together such as:

write 2 * 2
write -2 * 5 - 3

Division Operator:

It is the exact opposite of the multiplication operator. It can divide numbers and equations:

write 4 / 2
write 1 / 2 + 4 - 1

Modulo Operator:

The modulo operator works closely with division. It returns the remainder of a division problem, or 0 if there is no remainder.

write 5 % 5

To Uppercase Method:

This method converts a string of alphabetical letters into their uppercase form. It only accepts strings and variables.

write "bro." to uppercase

To Lowercase Method:

This method converts a string of alphabetical letters into their lowercase form. It only accepts strings and variables, just like its opposite.

write "is SHAKESPEARE really Dead?" to lowercase

Reversed Method:

This method converts a string or variable (as of now) into reverse. We plan, eventually, to extend this to arrays, but arrays do not exist in Pencilscript as of now.

ask "reversed" rеversed

Trim Method:

This method removes extra spaces and tabs in front of or behind text.

write " I need a cut! " trimmed

Part 2: Inner Workings

Now that you are aware of how pencilscript works on the outside, it is time to look at it on the inside.

Functions

When you look in the code, you find a few functions. First, there is pError(). This is the error function that Pencilscript uses. It clears the innerText and innerHTML of the terminal, changes the color to red, then throws an error, then returns from it's function. Then, we have a collection of async functions. These are the commands. Note the best way to tell an action from a command is to check its function. An action uses a regular function instead.

The Run Event Listener

This is where the main interpreter is. It is an async event listener, which looks like:

run.addEventListener("click", async function (e) { ... })

Inside is a for loop. It uses the variable i to track it's index.

The For loop

The for loop can be split into 3 main parts. The declarations, identification, and the execution. The declarations are a bunch of variables that are reset to undefined. If they stayed the same, likely some wonky things would happen. The identification is when the command and action is found (refered to as a modifier in the code). It uses a switch case system, and heavily relies on the fact that _Functions are first class citizens,_see functions. The execution is executing that function using the passed in data. We can pass in the variables directly to avoid long switch case chains with code inside them. An example is provided below:

function example(txt) { 
    return txt.toUpperCase() 
    } 
    let x = example 
    console.log(x("input"))

Errors

With great power, comes great responsibility. Instead, comes great amounts of errors.

Type Errors:

When you pass the wrong type into a command:

wait "time"

Syntax Errors:

When you mess up the syntax of a command:

create "time" and check your watch

Interpreter Error:

Probably not your fault, a problem with the interpreter. Report immediately.

I don't have an example for this

Arithmetic Error:

Messing up your math. I thought you learned this in school!

write 1 / 0

String Error:

Messing up string (text) operations instead of math!

write 18 to uppercase