Guides

 

Here is a quick rundown of Ophidian's grammar. This page does not cover all of Ophidian's features but you can learn more on the official documentation

WRITE TO THE OUTPUT:
Usage:  WRITE(arg)

The  WRITE() method  is  a  built  in function in Ophidian that allows users to "write" something to an output.

 

Example:  WRITE("Hello  World!")

Output: Hello World

Example: WRITE(3)

Output: 3


CREATING A VARIABLE:

Usage: VAR <name> = <value>

The  VAR keyword is a reserved word in Ophidian that lets the program know that you are declaring a variable. <name> is the variable's name or identifier that is used to reference the variable. 

Variables in programming are very similar to variables in math. The = is the 'assignment operator' which lets the program know that you are assigning a value to the variable.  <value> is the value that you assign to the variable and can be a String, Number, or a List object. 


Example:  VAR x = 2

Value of x: 2

Example: VAR x = "hello"

Value of x: "hello"

Example 

VAR x = 2

VAR y = 2

WRITE(x + y)

Output: 4


STRING METHODS:

The 'String' object in Ophidian can be manipulated in various ways. Using a + operator can add (concatenate) 2 or more strings together.

Example:  WRITE("Hello " + "World!")

Output: Hello World!


The built-in function INDEX_OF() takes in 2 arguments, INDEX_OF(String, int) and will return the character at the corresponding index value of the String. 

Example:  INDEX_OF("Hello", 0)

Returns: H


What is an index value? An index value is just a term used to refer to a position of a character in a string. In the example above, the index value of "H" is 0 and the index value of "e" is 1 and so on and so forth. 

The reason why the index of "H" is 0 is because computers begin counting from 0 so the position of "H" is the 0th index.

Example: "World"

Index at 0 = W | Index at 1 = o | Index at 2 = r | Index at 3 = l | Index at 4 = d |


CREATING A FUNCTION:

Usage (Multiline functions)

CREATE FUNCTION <name>(arguments)

END


What is a function? A function is just a collection of code organized under a name, similar to variables. A function also takes in values known as arguments and these arguments are passed in order. It sounds complicated to explain but there will be a few examples down below later. First, let's get started on how to create a function. In order to create a function, you must first use the keyword CREATE followed by the keyword FUNCTION

After that, create a name for the function which serves as its identifier and you can reference that name later in order to "call" the function. Right after the name, create a pair of parenthesis "()" and inside you can list the values that can be passed in known as "parameters" separated by commas. 

 

Example: CREATE FUNCTION example(value1, value2)

After that, you can press 'enter' and insert whatever code you want to be run inside the function and after you've finished, close off the function on a new line with the END  keyword, this lets the program know that you've ended the function. For the sake of learning the function below does not have any parameters.

Example:

CREATE FUNCTION example()

WRITE("Hello")

END


To run the function, simply type out the function name followed by a pair of '()' with any appropriate arguments.

Example:

CREATE FUNCTION example()

WRITE("Hello")

END

example()

Output: Hello