Statements

PGL code is a sequence of statements separated by semicolumns. There are three major kinds of statements: ``expression statements'', ``declaration statement'', and ``code blocks''. All are described below.

1. Expression Statement

There are two kinds of expression statements: ``assignments'' and function or procedure ``calls''. All have syntax common to procedural languages.

bar.field1 = 1235;
foo = bar;
f(foo, bar);
z = normal(10sec, 3sec);

When many field modifications to the same object are required, it is often convenient to use a scope operator. The two pieces of code below are equivalent.

foo.field1 = 1;
foo.field2 = "something";
foo.field3 = '127.0.0.1';

// same using foo's scope
foo = {
    field1 = 1;
    field2 = "something";
    field3 = '127.0.0.1:8080';
};

PGL uses the same rules for scoped statements as for the statements inside a code block (see below). For example, you can declare new [local] variables inside a scope operator.

2. Declaration Statements

These are no different from declarations in C and many other languages. All declarations start with the object type and may have an optional initialization clause. Just remember that every object in PGL must be declared exactly once and before first use.

int i;
string s = "something";
rate peak_rate = 140/sec;
addr[] hosts = '10.13.0-4.1-250';

Bench TheBench = {
    client_side.addr_mask = 'fxp0::192.176.0.0/16';
    server_side.max_host_load = peak_rate;
};

3. Code Blocks

Sometimes it is convenient to group several statements into a ``block''.

// do magical calculations
{
    int foo = 12345;
    int bar = foo / clientHostCount(TheBench);
    working_set_capacity(foo);
}
int foo = 0; // this is a different foo

As the above example illustrates, variables declared inside a block are local to that block.