Last modified 7 years ago Last modified on 2017-06-30 05:59:01

Pages linking to AllAboutSGI:
WikiStart

All About SGI

It does what it's on the tin, it interprets generation scripts. It has the C-Code like grammar, but in the tradition of BCPL it's typeless. There are however some considerable exceptions.

A full syntax, here, with some semantic explanation, follows ...

SGI Pre-Processing

SGI has a C-Code style pre-processing, ie has

Syntax Description Example
#include stringincludes a file for interpreteation starting at the %vbron%\gen base directory#include "PreFatApp/?/extracode.gen"
#define ident string-to-eoldefine a-la C-Code#define HEADER_INCLUDED 1
#define ident(params)define a-la C-Code#define macro(_here) _here
#ifdef ident ... #else ... #endifconditional compilation a-la C-Code ... the ident is a macro, not a SGI variable#ifdef HEADER_INCLUDED
#define macro(_here)
#else
#define macro(_here) _here
#endif

SGI Meta Syntactic Variables

These are a set of what appear to be variables but control functions within the interpreter.

These are ...

VariableRangeValueMeaning
debugLevel0-71Trace all function call entry and exit
2Trace locals, aliases and parameters
4Trace all assignments
8Trace filename and line number recognised when "pre-compiling" into intrinsic functions
16Trace the execution of all intrinsic functions
autoIndent0+ The number of tabstops ejected after each "\n"
This value can be incremented with the ">>"(!1) command
and decremented with the "<<" (!2) command
or with autoIndent++; and autoIndent--;
lines0+ The number of lines ejected so far
columns0+ The current column number of the output
pageWidth40+80This is the default page width, used to offer automatic page formatting ( no line going over the pageWidth )
tabWidth1+4The expected size of a tab character
tabReqd0-10Tabs produced as spaces or tabs produced as tab characters
(!1) not to be confused with the ">>" operator
(!2) not to be confused with the "<<" operator

Simple Output

Anything inside "\[" "\]" will be evaluated and output to stdout.

three = "two";
["Hello the " three " of you\n" ]

will result in

Hello to the two of you

appearing on standard out.

SGI Scope

Scoping in SGI is similar to Pascal.

b = 2;

function fn2()
{
    [ b "\n" ]
}

function fn1()
{
    local b;

    b = "one";
    fn2();
}

[ "A) " ] fn1();
[ "B) " ] fn2();

will produce

A) one
B) 2

The call to fn2() within the fn1() call will produce "one" because the local "b" in fn1() has scope.
The call to fn2() ... will produce "2" because the local "b" from fn1() is no longer in scope and the global "b" is uncovered.
Scope is maintained on a stack frame basis, ie where local variables and parameters are pushed on the stack frame and only the latest one is visible.

A function needs to be declared before it is used, NB declared but not necessarily written. Each time a function is declared it's old code is deleted ... to this end, any function can be re-defined "on the fly" using the 'exec' function.

SGI Lazy Evaluation

In the "expression" and "andClause"s, SGI is now (like C) decision optimising.

in the expression

 a = b() ? c() : d();

if b() is true then only c() is executed if b() is false then only d() is executed a is assigned either c() or d() ... and not assigned to one or the other after the execution of both c() and d().

in the expression

 a = b() || c() || d();

If b() is true then neither c() nor d() are executed. If b() is false however c() is executed. If c() is true then d() is not executed, however if c() is also false then d() is finally executed.

and finally in the expression

 a = b() && c() && d();

If b() is false then neither c() nor d() are executed. If b() is true however c() is executed. If c() is false then d() is not executed, however if c() is also true then d() is finally executed.

function logicalNot( val )
{
    [ "NOT " ]
    return val ? 0 : 1;
}

function hello( name )
{
    [ "Hello " name "\n" ]
    return 1;
}

[ logicalNot( 1 ) ? hello( "Colin" ) : hello("James") ]

will create

NOT Hello James

SGI External Debugging

As well as the debegLevel support, there is an SGI Debugger, that allows you to single step through yout SGI code. This can be turned on and off from within the code with the

@debug on

and

@debug off

commands see SGISyntax below ...

SGI Statement Syntax