Fall 2000
Sketcho Match-Maker
Sketcho, a programming language, was designed for the production line drawings for small hand-held devices. Sketcho is a simple stack-implemented language. The grammar for Sketcho is listed in BNF form.
Review of BNF:
In the Backus-Naur Form a terminal symbol is indicated by not enclosing it within angle brackets. The angle brackets and enclosed words are non-terminals. Production rules consists of non-terminal at the left-hand side of the symbol := and one or more constructs, consisting of non-terminals and terminals at the right-hand side. If the right-hand side has several alternative productions, these can be separated by vertical bars (|). Syntactic elements may be grouped together by using curly brackets. A curly bracketed group may contain one or more vertical bars, indicating alternative syntactic elements. Repetition of curly bracketed groups is indicated by an asterisk (*) or a plus sign (+). An asterisk denotes that the group is optional and can be repeated any number of times. A plus sign indicates the group must be present and can be repeated any number of times. If syntactic elements are grouped using square brackets, the group is optional
<program> =: [comments] <main module definition>{ [comments] <module definition> }*
<main module definition > =: <start statement> { <body statement> }* <end statement>
<module definition> =: <begin statement> { <body statement> }* <end statement>
<start statement> =: START <program name> ;
<begin statement> =: BEGIN <module name> ;
<end statement> =: END [ <module name> | <program name> ] ;
<body statement> =: <declaration> |
<comments> |
<assignment> |
<pen attributes> |
<call statement> |
<moveto statement>
<declaration> =: DCL [<identifier> | <module name> ] ;
<identifier> =: <letter> { <alphanumeric> }*
<alphanumeric> =: <letter> | <decimal digit> | <national>
<letter> =: A-Z | a-z
<decimal digit> =: 0-9
<national> =: any symbol on the keyboard
<module name> =: <identifier>
<program name> = : <identifier>
<call statement> =: CALL <module name> ;
<assignment> =: <identifier> = <expression> ;
<expression> =: { primary> |
<expression> <arithmetic operator> <expression> }* ;
<primary> =: <identifier> | <constant> | ( <expression> )
<constant> =: integer | float
<arithmetic operator> =: + | - | / | * | ** | MOD
<pen attributes> =: DOWN ; | UP ; | <color statement> | <moveto statement>
<color statement> =: COLOR <hex color> ;
<hex color> =: { <hex number>}+
<hex number> =: 0-9 | A-F
<moveto statement> =: MOVETO <expression> <expression> ;
<comments> =: [REM any text until a newline]*
General rules:
REM example of a box drawing Sketcho program
START DrawBox
DCL Box
DCL x
DCL y
x = 100;
y = 100;
MOVETO x, y;
CALL Box;
END DrawBox;
BEGIN Box;
DOWN;
MOVETO X+10, Y;
MOVETO X, Y - 10;
MOVETO X - 10, Y;
MOVETO X, Y +10;
END Box;
Since space is the most important constraint of Sketcho programs, designers would like to have a tool to find patterns in Sketcho programs. Using this information, these patterns could be abstracted out and placed in modules, thereby reducing size of the current executing unit. You are going to take up the cause to help out the Sketcho designers. For your semester software engineering project, you will design and implement a Sketcho match-maker.
Project Requirements
Example pattern:
Moveto *
Moveto *
Result stemming from the Sketcho program above, assuming that the listing began on the first line of the file:
File abc.sko Line 14
File: abc.sko Line 15
File: abc.sko Line 16
Note the pattern could also have been entered as
Moveto * Moveto *
http://www.bsu.edu.edu/homepages/dolores/CS689/mm_inter.html