CS 60, Fall 2001

Assignment 8, Due Sat. 10 November

Logo meets Java

 

Logo is a program language with featuring a number of easy-to-access features, including “turtle graphics”. Turtle graphics is a simplified form of graphics in which an imagined “turtle” moves on the screen, drawing with its “pen”. Turtle graphics commands include telling the turtle to move forward some number of pixels, turn right some number of degrees, pick its pen up (so that it doesn’t draw when it moves) and put it down again (to resume drawing). Using simple commands, quite elaborate drawings can be made, such as the one shown below, which was created by the Logo program shown in the text area:
      “repeat 36 [ repeat 36 [fd 10  rt 10]  fd 20  rt 10 ]”.


 

Iteration in Logo is accomplished either by the repeat command or by recursion. In this assignment you only deal with the repeat command, not recursion, and all quantities are constants, no variables. You are given a setup for Logo turtle graphics. You are asked to construct a parser for a small subset of the Logo language, using a tokenizer that is provided. The grammar to be used is as follows, where auxiliary symbols are in italics, {...} means "0 or more occurences of ...", | means "or", and other symbols '[', ']', "cs", etc. are terminal.

There is no grammar rule given for number
or for string because the tokenizer will parse these for you automatically.

 

program -> { command }

command -> cs |                                 // clear screen

                   home |                           // home turtle

                   pu |                              // pen up

                   pd |                              // pen down

                   fd number |                   // move forward

                   rt number |                   // right-turn

                   repeat number [ program ]

 

Note that the grammar allows arbitrary nesting of repeats, and this is one of the key points of this assignment, recursive-descent parsing.

 

You are welcome to augment these commands for your enlightenment, but don’t ITR because you are having so much fun. A running applet may be found at:

 

http://www.cs.hmc.edu/courses/current/cs60/examples/java/logo/logo.html

 

We also give you a skeleton applet with an empty Parser class to fill in, as well as a Turtle class and a handy Tokenizer:

 

http://www.cs.hmc.edu/courses/current/cs60/examples/java/logoSkeleton

 

 See the following page for documentation on the various classes provided in the skeleton:

 

http://www.cs.hmc.edu/courses/current/cs60/examples/java/logoSkeleton/javadoc/


http://www.cs.hmc.edu/courses/current/cs60/examples/java/logoSkeleton/doxygen/doxyhtml/

 

 Please ask your instructor if you have any questions about the usage of these.