Wsh4 Semantic Notes

Universe U = disjoint union of

  • Bool = {true, false}
  • Nat = {0, 1, ...}
  • Obj: U → U
    • inheritance to class?
  • Code ???

State S

  • Store: Obj
  • Stack of
    • Activation Records
      • local/temporary Vars
      • CodePoint

Version from 2.1.2011

block: the semantics of a block is completely defined only in the context obOp kind block:
kind @Run, default op @ (identical), operator is simply applied to Run
kind = - # ⇒ sequence of strings, defalut op - concat
kind . : ! ⇒ sequence of objects, default op ! singleton
for sequences of elements:
operator < ⇒ file containing the sequence of elements (equivalent to copy elements to JBuf)
operator @ ⇒ a Run which writes the sequence of elements to stdOut
operator - ⇒ concat elements casted to string
operator ! ? ⇒ first element
operator . ⇒ fail
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
this is still rather messy, and it is not clear whether this should be implemented as syntactical sugar or as a concept. The primary goals are
  • allow simple assignment syntax as input interface for tools
  • easy definition of tables
  • abbreviation for muliple assingments
  • still missing is syntax for an explicit class in the WA
one alternative would be
  • singleton assStmt directly in a with simply updates current with (plus with for current stmt)
  • singleton assStmt directly in a assignment simply updates current assTarget (with new form typeInfo if null)
  • all other assStmt locally create a sequence of objects
  • the assingment Operator will copy to stem with correct subtypes etc.
second alternative
  • in the AST put a special type: WA = withAssignment: (class, assStmts) (wheter class is explicit or in the code of assStmts is an implementation variant,
  • allow stdOut to contain typing infos
  • WA uses WABegin, WANext adn WAEnd that in combination with the typeInfo in stdOut will keep the current with, push an old obj to with or push a new obj to with. The new is from class in stdOut typeInfo if unspecified form class parms in WABegin/Next.
  • This eliminiates the complexitiy of muClass in with, and it works also with a pushWith before the WA

copy of syntax ....

wsh = cUnit ? ( '$#' name '#' kind cUnit )* ( ( '$#end' | '$#out' ) litText )
wsh input consists of a compilation unit possibly followed by named compilation units, that are put into the variable pool. This allows to combine the arguments to the interpreter and several fragments of the source file.
cUnit = unit ? ( '$#' kind unit )*
a compilationUnit consists possibly of an unit of implicit kind, possibly followed by units of explicit kind.
unit = data | shell | assAtt | assTab | litText
A unit with implicit kind, which is determined by the environment
data = ( spCom* | expr) (nl (expr | sp* comment spCom* )* (nl spCom* )? (stmt data )*
Defines line oriented data and consists of expressions and statements.
  • All expressions are of the same kind or constant
  • Partial lines (i.e. at begin, end or beside a stmt) are ignored, if they consist only of spaces and comments.
  • Empty lines with comments are also ignored
shell = pipe ? ('$;' pipe? )*
A pipe is a statement or language code with optional IO redirections. Caution: Semicolons without $ do not terminate a pipe but are part of the underlying language.
expr = (( noDo+ | primary ) comment* )+
expressions consists text (without dollars or newLines) and primaries, comments are ignored (i.e. substitued by 0 or 1 space depending on the context). The kind of the expression determines how text is interpreted.
exprS = spCom* expr spCom*
an expression with leading and trailing spaces stripped
exprB = spCom* (( noBr | primary ) comment* )+ spCom*
a type of expressions with texts without {}=, leading and trailing spaces stripped
exprW = (( word | primary ) comment* )+
an type of expressions with texts without (free) spaces or {}=
kind = '.' | '-' | '=' | ':' | '!' | '#' | '@'
there are 7 kinds with the following meaning
three flavours of data
. = object: text is rexx, expression yields an object reference
- = string: text is rexx, expression yields a string
= = skeleton: text is literal data, expression yields a string
three flavours of code (yielding an oRun)
@ = shell: text is rexx,
: = attribute assignments (of last with)
! = tabular assignments (of last with)
# = literal text: text without rexx or wsh interpretation
obOp = '.' | '-' | '<' | '@' | '!' | '?'
there are 6 object operators:
. = a2object: a string is lifted to an objectString, everything else unchanged
- = a2string: objectString to its value, conacatenates the contents of a File or Run (with one space between lines, files any line is no

string), otherwise fails

< = a2file: objectString to file with that specification, a Run to ???, otherwise fails
@ = a2run: a file or run as a run, ohterwise fails
! = exact1: if File or Run, extracts the only element of the content, fails if it contains 0 or more than 1 element, identiy on other objects
? = max1: File or Run, extracts the only element of the content, or null if it contains 0 elements. Fails if more than 1 element, identiy on other objects
primary = var | '$' sConst | '$.' obj | '$-' str
A primary is a variable expansion, a string constant, an object or a string expression
var ='$' name | '${' ( '?' | '>' )? exprB '}'
variable expansion to a string or an object depending on context). The form with braces allows options, nested variables and variable names that are not a name.
? yields 1 if variable is defined, 0 otherwise
> reads stdIn into variable, yields 1 if not at end
otherwise does a normal expansion
exprB yields an arbitrary variableName, possibly with nested variable expansions
obj = obOp* '<' file | block | obOp* primary | obOp* 'compile' kind
yields an object
! singleton operator
primary yields the primary casted to an object
block yields an instance of string, object, Run or File, depending on the kind of the block
file a file as an object
compile stdIn compiled as the specified kind to a Run
str = obj
A string term is syntactically the same as an object term, however it is casted differently. A file or a block yields its concatenated output etc.
file = block | kind? exprS
block: each line (or output) is a record of the file, default kind '='
exprS cast to file the exprS of the indicated kind (default '=') e.g. String as fileSpec.
block = (obOp* kind)? ( '{' unit '}' | '[' ( unit ) '$]' | '/' noSla* '/' ( unit ) '$/' noSla* '/' )
A block combines several expressions or statements in a single syntactical entitiy. The content of a block is evaluated as the indicated kind, the default is context dependent. For clarity, {} blocks do not allow nls. The slashes give label a block with the same label at the begin and end
exprBlo = block | kind? exprS
allows a block or an expression of a possibly specified kind
pipe = ioRedir stmts ( '$|' stmts )*
this is execution order, syntax order is more flexible
ioRedir = (('$<' | '$>' | '$>>') file spNlCom* )+
$< designates an input file, several input files are concatenated. An Output with $> replaces an existing file, $>> appends to it. Several Outputs are an error.
stmts = ( ( stmt | expr ) spNlCom* )+
expr yields rexx statements with trailing comma handling for rexx line continuations
stmt = '$=' ass
| ( '$@for' | '$@with' | '$@forWith' ) exprB stmt
| '$@ct' spCom* stmt
| '$@proc' exprB stmt
| '$@do' (spCom* name spCom* '=')? exprB stmt
| '$@' name '(' spCom* ')'
| '$@' name ( '-' | '.' )? '{' exprB '}'
| '$@' obj
| '$$' exprBlo
$@for readloop on stdIn, the read object is assigned to the variabe named exprB
$@ct executes the statement at compile time
$@proc declares the variable named exprB as a procedure (an instance of run) at compile time
$@do: rexx do logic, control variable assigned
$@name() run the procedure (oRun of the object in variable pool) of the given name
$@name?{exprB} run the procedure (object in variable pool) of the given name with exprB as arguments, the kind of exprB is given between name and {.
$@obj run the object
exprBlo writes the exprBlo to stdOut (default kind =, no cast)
ass = ( exprB '=')? exprBlo
assigns variable named exprB the contents of exprBlo.
  • If exprB is missing, the expr must be a named block, and its name is used as the name of the variable, e.g. $=/lines/ ... $/lines/
  • an assignment can address object in the variable pool, or an attritute at the end of an attribute chain of an object from the variable pool.
  • If the block is of kind attribute or tabular assignment then the addressed variable or attribute defines the environment for that block
assAtt = ( ass | stmt | ( '$'? (':' class | ':.' exprB)? ';' ) | spNlCom )*
the ass (without $) are confined to the latest with, typically from an assignment of the form .... =:... The semicolon (with or without $) create the next element of collection. This only works after =<: (replacment of old collection) or =<<: (append to old collection). Currently it only works for stems. The dollar before the block terminator (] or /../) can be omitted on the beginning of a new line or anywhere, the scanner can recognise it.
assTab = spNlCom? ( name spCom )* nl (spNlCom | stmt | (exprW spCom)+ nl )*
Multiple assignments in the form of a table. The list of names are the headers with the fieldName to be assigned to. Each line of exprWs assigns the fields of one element of a collection. Each expression must overlap with exactly on name from the header. All expression are of kind = and cannot contain free spaces - however $-string constants with spaces are ok (e.g. $" "). The rest is similar to assAtt.

Lexicals

sConst = '$''' ((* noNl not '''' *) | '''''')* '''' | '$"' ((* noNl not '”' *) | '””')* '”'' ''''
a string enclosed in single or double quotes, prefixed by a dollar. Inside, two quotes stand for a single one.
name = (* starting with a letter followed by any number of digits or letters, case sensitive! *)
nl = (* newLine character(s) or record switch *)
noNl = (* one character not nl *)
sp = (* one space character ' ', tab etc., but not nl *)
noDo = (* one character neither '$' nor nl *)
noSla = (* one character neither '/' nor nl *)
noBr = (* one character neither in '{}=' nor nl *)
word = (* one or more characters of noBr but not space *)
textB = ( noBr+ | '{' textB '}' )*
textLns = spCom* (nl noNl* )*
comment = '$**' noNl* | '$*+' noNl* nl | '$*(' (comment | sConst | noNl | nl )* '$*)'
$** starts a comment until the last character before next nl,
$*+ includes also the next nl (joins lines)
spCom = sp | comment
spNlCom = sp | nl | comment
litText = (* any number of any characters, newlines, etc. *)
uninterpreted text, with or without stopper, depending on the context