WL Programming Language Specification

The WL programming language (pronounced Wool) contains a strict subset of the features of Java and C. A WL source file contains exactly one procedure definition.

Lexical Syntax

A procedure definition is a sequence of tokens optionally separated by white space consisting of spaces, newlines, or comments. Every valid token is one of the following: White space consists of any sequence of the following: Any pair of consecutive tokens may be separated by white space. Pairs of consecutive tokens that both come from one of the following sets must be separated by white space: Tokens that contain letters are case-sensitive; for example, int is an INT token, while Int is not.

Context-free Syntax

A context-free grammar for a valid WL program is:

Context-sensitive Syntax

Any ID in a sequence derived from dcl is said to be declared. Any ID in a sequence of tokens derived from statement or factor is said to be used. Any particular string x that is an ID may be declared at most once. A string x which is an ID may be used any number of places, but only if the same string x is declared. String comparisions are case sensitive; for example, "FOO" and "foo" are distinct.

Semantics

The meaning of a syntactically correct WL program is defined by transforming it to an equivalent Java program; the semantics of the Java program are identical to those of the WL program.

A syntactically correct WL program may alternatively be transformed into a C++ program with the same meaning.

Meaning in Java

Any WL program that obeys the syntax rules above is a valid Java program fragment. The meaning of the program fragment is identical to that of the Java program formed by inserting it at the indicated location in the following Java program shell:
class WL {
    public static void main(String[] args) {
       println(wain(Integer.parseInt(args[0]),
                    Integer.parseInt(args[1])));
    }
    static void println(int x) { System.out.println(x); }
    static 

// === Insert WL Program Here ===

}
The resulting program takes two integer command line parameters, passes them as arguments to the WL program, and prints the result of the WL program to standard output.

Equivalent Meaning in C++

Any WL program that obeys the syntax rules above is a also a valid C++ program fragment. The meaning of the program fragment is identical to that of the C++ program formed by inserting it at the indicated location in the following C++ program shell:
int wain(int, int);
void println(int);

// === Insert WL Program Here ===

#include <stdlib.h>
#include <stdio.h>
int main(int argc, char **argv){
   int r = wain(atoi(argv[1]),atoi(argv[2]));
   printf("%d\n",r);
}
void println(int x){
   printf("%d\n",x);
}