The {high-level} programming language was designed with three goals in mind: make it easy to call C++ functions from {high-level}, and make it easy to call {high-level}functions from C++, and to develop a language designed from the ground up to be part of the {engine name}. All non-engine code is written in {high-level}. Programmers familiar with any curly bracket language (C,C++,PHP) will be immediately familiar with {high-level}. There a few notable exceptions to take into account when programming in {high-level}that are discussed within the sections below.
In this section we'll review a sample program, variables, operators, and basic input/output functionality.
This program prints “Hello World” on the screen minus the quotes.
function int Main(int argc, array <string,*> argv)
{
cout << "Hello World";
return 0;
}
function int Main(int argc, array <string,*> argv)
All programs will contain the following line of code. This is called a function. We'll cover those more in detail later on, but the key thing to remember is that when a program is executed this is the first piece of code that is run regardless of where it actually is within the program. When a call a program you may sometimes have the option to pass it parameters, these parameters are then stored in the two variables: argc how many variables where passed, and argv which is an array containing the actual variables. For example: MyProgram 1 2 3. In this case argc would be set to three, and argv would contain the parameters 1,2, and 3.
{
The curly bracket let's the compiler know that the body of function will immediately follow it.
cout « “Hello World”;
This statement is what actually does the displaying of the text. Note that the line ends in a semicolon. The semicolon tells the compiler that it has reached to end of the statement. The semicolon is always required unless otherwise specified.
return 0;
Once a program finishes executing it has the ability to return data to the process or program that launched it. In this case we are returning the number 0. Again, note that this line ends with a semicolon.
}
The closing curly bracket tells the compiler that it has reached the end of the function int Main
As programs grow in complexity it can become difficult to quickly understand a section of code, so adding comments to your code is important for maintainability. There are two styles of comments supported. Comments are removed from the program prior to compilation, so you can have as many comments in a program as you want and it won't change the size of the compiled program.
Example:
// This comments out a single line until a carriage return is reached.
/* This comments out
a block of text */
{high-level} is a statically typed language. This means that once you initialize a variable to a certain type you can't then change the type of the variable later in the program. Variables may contain numbers, but they must always begin with a letter. You may not use registered keywords as variables.
| Type | Definition |
|---|---|
| int | Integer is any number -32767 to 32767 without a decimal |
| bool | Boolean can have a value true or false |
| string | String can contain any characters up to a maximum of 2^32 |
| float | Floating Point numbers can be any value -3.4 x 10^38 to -3.4 x 10^38 |
Variable Declaration
int x; x = 1; int x = 1; int x = 0, y=1; bool flag = true; string name = "Alex Ayers";
You can also create multiple variables at one time.
int x,y,z;
Arrays allow for the sequential storing of data of a similar type. You can create an array of any of the simple types listed in the section above.
Initialization
array <type,size> var_name; array <int,10> int_array; /* The array int_array can store 10 numbers. */
Usage
my_array[0] = 5; x = my_array[0] + my_array[1]; x = my_array[1+x*4]; // Variables can be used inconjunction with constants to access values within the array. myarray[0] = myarray[1];
A string is an array of characters, and so you can perform the same operations on a string that you can on an array.
This string variable:
string Hello = “Hello”;
Translates to:
Hello[0] = “H”;
Hello[1] = “e”;
Hello[2] = “l”;
Hello[3] = “l”;
Hello[4] = “o”;
That means you can perform the following actions.
cout << Hello[0]; Output: H
Hello[0] = "J"; cout << Hello; Output: Jello
String Concatenation
It's possible to concatenate a string with another string.
string Hello = "Hello "; string World = "World!"; Hello += World; cout << Hello; output: Hello World!
There are three levels of variable scope or lifetime: global, local, and loop. A variable with global scope can be used anywhere within the program. A variable with local scope can only be used within the function it was defined. A loop defined within the loop declaration can only be used within the loop.
Scope Example
global int x = 5;
function int Main(int argc, array <string,*> argv)
{
Fun1();
Fun2();
return 0;
}
function void Fun1()
{
int y;
y = 1;
cout << y << " " << x << endl;
}
function void Fun2()
{
string y = "var";
cout << y << " " << x << endl;
}
output 1 5 var 5
A program without any control structures would follow a linear path until the program was complete. While this might useful some of the time, most of the time you will need to perform more complex operations. There are two types of control structures: loops, and branches. A loop will cause a section of code to repeat until a certain condition is met. A branch will only execute a certain section of code if a certain condition is met. Loops and branches rely on comparison and boolean operators.
Comparison Operators
| Operator | Definition |
|---|---|
| > | Greater than |
| < | Less than |
| >= | Great than or equal to |
| <= | Less than of equal to |
| == | equal |
| != | not equal |
Boolean Operators
| Operator | Definition |
|---|---|
| && | Logical And |
| || | Logical OR |
There are three types of loops: for, do-while, and while.
for (int i = <:variable|integer|int function:>; <:variable|integer|int function:> <:comparison operation:> <:variable|integer|int function:>; <:variable:>++)
{
;
}
Example
for (int i = 0; i < 10; i++)
{
;
}
A for loop has three components: variable initialization, loop terminator, and iteration statement. All parts a mandatory. It's important to realize that the variable declared within the for loop is local to the loop. Note: variable must be an integer value. Currently the iterated MUST be the form of <variable>++ or <variable>–.
while (condition)
{
;
}
The simplest type of branch is an a stand alone if branch.
if (x == 0)
{
cout << "x = 0";
}
The next style of branch is the if-else
if (x == 0)
{
cout << "x = 0";
}
else
{
cout << "x != 0";
}
However you can string multiple branches together by using else if:
if (x == 0)
{
cout << "x = 0";
}
else if (x > 0 && x != 2)
{
cout << "x > 0, but not equal to 2.";
}
else
{
cout << "x is < 0";
}
function <:type:> <:name:> (variables)
All functions are pass by value. This means if you pass the variable x to a function you can be sure that x will not alter after the function returns.
Note: Recursive programming is not supported.
Before using a function you must first declare the function.
Examples:
function int Foo(int x); function bool Foo2(float point_x,float point_y);
The keyword function must start every function declaration. After the keyword function you need to define the return value. For valid function return types see the above section on variables.
function int Foo(int x)
{
cout << x;
return 0;
}
Functions can be called within loops or branch statements:
while (IsTrue())
{
// code
if (BigValue() > SmallValue())
{
// code
}
}
{high-level} also supports writing embedded vasm within {high-level}, and you can reference (high-level} variables within a vasm block.
int x = 5;
__vasm
{
mov ax x
mov ix 1
int 6
}
Developing reusable libraries is a good programming practice, and {high-level} supports code libraries. You are allowed to link as many libraries as you want, but you can't link to other libraries from within a library.
Syntax:
#include “library”
Usage:
#include “c:\lib\string.h”
Important things to remember about code libraries.
1. You can't link to other code libraries from within the library. 2. Library source files and header files must have the same filename. Ex: library.vc and library.vh.
In programming is can be useful to create an alias for a data type.
Example:
string kia; string ford; kia = "Rio"; ford = "Focus";
To someone that is familiar with cars the variable names might make sense even though they are strings. However, if you could create an alias for string called Car it would allow a future programmer to look over your code and quickly realize that kia and ford were cars. Here's the same example using typedefs.
typedef string Car
Example:
Car kia; Car ford; kia = "Rio"; ford = "Focus";
It should be noted that this only creates an alias for the variable type string; it does not rename the type string to be Car.