Last modified 7 years ago Last modified on 2017-06-30 08:51:46

Pages linking to SGISyntax:
AllAboutSGI

SGI Statement Syntax

a generator file contains

SGI := { statementClause }*;

An SGI script is made up from a number of statement clauses.

statementClause

statementClause := ( outputClause | informClause | defineClause
    | ifClause | whileClause | forClause | switchClause | expressionClause
    | filingClause | returnClause | localDefinition | loopControl
    | blankClause ) ;

A statement clause could be one of ...

  • an output clause;
  • an inform clause;
  • a define clause;
  • an if clause;
  • a while clause;
  • a for clause;
  • a switch clause;
  • an expression clause;
  • a filing clause;
  • a return clause;
  • a local data definition clause;
  • a loop control clause or
  • a blank clause

loopControl

loopControl := ( "break" | "continue" ) ";" ;

A loop control clause is either

  • a break command or
  • a continue command

however, the result of executing such a command outside a loop is unknown.

filingClause

filingClause :=
    ( "create" expression "{" { statementClause }* "}"
    | "section" expression "{" { statementClause }* "}" 
    | "drop" expression { "," expression }* ";" 
    | "flush" expression { "," expression }* ";" 
    );

The create clause opens a file (for writing) with the name detailed in the expression. All output statements executed in the following compound statement are written into the file.

Within the compound statement of a create statement, a section identified by an integer, can be declared. All output statements executed in the following compound statement, are buffered until a flush statement identifies the section and flushes it to the output file.

Within the compound statement of a create statement, a predefined section can be discarded or dropped.

Within the compound statement of a create statement, an identified buffered section can be flushed to the output file.

see FilingClauseExample?

blankClause

blankClause :=
  ( ";"
  | ">>"
  | "<<"
  | "@"
    ( "vdump"
    | "adump"
    | "dump"
    | "fdump"
    )
  );

a blank clause does not affect the use output. It consists of one of the following,

  • no operation
  • increase the level of indentation
  • decrease the level of indentation
  • inform the user
    • dump the list of variables
    • dump the list of aliases

ifClause

ifClause := "if (" expression ")" "{"  compoundStatementClause "}"
  ( "else {" compoundStatementClause "}"
  | ""
  );

An "if clause" is similar to that found in C-Code, with its dangling "else".

informClause

informClause := "inform (" expression
  {
    ( expression { "," }
    | "["
      {
        expression
        {
          ","
        }
      }*
      "]"
    )
  }*
  ")";

An inform clause is similar to an output clause, except that the inform clause output goes to the console.

outputClause

outputClause := "["
  {
    ( "," expression
    | expression
    | "["
      {
        ( "," expression
        | expression
        )
      }+
      "]"
    )
  }+
  "]";

An output clause "prints" the value of the expressions contained therein, to the console if no file has been created (inside create clause) or to the file or file section declared (inside create or section clause.) Please note, expressions and nested inside square brackets, are output directly without any form of escape character expansion.

whileClause

whileClause :=  "while (" expression ")" "{" compoundStatementClause "}";

The "while clause" is similar to that found in C-Code.

forClause

forClause :=
  ( "for each" ident "in" expression
    {
      "where"
      ( expression
      | "(" expression ")"
      )
     }
     "{" compoundStatementClause
  | "for ("  expression ";" expression ";" expression ")" "{" compoundStatementClause "}"
  );

The FOR clause comes in two flavours, one similar to 'C's for statement, with a pre-condition, a post-increment and a while clause, and the other like C#'s "for each" for traversing lists.

switchClause

switchClause := "switch (" expression ")" "{"
  {
    caseClause
  }+
  ( "default" "{" compoundStatementClause "}"
  | ""
  )
  "}";

caseClause

caseClause := "case" expression
  {
    "," expression
  }*
  "{" compoundStatementClause "}";

expressionClause

expressionClause := expression ";";

An expression clause executes an assignment or function call.

expression

expression := andClause
  {
    "||" expression
  }*
  {
    "?" expression ":" expression
  }; 

An expression consists of an "andClause" and a number of logical-or sub-expressions with an optional ternary operator.

andClause

andClause := bitOrClause
  {
    "&&" andClause
  }*; 

an andClause consists of a bitwise or clause with optional number of logical and sub-clauses.

bitOrClause

bitOrClause := bitXorClause
  {
    "|" bitOrClause
  }*; 

a bitwise or clause consists of a bitwise exclusive-or clause followed by an optional number of bitwise-or operators with sub-clauses.

bitXorClause

bitXorClause := bitAndClause
  {
    "^" bitXorClause
  }*;

a bitwise xor clause consists of a bitwise and clause followed by an optional number of carret and another bitwise xor clauses.

bitAndClause

bitAndClause := equalityClause
  {
    "&" bitAndClause
  }*;

equalityClause

equalityClause := comparativeClause
  {
    ( "==" equalityClause
    | "!=" equalityClause
    )
  }*;

comparitiveClause

comparativeClause := shiftClause
  {
    ( "<" comparativeClause
    | "<=" comparativeClause
    | ">=" comparativeClause
    | ">" comparativeClause
    )
  }*;

shiftClause

shiftClause := additionClause
  {
    ( "<<" shiftClause
    | ">>" shiftClause
    | ">>>" shiftClause
    | "<<<" shiftClause
    )
  }*;

additionClause

additionClause := multiplyClause
  {
    ( "+" additionClause
    | "-" additionClause
    )
  }*;

multiplyClause

multiplyClause := unaryClause
  {
    ( "*" multiplyClause
    | "/" multiplyClause
    | "%" multiplyClause
    )
  }*;

unaryClause

unaryClause :=
  ( "!" unaryClause
  | "-" unaryClause
  | "~" unaryClause
  | "(" expression ")"
  | functionalClause
  | baseClause
  );

functionClause

functionClause :=
  ( "size (" expression ")"
  | "number (" expression ")"
  | "lower (" expression ")"
  | "asc (" expression ")"
  | "chr (" expression ")"
  | "upper (" expression ")"
  | "commandLine (" expression ")"
  | "capital (" expression ")"
  | "next"
    ( "(" expression ")"    /* next item in list */
    | ident "(" expression  /* next in search */
      {
        "," expression
      }+
      ")"
    )
  | "prev (" expression ")"
  | "empty (" expression ")"
  | "count (" expression ")"
  | "contains (" expression "," expression ")"
  | "open (" expression ")"
  | "close (" expression ")"
  | "read (" expression ")"
  | "eval (" lambdaExpression | stringExpression ")"
  | "exec (" lambdaStatement | stringExpression ")"
  | "daTime"
  | "wait"
  | "new" ident "(" { expression { "," expression }* } ")"
  | "free" ident "(" expression ")"
  | "link" ident "("    expression "," expression ")"
  | "unlink" ident "(" expression  ")"
  | "link new" ident "(" expression { "," expression }* ")"
  | "unlink free" ident "(" expression  ")"
  | "find" ident "(" expression { "," expression }* ")"
  | "find or link new" ident "(" expression { "," expression }* ")"
  );

see the ListOfFunctionalClauses?

baseClause

baseClause :=
  ( number
    ( "." number
      {
        ( "e"
        |"E"
        )
        number
      }
    | ( "e"
      | "E"
      )
      number
    | ""
    )
  | "({" compoundStatement "})" /* lambda statement */
  | "<{" expression "}>"        /* lambda expression */
  | litteral
  | "++" identifier
  | "--" identifier
  | identifier
    {
      ( "++"
      | "--"
      | "("
        {
          expression
          {
            "," expression
          }*
        }
        ")"
      | assignop
      | ""
      )
    }
  );

assignop

assignop :=
  ( "=" expression
  | "+=" expression
  | "-=" expression 
  | "*=" expression 
  | "/=" expression 
  | "%=" expression 
  | "&=" expression 
  | "|=" expression 
  | "^=" expression 
  | "&&=" expression 
  | "||=" expression 
  | ">>=" expression 
  | "<<=" expression 
  | "<<<=" expression 
  | ">>>=" expression 
  );

identifier

identifier := ident
  {
    ( "[" expression "]"
    | {
        "." ident
      }+
    )
  }*
  {
    "->" ident
  }*;

The "->ident" clause only applies to interpreters that "own" a data schema.

defineClause

defineClause := "function" ident "("
  {
    singleParam
    {
      "," singleParam
    }*
  }
  ")" functionDefinitionBit;

A function definition looks like this ...

function apply();            /* for a prototype  or ... */
function apply() { return; } /* for a real function */

singleParam

singleParam :=
  ( ident
  | "$" ident
  ); 

each function parameter is either passed by value or passed by reference.

localDefinition

localDefinition := "local" ident
  {
    "," ident
  }*
  ";";

defines a local variable ...

functionDefinitionBit

functionDefinitionBit :=
  ( "{" compoundStatementClause "}"
  | ";"
  );

a function definition is either a prototype or a full function definition with a compound statement.

returnClause

returnClause := "return"
  ( expression
  | ""
  )
  ";";

returns from a function with the value of an expression or NULL.

SGI imported C libraries

uartFunctions := 
  { "openSerialPort (" expression ")"
  | "sendChar (" expression "," expression ")"
  | "recvChar (" expression ")"
  | "closeSerialPort (" expression ")" };

pipeFunctions :=
  { "psopen (" expression ")"
  | "pcopen (" expression ")"
  | "pputc (" expression "," expression ")"
  | "pgetc (" expression ")"
  | "pclose (" expression ")" };

winFunctions :=
  { "msgBox (" expression "," expression "," expression ")"
  | "MessageBox (" expression "," expression "," expression "," expression ")"
  | "MSG_OK"
  | "MSG_OKCANCEL"
  | "MSG_ABORTRETRYIGNORE"
  | "MSG_MSG_YESNOCANCEL"
  | "MSG_YESNO"
  | "MSG_RETRYCANCEL"
  | "MSG_CANCELRETRYCONTINUE"
  | "MSG_WARNING"
  | "MSG_INFO"
  | "MSG_ERROR"
  | "MSG_QUESTION" }