Making of Pseudo-Code Engine: Part 2 – Syntax Part 1
In the last entry in this series I just discussed some of the basics of the engine (and programming languages in general). In this entry, I want to present the current structure of the syntax which will be used in the engine.
The Syntax
The syntax specifies the rules for what how we type our various code. One important thing about our syntax is that it is case sensitive. All keywords will start with a capital letter, with all lowercase letters for the rest.
Components
In this syntax, we have a couple symbols which we’ll use to describe things. Things written in square braces [] mean that it is optional to use. Things in between greater than and less than signs <> are variable components. These components are as follows:
- <name>
- The name of a variable, function, or class. If a datatype is in the <> before name (such as <Array name>), it means it must be of that type. These names must follow the following rules: can only contain letters, numbers, or an underscore. They cannot begin with a number.
- <datatype>
-
Specifies one of our built-in datatypes or a custom one.
Our datatypes are as follows:
- Integer – A whole number value (0, 123, 232, 31, etc.).
- Real – A decimal value (0.1, 123.4, etc.).
- Boolean – A true/false value. The values must be written as either True or False. 0 and 1 will also work.
- String – A string of zero or more characters. Strings must be surrounded by double-quotes (“”, “apple”,”c”, etc.).
- Array – A collection of values (or any type). Arrays must surround their data with an open and close curly bracket. ({0,1,2},{1.0,”a”,10},{True, False, True}).
- Void – A value that is essentially no value. You can’t create a value of type Void, only use it as a function’s return type.
- <value>
- A single value of any datatype.
- <expression>
- A single expression, which results in zero or one values.
- <expressions>
- Any number of expressions, each on it’s own line.
- <parameters>
- One or more parameter for a function.
- <condition>
- An expression that evaluates to a Boolean (true/false) value.
Operators
In this language, we’ll just have a couple basic operators:
- Addition sign (+)
-
This will take two values, and depending on the datatypes of the values, will try to add them together. Here is a chart of the input datatypes and their output:
First Datatype Second Datatype Resulting Datatype Notes Integer Integer Integer Integer Real Integer The decimal value is truncated Integer Boolean Integer False is treated as 0, True is treated as 1 Integer String String The Integer is converted to a String Integer Array Array The Integer is appended to the beginning of the Array Integer Void Integer Equals the Integer Real Integer Real Real Real Real Real Boolean Real True is treated as 1, False is treated as 0 Real String String The Real is converted to a String Real Array Array The Real is appended to beginning of Array Real Void Real Equals the Real Boolean Integer Integer True is treated as 1, False is treated as 0 Boolean Real Real True is treated as 1, False is treated as 0 Boolean Boolean Boolean True is treated as 1, False is treated as 0; If the result is 2, it will be reduced to 0 (False) Boolean String String The Boolean is converted to a String of “0″ or “1″ Boolean Array Array The Boolean is appended to beginning of Array Boolean Void Boolean Equals the Boolean String Integer String The Integer is converted to a String String Real String The Real is converted to a String String Boolean String The Boolean is treated as “0″ or “1″ String String String The two strings are concatenated. String Array Array Appends the String to beginning of Array String Void String Equals the String Array Integer Array Appends the Integer to the end of the Array Array Real Array Appends the Real to the end of the Array Array Boolean Array Appends the Boolean to the end of the Array Array String Array Appends the String to the end of the Array Array Array Array Concatenates the two Arrays Array Void Array Appends a Void to the end of the Array Void Integer Integer Equals the Integer Void Real Real Equals the Real Void Boolean Boolean Equals the Boolean Void String String Equals the String Void Array Array Void is appended to the beginning of the Array Void Void Void A couple things to note:
- Variables cannot be created with a datatype of Void. Only source of Void is from Functions.
- When Void is added to anything else, it essentially doesn’t affect the value. The exception is with Array, it will be appended to an Array.
- If you are a bit confused about a few things, remember that when things are “treated as” something, it’s the same as adding two values of the treated as datatype (ex. If you add 5 + True (Integer + Boolean), the True is treated as 1, so it’s the same as Integer + Integer, so you’d get 6.
- There are a number of oddities in our table, when compared to other languages. For example, most don’t allow appending to an array with the + sign. Also, most languages have certain combinations which would throw an error (such as adding Voids).
- Subtraction sign (-)
-
This will take two values, and depending on the datatypes of the values, will try to subtract them from each other. Here is a chart of the input datatypes and their output:
First Datatype Second Datatype Resulting Datatype Notes Integer Integer Integer Integer Real Integer The decimal value is truncated Integer Boolean Integer False is treated as 0, True is treated as 1 Integer Void Integer Equals the Integer Real Integer Real Real Real Real Real Boolean Real True is treated as 1, False is treated as 0 Real Void Real Equals the Real Boolean Integer Integer True is treated as 1, False is treated as 0 Boolean Real Real True is treated as 1, False is treated as 0 Boolean Boolean Boolean True is treated as 1, False is treated as 0; If the result is -1, it will be reduced to 1 (True) Boolean Void Boolean Equals the Boolean Void Integer Integer Equals the Integer Void Real Real Equals the Real Void Boolean Boolean Equals the Boolean Void Void Void Anything not in this table will cause an error (noteably, trying to use a String or Array as one of the operands will always cause an error).
- Multiplication sign (*)
-
This will take two values, and depending on the datatypes of the values, will try to multiply them together. Here is a chart of the input datatypes and their output:
First Datatype Second Datatype Resulting Datatype Notes Integer Integer Integer Integer Real Integer The decimal value is truncated Integer Boolean Integer False is treated as 0, True is treated as 1 Integer Void Integer Equals the Integer Real Integer Real Real Real Real Real Boolean Real True is treated as 1, False is treated as 0 Real Void Real Equals the Real Boolean Integer Integer True is treated as 1, False is treated as 0 Boolean Real Real True is treated as 1, False is treated as 0 Boolean Boolean Boolean True is treated as 1, False is treated as 0 Boolean Void Boolean Equals the Boolean Void Integer Integer Equals the Integer Void Real Real Equals the Real Void Boolean Boolean Equals the Boolean Void Void Void - Division sign (/)
-
This will take two values, and depending on the datatypes of the values, will try to divide them. Here is a chart of the input datatypes and their output:
First Datatype Second Datatype Resulting Datatype Notes Integer Integer Integer Any decimal is truncated. Integer Real Integer The decimal value is truncated Integer Boolean Integer False is treated as 0, True is treated as 1 Integer Void Integer Equals the Integer Real Integer Real Real Real Real Real Boolean Real True is treated as 1, False is treated as 0 Real Void Real Equals the Real Boolean Integer Integer True is treated as 1, False is treated as 0 Boolean Real Real True is treated as 1, False is treated as 0 Boolean Boolean Boolean True is treated as 1, False is treated as 0. Boolean / False = Not Boolean Boolean Void Boolean Equals the Boolean Void Integer Integer Equals the Integer Void Real Real Equals the Real Void Boolean Boolean Equals the Boolean Void Void Void A special note about division: Anything divided by zero doesn’t exist (it’s inifinity), so dividing anything by zero will cause an error.
- Equals Sign (=)
-
The equals sign will serve two purposes. The first person is as an assignment operator. It will take whatever is on the right side of the operator (evaluated down to a single value), and assign it to the variable on the left. So, it would be like this:
Real num1 = 3.5 // Gives the value of 3.5 to num1. Integer num2 = 5 + 3 // Gives the value of 8 to num2.
In this usage, if what is to the left of the operator isn’t a variable, and what is on the right doesn’t evaluate to a single value, an error will be thrown.
The other usage is as an equivalency comparison operator. It will take a value on the left and a value on the right and determine if they are equal to each other. They are considered equal if they have the same datatype and the same value. The exception to this is two values can evaluate to the same if they are any combination of Integer, Boolean, or Real. Example:
Integer a = 0 a = False // This would become True.
You can assign the result of a comparison to a variable. In any expression that isn’t a conditional statement, if an equal sign is found, the first one will be treated as an assignment operator, and any subsequent ones will be treated as comparison operators. This means if the value to the left of the equal sign is not a variable, an error will be thrown. The exception to this is if it is within a function call or after something like “Print” (which will be discussed later). In these cases, it’ll always be treated as a comparison operator.
In a conditional statement, an equal sign is always assumed to be a comparison operator.
Boolean b = (5 = 3) // Assigns b to False
- Greather Than (>), Greather Than or Equal To (>=), Less Than (<), Less Than or Equal To (<=)
- All of these are comparison operators, much like the equivalency comparison operator. The Greater Than sign will return True if the left operand is greater than the right. The Greater Than or Equal To sign will return True if the left operand is greater than or equal to the right. The Less Than sign will return True if the left operand is less than the right. The Less Than or Greater To sign will return True if the left operand is less than or equal to the right.
- Parentheses (())
- Parentheses are used to surround values to modify the order of precedence when using the previous five operators. The normal order of precedence is: * or /, then + or -, then =. This is basically the same as regular mathematics. When you use parentheses, anything within the parentheses is evaluated before anything else in the expression.
- Not (!)
- The Not operator, when placed before a Boolean value will return the opposite of the value. If it has any other datatype next to it, it will throw an Error. In the order of precedence, ! has the highest.
- Not Equal (!=)
- The Not Equal operator is a comparison operator that gives the opposite result of the equivalency operator.
- Comments (//)
- The comment operator allows you to add comments to your code. Anything after the comments operator is completely ignored, so you can put anything. This is useful for remembering what your code is supposed to do.
Wow, it sure takes a while to type all this out. In this entry we covered the types of components, the built-in datatypes, and the operators. In the next entry of this series we’ll get to the other statements and keywords that we’ll make use of in this language.




