SGL provides a procedural language (used to write event handlers) within a declarative framework (used to specify graphics objects). Semi-colon (;) serves as statement terminator.
SGL has two variable data types, integer and floating_pt, as well as three literal (constant) types, numeric, string, and color. All variables in an SGL program are global to the entire program. There is no notion of user-defined function or procedure beyond the standard event handlers.
Variable names are a letter followed by an alphanumeric string (including underscore (_) ). Numeric constants are (unsigned) decimal numbers with optional decimal point.
Output of expression values is provided by the display statement. There is no provision for input into an SGL program beyond response to mouse events.
Here is a short sample program:
{ Draw a "bouquet" of sticks and count them.
- written by mike slattery, feb 1996 }
{ Note that comments are enclosed in braces }
integer x_loc;
frame labelled "Fan"
canvas
coordinates:0,0,7,7;
x_loc = 1;
while x_loc < 7 do
draw line:4.5,1,x_loc,6;
display x_loc;
x_loc = x_loc + 1;
end while;
end canvas;
end frame;
Here is a draft of a
grammar
for the language (this may
need to be revised as we move through the semester).
Words in angle brackets (<..>) represent non-terminals, whereas
other words and symbols represent terminals (keywords) in
the language. ID, COLOR, STRING, and NUMBER are returned by
the scanner with attributes specifying the matched lexemes.Additional Sgl examples (and corresponding hand-written C code) can be found in ~mikes/170/sgldemo .
A general description of the semantics of the language is also available.