Menu

Wirthless Level 0

Phillip Kilgore

Wirthless Level 0 (WL0) is the first iteration of the [Wirthless] programming language. It consists of three statement types and can manage up to 26 variables, but it can do little else.

Language Specification

Below is the language specification in Wirthless's augmented [BNF].

Lexemes

var := [A-Z]
num := 0 | -?[1-9][0-9]*
str := '"' ( [^\\"] | '\\' . )* '"'

Grammar

program := (statement ';')*

statement := assignment | print | read

assignment := var '=' expr | string
expr := expr [+-] term
term := term [*/%] factor
factor := var | num | '(' expr ')'

print := "print" value-list
value-list := value ( ',' value )*
value := string | num | expr

read := "read" var

Semantics

The Assignment (=) Operator

The assignment operator evalutes its right operand and stores the value in the variable specified by its left operand. Unlike most other languages, assignment is not an expression; thus, a form such as "A = B = C" is not well-formed. The right operand may either be a string or an expression.

The Plus (+) and Minus (-) Operators

The plus and minus operators respectively add and subtract their operands. These operators are left-associative. Addition and subtraction have the following properties in WL0:

  • Adding two positive numbers yields a positive number unless overflow occurs.
  • Adding two negative numbers yields a negative number unless overflow occurs.
  • The subtraction of two positive numbers yields a positive number if the left operand is greater than the right operand; otherwise, it yields a negative number.
  • The subtraction of two negative numbers yields a negative number if the left operand's absolute value is greater than the right operand; otherwise, it yields a positive number.
  • If the right operand is negative, then the addition follows the same rules as subtraction.

The Multiply (*), Divide (/), and Modulo (%) Operators

The multiple, divide, and modulo operators respectively multiply, divide, and take the remainder of their operands. These operators are left-associative. Multiplication has the following properties in WL0:

  • Multiplying two positive numbers yields a positive number unless overflow occurs.
  • Multiplying two negative numbers yields a positive number unless overflow occurs.
  • The multiplication a positive and negative number negative iff they have different signs; otherwise, the result is positive.

Division has the following properties in WL0:

  • The division operator performs "integer division"; only the whole part of the resulting number will be captured.
  • The signedness of division is the same as with multiplication.
  • The result of dividing by or taking the modulus by zero is undefined.

The modulo operator has the following properties in WL0:

  • The modulo operator shall be equivalent to (A - A / B), where A and B are operands.
  • The signedness of the modulo is the same as with multiplication.
  • Taking the remainder by zero is undefined.

The Grouping "()" Operator

The "print" Keyword

The print keyword contatenates its operands in the order they appear and prints the result to standard output. The print keyword is right-associative.

The "read" Keyword

The read keyword reads the next line from standard input and stores it in its operand. The value is coerced to a number if possible; otherwise, it is stored as a string.

Discussion

WL0 is a context-free language and specifically violates the pumping lemma for regular languages because its grouping operator. Because of its limited storage and lack of mechanism for looping, WL0 is not [Turing Complete]; as such, there are certain programs it is not capable of expressing.

DLP Units

WL0 is featured in the following units of [Developing A Programming Language]:


Related

Wiki: DLP Unit 1
Wiki: Wirthless