Simple Calculator Language ("Clang," pronounced "clang!")
Clang is a very simple imperative language for writing programs that
perform calculator-like computations. It consists of three statement types:
input, assignment, and show. Here is an example clang program:
input "Enter the value of a:" a;
input "Enter the value of b:" b;
input "Enter the value of c:" c;
discrim := b^2-4*a*c;
discroot := discrim^(.5);
show "root1 is", (-b+discroot)/(2*a);
show "root2 is", (-b-discroot)/(2*a);
The syntax and semantics of this language should be fairly
intuitive to most programmers. Here are a few things to note:
- There are just two data types: numbers and strings. All
numbers are represented as floating point values.
- String literals are indicated with double quotes.
- A semi-colon is used to terminate each statement (end
of lines are just like any other white space)
- An input statement has exactly 1 prompt and 1 variable.
- A show statement takes zero or more expressions separated by commas.
- There are no string operations; The numeric operators
are + - * / and ^ with the usual association and precedence rules.