= SGI Statement Syntax = [[TOC]] ==== a generator file contains ==== {{{ #!c SGI := { statementClause }*; }}} An SGI script is made up from a number of statement clauses. ==== statementClause ==== {{{ #!c 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 ==== {{{ #!c 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 ==== {{{ #!c 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 ==== {{{ #!c 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 ==== {{{ #!c ifClause := "if (" expression ")" "{" compoundStatementClause "}" ( "else {" compoundStatementClause "}" | "" ); }}} An "if clause" is similar to that found in C-Code, with its dangling "else". ==== informClause ==== {{{ #!c 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 ==== {{{ #!c 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 ==== {{{ #!c whileClause := "while (" expression ")" "{" compoundStatementClause "}"; }}} The "while clause" is similar to that found in C-Code. ==== forClause ==== {{{ #!c 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 ==== {{{ #!c switchClause := "switch (" expression ")" "{" { caseClause }+ ( "default" "{" compoundStatementClause "}" | "" ) "}"; }}} ==== caseClause ==== {{{ #!c caseClause := "case" expression { "," expression }* "{" compoundStatementClause "}"; }}} ==== expressionClause ==== {{{ #!c expressionClause := expression ";"; }}} An expression clause executes an assignment or function call. ==== expression ==== {{{ #!c 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 ==== {{{ #!c andClause := bitOrClause { "&&" andClause }*; }}} an andClause consists of a bitwise or clause with optional number of logical and sub-clauses. ==== bitOrClause ==== {{{ #!c 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 ==== {{{ #!c 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 ==== {{{ #!c bitAndClause := equalityClause { "&" bitAndClause }*; }}} ==== equalityClause ==== {{{ #!c equalityClause := comparativeClause { ( "==" equalityClause | "!=" equalityClause ) }*; }}} ==== comparitiveClause ==== {{{ #!c comparativeClause := shiftClause { ( "<" comparativeClause | "<=" comparativeClause | ">=" comparativeClause | ">" comparativeClause ) }*; }}} ==== shiftClause ==== {{{ #!c shiftClause := additionClause { ( "<<" shiftClause | ">>" shiftClause | ">>>" shiftClause | "<<<" shiftClause ) }*; }}} ==== additionClause ==== {{{ #!c additionClause := multiplyClause { ( "+" additionClause | "-" additionClause ) }*; }}} ==== multiplyClause ==== {{{ #!c multiplyClause := unaryClause { ( "*" multiplyClause | "/" multiplyClause | "%" multiplyClause ) }*; }}} ==== unaryClause ==== {{{ #!c unaryClause := ( "!" unaryClause | "-" unaryClause | "~" unaryClause | "(" expression ")" | functionalClause | baseClause ); }}} ==== functionClause ==== {{{ #!c 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 ==== {{{ #!c baseClause := ( number ( "." number { ( "e" |"E" ) number } | ( "e" | "E" ) number | "" ) | "({" compoundStatement "})" /* lambda statement */ | "<{" expression "}>" /* lambda expression */ | litteral | "++" identifier | "--" identifier | identifier { ( "++" | "--" | "(" { expression { "," expression }* } ")" | assignop | "" ) } ); }}} ==== assignop ==== {{{ #!c assignop := ( "=" expression | "+=" expression | "-=" expression | "*=" expression | "/=" expression | "%=" expression | "&=" expression | "|=" expression | "^=" expression | "&&=" expression | "||=" expression | ">>=" expression | "<<=" expression | "<<<=" expression | ">>>=" expression ); }}} ==== identifier ==== {{{ #!c identifier := ident { ( "[" expression "]" | { "." ident }+ ) }* { "->" ident }*; }}} The "->ident" clause only applies to interpreters that "own" a data schema. ==== defineClause ==== {{{ #!c defineClause := "function" ident "(" { singleParam { "," singleParam }* } ")" functionDefinitionBit; }}} A function definition looks like this ... {{{ #!c function apply(); /* for a prototype or ... */ function apply() { return; } /* for a real function */ }}} ==== singleParam ==== {{{ #!c singleParam := ( ident | "$" ident ); }}} each function parameter is either passed by value or passed by reference. ==== localDefinition ==== {{{ #!c localDefinition := "local" ident { "," ident }* ";"; }}} defines a local variable ... ==== functionDefinitionBit ==== {{{ #!c functionDefinitionBit := ( "{" compoundStatementClause "}" | ";" ); }}} a function definition is either a prototype or a full function definition with a compound statement. ==== returnClause ==== {{{ #!c returnClause := "return" ( expression | "" ) ";"; }}} returns from a function with the value of an expression or NULL. ==== SGI imported C libraries ==== {{{ #!c 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 } }}}