Child pages
  • Shapes - an introductory MPS tutorial

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...


You will get a running Java application with your drawing on it as a reward for your efforts.

An alternative

...

generator - generating XML

Just to give you an idea how the generator could be utilized to generate code in a declarative language, such as xml, here's a simple generator for the Shapes language generating xml. We start from an empty generator. The Java templates and rules have all been deleted:

...

Then insert a COPY_SRCL macro to loop through all the shapes of a Canvas and trigger their reduction rules:

The name of the generated xml file can also be customized using a property macro.

Image Added

Image Added

Reduction rules for Square and Circle also now need to be created:

The templates for Circle and Square must hold an XmlElement as their root:

...

Then the xml template must be builtfully constructed:

template fragment must be created around the whole xml code:

...

For radius, we will use a dedicated xml element:

And quire similar similarly for the color reference:

The template for Square will be very similar:

...