Sketch = Shape Mode. Shape : VisualComponent | // ShapeGroup | Box | Line *common* Coordinates. // Repetition-Buffer rule ShapeGroup = "{" List(Shape) "}". VisualComponents = List(VisualComponent). VisualComponent : ShapeGroup | Decorator. Decorator : ScrollDecorator | BorderDecorator *common* VisualComponents. ScrollDecorator = "scroll". BorderDecorator = "border". Coordinates = Point Point. Point = Integer Integer. Box = "box". Line = "line". Mode : Gesture | Transfer | Drag *common* [ Mode]. Gesture = "gesture" Shape Point. Drag = "drag" ShapeGroup Point. Transfer = "transfer" ShapeGroup Point. List(S) ~ {S}. Main = . Cursor = . DrawingVisitor = Color. Color : Black | Red. Black = "black". Red = "red". // would like to say: // Shape { // traversal-pp Integer gp1x(){ // bypassing {-> *,p2,*, -> *,y,*} to Integer; // (@ return this; @) } } // will check that path is unique // it is ok to traverse to terminal class // // will create traversal function, create visitor class and object, // and call function // // Instead of // bypassing {-> *,p2,*, -> *,y,*} to Integer;} // would like to say // ordered-through {-> *,p1,*, -> *,x,*} to Integer;} DrawingVisitor { // BAD STYLE before Shape (@ System.out.println("drawing object of " + host.getClass().toString()); @) before ScrollDecorator (@ System.out.println(" draw scroll bar "); @) before BorderDecorator (@ System.out.println(" draw border "); @) before Line (@ // Cursor.move(host.get_p1x(), host.get_p1y()); Cursor.move(host.get_coords().get_p1().get_x(), host.get_coords().get_p1().get_y()); Cursor.line(host.get_coords().get_p2().get_x(),host.get_coords().get_p2().get_y()); @) before Box (@ Cursor.move(host.get_coords().get_p1().get_x(), host.get_coords().get_p1().get_y()); Cursor.line(host.get_coords().get_p1().get_x(),host.get_coords().get_p2().get_y()); Cursor.line(host.get_coords().get_p2().get_x(),host.get_coords().get_p2().get_y()); Cursor.line(host.get_coords().get_p2().get_x(),host.get_coords().get_p1().get_y()); Cursor.line(host.get_coords().get_p1().get_x(),host.get_coords().get_p1().get_y()); @) } Sketch { traversal allShapes(DrawingVisitor d) { bypassing -> *,mode,* to {Box, Line};} // go to subclasses of Shape (@ void draw(Color c) { DrawingVisitor d = new DrawingVisitor(c); this.allShapes(d); } @) } Cursor { (@ static void move(Integer x, Integer y) { System.out.println(" move to " + x + " , " + y);} static void line(Integer x, Integer y) { System.out.println(" line to " + x + " , " + y);} @) } Main { (@ public static void main(String args[]) throws Exception { System.out.println(" *** START *** "); Sketch s = Sketch.parse(System.in); s.draw(new Black()); } @) } scroll border { box 1 1 2 2 line 1 1 2 2 } 8 8 9 9 transfer {} 3 4