Making of Pseudo-Code Engine: Part 3 – Syntax Part 2
In my previous entry in this series I described the the datatypes, the operators, and some of the constructs we’ll be using in this language. In this entry I want to finish up the syntax by going through the keywords and the actions we can use.
As I mentioned in the first part of this series, the Pseudo-Code Engine is going to be released in three main parts. We’ll be grouping off the parts of this into the three releases as well. Each new version will add to the previous, not replace them. In this entry, I’m just going to post the syntax for the first version to give you a taste. Once we actually release it, there will be “official” documentation which will declare all of it in it’s functioning form.
Version 0.1 Syntax
In this language, each line will be considered a separate statement.
Variable Declaration
<datatype> <name> [= <value>]
This is used for declaring a new variable. You can optionally define the variable at the same type.
Examples:
Integer num = 5
Boolean is_bob = True
Array names = {"Bob","Tim","Joe"}
Variable Assignment
<name> = <value>
This is used to assign a value to a variable. Value doesn’t have to be a single number, it can be values that combined with various operators that combine into a single value.
Examples:
num = 5 + 2 is_bob = False String name = "Bob" name = name + " Smith"
If…Else If… Else Statements
If <condition> Then [<expressions>] [Else If <condition> Then [<expressions>]] [Else [<expressions>]] End If
The basic structure just requires the If portion, ended with End If. You aren’t required to have any expressions, but the If statement does nothing if you don’t. You can optionally add Else If statements, and/or an Else statement as well.
Examples:
Boolean is_bob = True If is_bob = True Then Print "It's Bob" Else Print "It's nobody" End If
Print <String value>
Print must be followed by a value (or expression that evaluates to a value) of the datatype String. This is the only built-in way to send output (of course, you can build on top of this).
Example:
Print "Bob is here!"
Switch…Case
Switch <value>
[Case <value>
[<expressions>]
Break]
[Default
[<expressions>]
End Switch
The Switch…Case requires the Switch and End Switch portion. You can optionally add as many Cases as you want and one Default. Note that the Default must be last in the Switch statement or else an error will be thrown. At the end of a Case you must specify a Break. Once it finds the first suitable case, it will continue until it reaches the first Break or End Switch.
Examples:
Integer aNum = 10
Switch aNum
Case 0
Case 1
Case 2
Print "The value is too low"
Break
Case 12
Case 13
Print "The value is too high"
Break
Default
Print "The value is appropriate"
In this entry we took a look at the initial syntax for the first version of the Pseudo-Code entry. The rest of the entries in this series will be talking about interesting specifics of the engine, instead of just these documentation aspects.




