Symbols
W is a minimalist language. In W, every symbol is a 16-bit value. In program code, symbols are evaluated as follows:
X() | Execute code at address X |
X | Take the value found at address X |
#X | Take address X |
@X | Take the value pointed to by the value found at address X |
X[n] | Take the value found at address X+2n |
X := | Allocate 2 bytes of memory (local or global) and assign its address to X |
X() := | Begin a new program subroutine and assign its start address to X |
X[n] := | Allocate n (n is a constant expression) 2-byte words of memory, and assign the start address to X |
Operators and Precedence
Unary operators | # @ + - ~ | Highest precedence
Lowest precedence |
Binary operators | << >> & * / % | + - > < >= <= == != && || = |
Comments and Whitespace
Whitespace characters may be used to separate syntactical elements and resolve ambiguities. Otherwise, whitespace characters (specifically, the space, tab, carriage return, and newline characters) are ignored.
For the purposes of compilation, characters between a semicolon appearing not between a pair of single or double quotes, and the end of the line, are ignored. Thus, the semicolon can be used to add comments to the source code.
Language Elements
program := definition [definition...] definition := declarator ':=' initializer [',' initializer] initializer := primary-expression | undefined-expression declarator := function-declarator | array-declarator | symbol function-declarator := symbol '(' [symbol[',' symbol...]] ')' array-declarator := symbol '[' constant-expression ']' primary-expression := compound-expression | constant_expression | simple-expression |
conditional-expression conditional-expression := primary-expression '?' primary-expression [',' primary-expression] compound-expression := '{' [primary-expression | definition...] '}' undefined-expression := '?' simple-expression := unary-expression [binary-operator unary-expression...] unary-expression := [unary-operator...] (function-call | array-dereference | atomic-expression) atomic-expression := literal | symbol | ( '(' primary-expression ')' ) function-call := atomic-expression '(' [primary-expression[',' primary-expression...]] ')' array-dereference := atomic-expression '[' primary-expression ']' binary-operator := '&' '*' '/' '%' '|' '+' '-' '>' '<' '>=' '<= '==' '!=' '=' '<<' '>>' '&&' '||' unary-operator := '#' '@' '+' '-' '~' '!' constant-expression := [unary-operator] ((number [binary-operator constant-expression]) |
'(' constant-expression ')' ) symbol := alphabetic [alphanumeric...] alphanumeric := alphabetic | digit alphabetic := 'a'..'z' | 'A'..'Z' | _ literal := string | character | number string := '"' [character-literal...] '"' character := ''' character-literal ''' character-literal := printable-ASCII-character | special-character special-character := '\\' | '\n' | '\x' hex-digit hex-digit number := [ '0x' ] digit[digit...] sign := '+' | '-' hex-digit := digit | 'a'..'f' | 'A'..'F' digit := '0'..'9'
Return Value
The return value of a function is the value of the expression on the right-hand side of a function declaration. The return value of a compound expression is the return value of the last expression within the compound expression.