Bobcat -- A language that is like Tiger
, but smaller and less frightening.
Bobcat is designed to let us look at some issues of compiling expressions,
flow control statements, and local variables, while ignoring many of the more
sophisticated issues that arise in a complete compiler such as the Tiger
compiler for CS350. Bobcat is, for the
most part, a subset of Tiger.
Bobcat language guide
A Bobcat program is made up of a sequence of variable and function
declarations, with comments allowed anywhere whitespace is allowed. Comments
are any text within /* and */ (possibly multiple lines). Declarations have
the form
var name : type
var name : type
:= expression
(for a variable), or
function name (
name: type, name : type ... ) =
(
expression;
expression;
...
)
(for a function). A type
may be either int
or double
; An expression
may be any of the following:
- A constant such as 17
or 3.14159.
- A variable that is in scope (either a global or a parameter).
- A non-destructive binary C operation such as +, -, *, /, %, &&,
&, >, ==, etc, applied to two (possibly parenthesized) subexpressions.
- An assignment var := expression;
As in C, the value of the assignment expression is the value assigned.
- if expression
then expression else expression (the
first expression must have type int; if it is zero, the value is given by the
third expression; if not, the value is given by the second expression).
- while expression
do expression (the second expression is repeatedly
evaluated, as long as the first (which must have type int) is non-zero). The
result is always zero.
- name(expression,
expression, ...), which calls the named function. The
result is the value of the last expression given in the function.