Changes between Initial Version and Version 1 of SGISyntax


Ignore:
Timestamp:
2017-06-30 05:46:50 (7 years ago)
Author:
archibald
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • SGISyntax

    v1 v1  
     1= SGI Statement Syntax = 
     2[[TOC]] 
     3==== a generator file contains ==== 
     4{{{ 
     5#!c 
     6SGI := { statementClause }*; 
     7}}} 
     8An SGI script is made up from a number of statement clauses. 
     9 
     10==== statementClause ==== 
     11{{{ 
     12#!c 
     13statementClause := ( outputClause | informClause | defineClause 
     14    | ifClause | whileClause | forClause | switchClause | expressionClause 
     15    | filingClause | returnClause | localDefinition | loopControl 
     16    | blankClause ) ; 
     17}}} 
     18A statement clause could be one of ... 
     19 * an output clause; 
     20 * an inform clause; 
     21 * a define clause; 
     22 * an if clause; 
     23 * a while clause; 
     24 * a for clause; 
     25 * a switch clause; 
     26 * an expression clause; 
     27 * a filing clause; 
     28 * a return clause; 
     29 * a local data definition clause; 
     30 * a loop control clause or 
     31 * a blank clause 
     32 
     33==== loopControl ==== 
     34{{{ 
     35#!c 
     36loopControl := ( "break" | "continue" ) ";" ; 
     37}}} 
     38A loop control clause is either 
     39 * a break command or 
     40 * a continue command 
     41however, the result of executing such a command outside a loop is unknown. 
     42 
     43==== filingClause ==== 
     44{{{ 
     45#!c 
     46filingClause := 
     47    ( "create" expression "{" { statementClause }* "}" 
     48    | "section" expression "{" { statementClause }* "}"  
     49    | "drop" expression { "," expression }* ";"  
     50    | "flush" expression { "," expression }* ";"  
     51    ); 
     52}}} 
     53The 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. 
     54 
     55Within 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. 
     56 
     57Within the compound statement of a create statement, a predefined section can be discarded or dropped. 
     58 
     59 
     60Within the compound statement of a create statement, an identified buffered section can be flushed to the output file. 
     61 
     62see FilingClauseExample 
     63 
     64==== blankClause ==== 
     65{{{ 
     66#!c 
     67blankClause := 
     68  ( ";" 
     69  | ">>" 
     70  | "<<" 
     71  | "@" 
     72    ( "vdump" 
     73    | "adump" 
     74    | "dump" 
     75    | "fdump" 
     76    ) 
     77  ); 
     78}}} 
     79a blank clause does not affect the use output.  It consists of one of the following, 
     80 * no operation 
     81 * increase the level of indentation 
     82 * decrease the level of indentation 
     83 * inform the user 
     84  * dump the list of variables 
     85  * dump the list of aliases 
     86 
     87==== ifClause ==== 
     88{{{ 
     89#!c 
     90ifClause := "if (" expression ")" "{"  compoundStatementClause "}" 
     91  ( "else {" compoundStatementClause "}" 
     92  | "" 
     93  ); 
     94}}} 
     95An "if clause" is similar to that found in C-Code, with its dangling "else". 
     96 
     97==== informClause ==== 
     98{{{ 
     99#!c 
     100informClause := "inform (" expression 
     101  { 
     102    ( expression { "," } 
     103    | "[" 
     104      { 
     105        expression 
     106        { 
     107          "," 
     108        } 
     109      }* 
     110      "]" 
     111    ) 
     112  }* 
     113  ")"; 
     114}}} 
     115An inform clause is similar to an output clause, except that the inform clause output goes to the console. 
     116 
     117==== outputClause ==== 
     118{{{ 
     119#!c 
     120outputClause := "[" 
     121  { 
     122    ( "," expression 
     123    | expression 
     124    | "[" 
     125      { 
     126        ( "," expression 
     127        | expression 
     128        ) 
     129      }+ 
     130      "]" 
     131    ) 
     132  }+ 
     133  "]"; 
     134}}} 
     135An 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. 
     136 
     137==== whileClause ==== 
     138{{{ 
     139#!c 
     140whileClause :=  "while (" expression ")" "{" compoundStatementClause "}"; 
     141}}} 
     142The "while clause" is similar to that found in C-Code. 
     143 
     144==== forClause ==== 
     145{{{ 
     146#!c 
     147forClause := 
     148  ( "for each" ident "in" expression 
     149    { 
     150      "where" 
     151      ( expression 
     152      | "(" expression ")" 
     153      ) 
     154     } 
     155     "{" compoundStatementClause 
     156  | "for ("  expression ";" expression ";" expression ")" "{" compoundStatementClause "}" 
     157  ); 
     158}}} 
     159The 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.                     
     160 
     161==== switchClause ==== 
     162{{{ 
     163#!c 
     164switchClause := "switch (" expression ")" "{" 
     165  { 
     166    caseClause 
     167  }+ 
     168  ( "default" "{" compoundStatementClause "}" 
     169  | "" 
     170  ) 
     171  "}"; 
     172}}} 
     173 
     174==== caseClause ==== 
     175{{{ 
     176#!c 
     177caseClause := "case" expression 
     178  { 
     179    "," expression 
     180  }* 
     181  "{" compoundStatementClause "}"; 
     182}}} 
     183 
     184==== expressionClause ==== 
     185{{{ 
     186#!c 
     187expressionClause := expression ";"; 
     188}}} 
     189An expression clause executes an assignment or function call. 
     190 
     191==== expression ==== 
     192{{{ 
     193#!c 
     194expression := andClause 
     195  { 
     196    "||" expression 
     197  }* 
     198  { 
     199    "?" expression ":" expression 
     200  };  
     201}}} 
     202An expression consists of an "andClause" and a number of logical-or sub-expressions with an optional ternary operator. 
     203 
     204 
     205==== andClause ==== 
     206{{{ 
     207#!c 
     208andClause := bitOrClause 
     209  { 
     210    "&&" andClause 
     211  }*;  
     212}}} 
     213an andClause consists of a bitwise or clause with optional number of logical and sub-clauses. 
     214 
     215==== bitOrClause ==== 
     216{{{ 
     217#!c 
     218bitOrClause := bitXorClause 
     219  { 
     220    "|" bitOrClause 
     221  }*;  
     222}}} 
     223a bitwise or clause consists of a bitwise exclusive-or clause followed by an optional number of bitwise-or operators with sub-clauses. 
     224 
     225==== bitXorClause ==== 
     226{{{ 
     227#!c 
     228bitXorClause := bitAndClause 
     229  { 
     230    "^" bitXorClause 
     231  }*; 
     232}}} 
     233a bitwise xor clause consists of a bitwise and clause followed by an optional number of carret and another bitwise xor clauses. 
     234 
     235==== bitAndClause ==== 
     236{{{ 
     237#!c 
     238bitAndClause := equalityClause 
     239  { 
     240    "&" bitAndClause 
     241  }*; 
     242}}} 
     243 
     244==== equalityClause ==== 
     245{{{ 
     246#!c 
     247equalityClause := comparativeClause 
     248  { 
     249    ( "==" equalityClause 
     250    | "!=" equalityClause 
     251    ) 
     252  }*; 
     253}}} 
     254 
     255==== comparitiveClause ==== 
     256{{{ 
     257#!c 
     258comparativeClause := shiftClause 
     259  { 
     260    ( "<" comparativeClause 
     261    | "<=" comparativeClause 
     262    | ">=" comparativeClause 
     263    | ">" comparativeClause 
     264    ) 
     265  }*; 
     266}}} 
     267 
     268==== shiftClause ==== 
     269{{{ 
     270#!c 
     271shiftClause := additionClause 
     272  { 
     273    ( "<<" shiftClause 
     274    | ">>" shiftClause 
     275    | ">>>" shiftClause 
     276    | "<<<" shiftClause 
     277    ) 
     278  }*; 
     279}}} 
     280 
     281==== additionClause ==== 
     282{{{ 
     283#!c 
     284additionClause := multiplyClause 
     285  { 
     286    ( "+" additionClause 
     287    | "-" additionClause 
     288    ) 
     289  }*; 
     290}}} 
     291 
     292==== multiplyClause ==== 
     293{{{ 
     294#!c 
     295multiplyClause := unaryClause 
     296  { 
     297    ( "*" multiplyClause 
     298    | "/" multiplyClause 
     299    | "%" multiplyClause 
     300    ) 
     301  }*; 
     302}}} 
     303 
     304==== unaryClause ==== 
     305{{{ 
     306#!c 
     307unaryClause := 
     308  ( "!" unaryClause 
     309  | "-" unaryClause 
     310  | "~" unaryClause 
     311  | "(" expression ")" 
     312  | functionalClause 
     313  | baseClause 
     314  ); 
     315}}} 
     316 
     317==== functionClause ==== 
     318{{{ 
     319#!c 
     320functionClause := 
     321  ( "size (" expression ")" 
     322  | "number (" expression ")" 
     323  | "lower (" expression ")" 
     324  | "asc (" expression ")" 
     325  | "chr (" expression ")" 
     326  | "upper (" expression ")" 
     327  | "commandLine (" expression ")" 
     328  | "capital (" expression ")" 
     329  | "next" 
     330    ( "(" expression ")"    /* next item in list */ 
     331    | ident "(" expression  /* next in search */ 
     332      { 
     333        "," expression 
     334      }+ 
     335      ")" 
     336    ) 
     337  | "prev (" expression ")" 
     338  | "empty (" expression ")" 
     339  | "count (" expression ")" 
     340  | "contains (" expression "," expression ")" 
     341  | "open (" expression ")" 
     342  | "close (" expression ")" 
     343  | "read (" expression ")" 
     344  | "eval (" lambdaExpression | stringExpression ")" 
     345  | "exec (" lambdaStatement | stringExpression ")" 
     346  | "daTime" 
     347  | "wait" 
     348  | "new" ident "(" { expression { "," expression }* } ")" 
     349  | "free" ident "(" expression ")" 
     350  | "link" ident "("    expression "," expression ")" 
     351  | "unlink" ident "(" expression  ")" 
     352  | "link new" ident "(" expression { "," expression }* ")" 
     353  | "unlink free" ident "(" expression  ")" 
     354  | "find" ident "(" expression { "," expression }* ")" 
     355  | "find or link new" ident "(" expression { "," expression }* ")" 
     356  ); 
     357}}} 
     358see the ListOfFunctionalClauses 
     359 
     360==== baseClause ==== 
     361{{{ 
     362#!c 
     363baseClause := 
     364  ( number 
     365    ( "." number 
     366      { 
     367        ( "e" 
     368        |"E" 
     369        ) 
     370        number 
     371      } 
     372    | ( "e" 
     373      | "E" 
     374      ) 
     375      number 
     376    | "" 
     377    ) 
     378  | "({" compoundStatement "})" /* lambda statement */ 
     379  | "<{" expression "}>"        /* lambda expression */ 
     380  | litteral 
     381  | "++" identifier 
     382  | "--" identifier 
     383  | identifier 
     384    { 
     385      ( "++" 
     386      | "--" 
     387      | "(" 
     388        { 
     389          expression 
     390          { 
     391            "," expression 
     392          }* 
     393        } 
     394        ")" 
     395      | assignop 
     396      | "" 
     397      ) 
     398    } 
     399  ); 
     400}}} 
     401 
     402==== assignop ==== 
     403{{{ 
     404#!c 
     405assignop := 
     406  ( "=" expression 
     407  | "+=" expression 
     408  | "-=" expression  
     409  | "*=" expression  
     410  | "/=" expression  
     411  | "%=" expression  
     412  | "&=" expression  
     413  | "|=" expression  
     414  | "^=" expression  
     415  | "&&=" expression  
     416  | "||=" expression  
     417  | ">>=" expression  
     418  | "<<=" expression  
     419  | "<<<=" expression  
     420  | ">>>=" expression  
     421  ); 
     422}}} 
     423 
     424==== identifier ==== 
     425{{{ 
     426#!c 
     427identifier := ident 
     428  { 
     429    ( "[" expression "]" 
     430    | { 
     431        "." ident 
     432      }+ 
     433    ) 
     434  }* 
     435  { 
     436    "->" ident 
     437  }*; 
     438}}} 
     439The "->ident" clause only applies to interpreters that "own" a data schema. 
     440 
     441==== defineClause ==== 
     442{{{ 
     443#!c 
     444defineClause := "function" ident "(" 
     445  { 
     446    singleParam 
     447    { 
     448      "," singleParam 
     449    }* 
     450  } 
     451  ")" functionDefinitionBit; 
     452}}} 
     453A function definition looks like this ... 
     454{{{ 
     455#!c 
     456function apply();            /* for a prototype  or ... */ 
     457function apply() { return; } /* for a real function */ 
     458}}} 
     459 
     460==== singleParam ==== 
     461{{{ 
     462#!c 
     463singleParam := 
     464  ( ident 
     465  | "$" ident 
     466  );  
     467}}} 
     468each function parameter is either passed by value or passed by reference. 
     469 
     470==== localDefinition ==== 
     471{{{ 
     472#!c 
     473localDefinition := "local" ident 
     474  { 
     475    "," ident 
     476  }* 
     477  ";"; 
     478}}} 
     479defines a local variable ...  
     480 
     481==== functionDefinitionBit ==== 
     482{{{ 
     483#!c 
     484functionDefinitionBit := 
     485  ( "{" compoundStatementClause "}" 
     486  | ";" 
     487  ); 
     488}}} 
     489a function definition is either a prototype or a full function definition with a compound statement. 
     490 
     491==== returnClause ==== 
     492{{{ 
     493#!c 
     494returnClause := "return" 
     495  ( expression 
     496  | "" 
     497  ) 
     498  ";"; 
     499}}} 
     500returns from a function with the value of an expression or NULL. 
     501 
     502==== SGI imported C libraries ==== 
     503{{{ 
     504#!c 
     505uartFunctions :=  
     506  { openSerialPort(expression) 
     507  | sendChar(expression, expression) 
     508  | recvChar(expression) 
     509  | closeSerialPort(expression) }; 
     510 
     511pipeFunctions := 
     512  { psopen(expression) 
     513  | pcopen(expression) 
     514  | pputc(expression,expression) 
     515  | pgetc(expression) 
     516  | pclose(expression) }; 
     517 
     518winFunctions := 
     519  { msgBox(expression,expression,expression) 
     520  | MessageBox(expression,expression,expression,expression) 
     521  | MSG_OK 
     522  | MSG_OKCANCEL 
     523  | MSG_ABORTRETRYIGNORE 
     524  | MSG_MSG_YESNOCANCEL 
     525  | MSG_YESNO 
     526  | MSG_RETRYCANCEL 
     527  | MSG_CANCELRETRYCONTINUE 
     528  | MSG_WARNING 
     529  | MSG_INFO 
     530  | MSG_ERROR 
     531  | MSG_QUESTION } 
     532}}}