Macros for Monitors

Macros for Monitors - CS1102: Macros for Monitors Kathi...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CS1102: Macros for Monitors Kathi Fisler, WPI September 28, 2004 1 A Non-Graphical Notation for Monitors In the previous lecture, we developed two data definitions for monitors, hand-translated the traffic light example into both of those definitions, and wrote the code necessary to run the monitors on inputs. As with our slideshow and animation language examples, we would like to have a nicer notation for writing down monitors and use macros to convert that notation into our desired data definitions. Here’s a possible ascii notation for monitors. We want to use -> to depict the arrows and : to separate a state name from its transitions. ( define TL-monitor ( monitor is-red ( is-red : ( green - > is-green ) ( red - > is-red )) ( is-green : ( yellow - > is-yellow ) ( green - > is-green )) ( is-yellow : ( red - > is-red ) ( yellow - > is-yellow )))) Our goal is to write the define-syntax expression that will let us use this notation. We will do this exercise twice, once for each data definition we developed for monitors. Converting to the Structure-Based Language Recall that our representation of TL-monitor in the structures-based language looked as follows [note: I’ve changed the name of the structure to monitor-struct from monitor to avoid a naming conflict between the structure and the macro in Scheme.] ( define TL-monitor ( make-monitor-struct is-red ( list ( make-state is-red ( list ( make-trans red is-red ) ( make-trans green is-green ))) ( make-state is-green ( list ( make-trans green is-green ) ( make-trans yellow is-yellow ))) ( make-state is-yellow ( list ( make-trans yellow is-yellow ) ( make-trans red is-red )))))) We want to write the monitor macro that to produce this code. First, let’s write the macro up to, but not including, the input pattern: ( define-syntax monitor ( syntax-rules ( - > : ) )) 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Recall that the items in parentheses after syntax-rules are the keywords for the macro. We treat both
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/06/2008 for the course CS 1102 taught by Professor Fisler during the Fall '07 term at WPI.

Page1 / 4

Macros for Monitors - CS1102: Macros for Monitors Kathi...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online