Wsh Semantics

Class Hierarchy

  • syntaxVariables: the corresponding construct
  • String with instances string
  • Object with instances object
    • Run with instances run: contain (compiled) code and can be executed (run) with (or without) arguments
      • File with instances file: files allow reading and writing. run will read whole file and write contents to stdOut

kindnameexpression yieldsliteral textdescritptin
.objectobjectrexxis interpreted as a rexx expression interwoven with '$'primary
-stringstringrexxis interpreted as a rexx expression interwoven with '$'primary
=skeletonstringliteral constantis a skeleton, with '$'primary as variable parts
#literalstringliteral constantliteral constant, no interpretation of $, except for detection of stopper
@codecoderexx statementrexx statements with '$'primary, in blocks with rexx line continuation (,)
:pure wsh------only wsh statements, with most $ superfluous - no expressions
%run outputfilevar argumentsruns the contents of variable (must be subclass of ORun) with the givgen arguments and yields the contents of the produced stdOut as file
^run returnString or Objectvar argumentsruns the variable (subclass of ORun) with the givgen arguments and yields what is returned by a rexx return statement
  • exprStmts the statements are executed and the expressions evaluated and written to stdOut. The sematics changed after a withNew or table statement, see further down. $$ statements are handled as expression - which may be of a different kind.
  • @ run stmt
    • '@' kind? block: the block is executed with default kind of @.
    • '@'oPrBlEx: the oPrBlEx is evaluated, casted with 2run and run
  • $$ output stmt
    • '$$' oPrBlEx the oPrBLEx is evaluated with default kind = and written to stdOut

op: Operators (all unary)

  • . 2object → Object:
    • .var: the varPool is accessed with vGet(var) and the yield treated as an object (no conversion!)
    • .block: the block is executed yielding the singleton of the output
    • .String: the value of the string as an object
    • .Object: identity
  • @ 2run → Run (attention the @ statement does something else!):
    • @block or @expression: yields a run. running it executes the block
    • @Run Identity (run of File reads the file and writes it to stdOut
    • otherwise fail
  • < 2file → File:
    • f → identical file
    • r → output of execution of run, arguments are supplied only by £ expression, returnValue is discarded
    • s → fileSystem file with string as filespec
    • b → 2file 2str block. new: before contents of block - now <@b or pipe syntax needed
    • o → dynamically as r, f or s
  • - 2string → String:
    • s → identical String
    • f → if all objects of f are Strings then concatenate f (with separating ' ') otherwise fail
    • b, r → 2string of 2file
    • o → dynamically as r, f or s
  • ! singleton → Object:
    • f → if f contains a single object then this object otherwise fail
    • else → singleton of 2file
  • ? 0or1 → Object:
    • f → if f is empty then null else if f contains a single object then this object otherwise fail
    • else → 0or1 of 2file
  • . 2object → Object:
    • b → singleton of output of execution of block
    • s → stringValue as object
    • else → identity
  • % runOut: oRun object, output yields result
  • ^ runRet: oRun object, return value yields result
  • ( close: bracket by ( ) or do end, if necessary internal only

wlkl

ast kind

  • 'S' String Constant
  • 'O' Object Constant
  • '.' rexx expression yielding object (if .0 = 0 in text else in stems)
  • '-' rexx expression yielding string (if .0 = 0 in text else in stems)
  • '='
  • '@'
  • '#'
  • '£'
  • '<'
  • '^'
  • '!'
  • '?'

offen

  • rexx Variables scopes versus block nesting und interprets
  • jBuf = File Contents Store formalisieren
  • ??

Classes

  • b: Block
  • s: String
  • o: Object
  • f: File
  • r: Run: execute some code with (or without) arguments, yield return value or output

Semantics

wshInt: compile some separate wshUnits, and add the sequence of units to m.code

  • kind: compile the following wshUnit with this kind
  • '*': everything is comment up to the next nl'$#'
  • hook: extend wsh by
    • if name is a registered hook (case insensitive!) execute the registered code
    • otherwise (try to) execute call wshHook<name> m, hook
    • in both cases the hook gets the current instance of the compiler as argument, and can do i.e.:
      • call compSepUnit m, ... to compile the following unit
      • use m.scan to compile some code itself and add it to m.code (to be executed later)
      • execute the already compile code, modify m.code etc.

op: Operators (all unary, except execution ???? by < or ^ which get arguments from £ expression)

  • & variable Access→ Object: new: was only implicit, is it really necessary as expicit op?
    • any → variableAccess of 2string
    • r → returned value of execution of run, output is appended to stdOut, arguments are supplied only by £ expression, fail if no value returned
    • o → dynamically as r
    • else → fail
  • @ 2run → Run:
    • b → run = execution of the block
    • r → identical Run
    • f → run = read file and write each object read to stdOut,
    • o → dynamically as r, f
    • else → fail
  • < 2file → File:
    • f → identical file
    • r → output of execution of run, arguments are supplied only by £ expression, returnValue is discarded
    • s → fileSystem file with string as filespec
    • b → 2file 2str block. new: before contents of block - now <@b or pipe syntax needed
    • o → dynamically as r, f or s
  • - 2string → String:
    • s → identical String
    • f → if all objects of f are Strings then concatenate f (with separating ' ') otherwise fail
    • b, r → 2string of 2file
    • o → dynamically as r, f or s
  • ! singleton → Object:
    • f → if f contains a single object then this object otherwise fail
    • else → singleton of 2file
  • ? 0or1 → Object:
    • f → if f is empty then null else if f contains a single object then this object otherwise fail
    • else → 0or1 of 2file
  • . 2object → Object:
    • b → singleton of output of execution of block
    • s → stringValue as object
    • else → identity
  • % runOut: oRun object, if a result needed, output is used, with arguments if there is a call
  • ^ runRet: oRun object, yielding return value, with arguments if there is a call
  • ( close: bracket by ( ) or do end, if necessary internal only

primary

  • String oder Object je nach Anfangs . oder -, default abhängig von kind der expression
  • sConst String Konstante → String
  • name: variable access mit dem Name → Object
  • block:
    • /.../ kein Block sondern /BlockEnd
    • {...} [...$] Variable access mit BlockKind =
    • op+block: block kind vom letzten Operator bestimmt: <→=, andere→.

expR hängt von kind ab

  • ., -: rexx expression, noDo+ ist Teil der expression und wird mit primaries zusammen konkatiniert (mit rexx space Logik)
  • @: rexx statements primaries werden wie oben zusammenkonkatinert, als Teil von expressions in den statements
  • =: skeleton noDo+ ist konstanter unveränderterter text mit primaries zusammen konkatiniert
  • #: Literal Text, $ werden nicht interpretiert

unitR statements und expressions, in 0 - n Zeilen, abhängig von kind. für jede Expression wird ein statement generiert und dann alles ausgeführt

  • .: jede Expression wird als Object auf stdOut geschrieben - falls ein table statement aktiv ist, wird jede expre in subexpressions aufgeteilt und in ein neuer Objekt abgelegt
  • -, =: jede Expression wird als String auf stdOut geschrieben
  • @: Expression werden als rexx Statements ausgeführt, Commas als rexxLineContinuation werden unterstützt
  • #:

TextCopy

  • .:
  • -:
  • =:
  • @:
  • #:

old

The following table gives the semantics of the operators. It is read from top downwards: the first matching entry (operator, from kind and conditition) is applied.

From and to rows contain extended kinds. The alphabetic character is used as a variable in the explaination or Rexx. The preceeding special character corresponds to the kind

extended kinds

  • b a block with elements (expressions), b1, b2, ...
  • ; c: rexx code, pseudoKind ;. kind @ from the syntax is often directly lifted to ; c (this may be documented later)
  • . j: object of class JRW
  • . r: object of class ORun, includes . j
  • . o: Object of any class includes . r and . j
  • - s: String
  • a: anything

conditions

  • aE: if each element of a block is . or -. The optimization with this condititon is semantically equivalent to the following definition without the exception, if none of the expression has side effects
opfromcotoresultrexx
-baE-cocatenates each line (- bi) casted to string, separated by 1 space 
-b --; b 
-; c -executes c and concatenates (- oi) for each output oi separated by one space 
-. r --@ro2string(r)
-- s -identys
-. o -depending of class of o select correct cast from aboveo2String(o)
.b .!; b 
.- s .cast string to strWs2o(s)
.; c . ryields an ORun with code c as oRun methodoRunner(c)
.. o .identityo
<b . j<@b 
<; c . jyields jBuf with output of execution of co2file(oRunner(c)))
<- s . jfile with fileSpec sfile(s)
<. j . jidentiyj
<. o . jif String or JRW as above, otherwise <@oo2file(o)
!baE.yields (. b1) if b has exactly on element otherwise fails 
!. j .reads j. returns first line read. Fails if 0 or more than 1 lines readable 
!; c .!<c 
?baE.yields null if b is empty, (. b1) if b has exactly 1 element, otherwise fails 
?a .analogous to ! 
;; b ;execute each (; bi) element of the block casted to ; 
;- s ;write s to stdOutcall out s
;. o ;write o to stdOutcall outO o
;; c ;execute c 
@b ;; b 
@. j ;reads j writes each line read (casted to obj) to stdOutcall jWriteAll j
@. o ;runs ooRun(o)
@; c ;executes c 

This semantics table is far from complete

  • Expression are not documented yet. This will be done, when they are migrated to AST.
  • there are further features for : ! which non atomically create/updates objects, the current with is used to remember the currenty object to update
    • directly in a with ( $@with obj $@:[... or $@with obj $@![...) the with object obj is updated
    • a singleton assignment like [" obj =:[...@] or obj =![... is converted to a with obj $@:[, if obj is null, it is created from the class of obj if it is declared, or the class deduced from the assignment block.
    • a multi assignment to a stem like obj.st =<:[... or obj.st =<![... will set the stem size to zero, and then initialize the next stem element, use it as the with object and update it.
    • In all other cases each element is created from the class deduced from the assignment block, used as the with object and updated. And the block yields just the sequence of elements created
    • still missing is syntax for an explicit class in : and ! blocks (wshDis