Computer Science Department, Bucknell University

CS360 Compiler Design Project
Programming Language Bisonita
Fall, 1996


The programming language Bisonita is a small language for the purpose of exploring compiler design theory. Bisonita is a language for creating animated colored line drawings on X-Windows based computers which support the Java Virtual Macine. Note that Bisonita has many features missing which one would expects a modern language to have, for example, no arrays, no classes, no file handling and no dynamic memory allocation.

Cosmetic Features

In Bisonita, statements are terminated by a semicolon and may spread across several lines, i. e., it is stream oriented. The language is case sensitive and all keywords are reserved. White space (spaces, tabs and new lines) delimit tokens. The characters consists of the standard ASCII set. Comments are like comments in Ada and C++ where the comment is delimited by // to the end of the line.

Program Structure

A Bisonita program is a sequence of statements where the source code is all in one file. Every Bisonita program must have exactly one main program construct as shown:

	program <id>;
	<declares>
	<statements>
	endprogram;
A program may include user-defined functions all at the same level, i. e., no nesting of functions like in Pascal.
	<returned type> function <id>(<parameters>);
	<declares>
	<statements>
	return <exp>;
	endfunction;
Only call by value is allowed in Bisonita.

Global declarations of variables are NOT allowed, i. e., no declarations can be outside the program block or function block. The scope of identifiers is from where defined until the end of the program block or function block.

Declares

Variables can be of three types: string, integer and real. A declaration is the <type> followed by a list of variables. An identifier must be declared before first use. Here are some sample declarations.

	string s;
	integer a, b, Cat13;
	real C, Dog;
String constants are text enclosed in double quotes. Numerical constants are like ones in C++.

Entities which name variables, functions and the main program, i. e., identifiers, start with a letter and followed by zero or more letters and digits. The first twenty characters are significant. All keywords are in lower case.

Statements

A). Assignment Statement

The assignment statement allows the assignment of the value of an expression to a variable.

	<id> := <expression>;
	s := "wow";
	a:=-3;
Types of both sides must be the same except that a real expression may be truncated to an integer and an integer expression can be assigned to a real variable.

B). Control Statements

Bisonita has three constructs to control the flow of statements. They operate much like as in other imperative languages. If the integer expression evalutes to 0, the behavior takes the "false" case, otherwise "true".

	if <integer expression> then
	<statements>
	else
	<statements>
	endif

while <integer expression> do <statements> enddo

for <integer var> := <integer exp> to <integer exp> do <statements> endfor

The return statement is used to return control to the called subprogram.
	return <exp>;
Expressions

Arithmetic expressions can be made from +, -, *, / and ** operators with common meaning. The two operands must be of the same type, i. e., either both integers or both reals. Unary - and + are also available. The integer type also has the following additional operators mod for remainder, and, or and not. The logical operators and, or and not return 1 if true and 0 if false.

	a := 3 + 2;
	b:=a-2;
	if(a=b) and (a > 0) then
	   c := -5;
	else
	endif
Numerical comparison can be performed with the relational operators =, <>, <, >, <=, >=. String comparison can only be done by = and <>. Operators have the usual operator precedence of C++.

I/O

    read <variable>;	        reads string, real or integer value
                                into the variable.
A Bisonita program opens a 500 by 500 pixel window and draws colored lines in the window. The following statements alter the state of the window.

    clear;                      clears the window.
	
    move <int exp>, <int exp>;  moves "pencil" to position x, y 
 		                where lower left corner of window 
                                is 0,0.

    draw <int exp>, <int exp>;	draws a line with "pencil" in the  
		                current color and line width from 
		                current position to position x, y.

    write <string>;	        writes the text string in window
		                where left lower corner of text 
		                starts at current position.

    set color <colorid>;	<colorid> is a keyword of one of
		                red, blue, yellow, orange,
 		                purple, green, white and black.

    set line <width in pixels>;

To send an email message to Dan about the course.
Page maintained by Dan Hyde, hyde@bucknell.edu Last update September 16, 1996

Back to Bucknell Computer Science Home page.