AFP2004
Ehc
AG material
- Slides of the preschool AG tutorial.
- AG manual.
- Paper and slides of "Typing Haskell with an Attribute Grammar". The paper will appear in the proceedings in a corrected and adapted form.
EH compilers
The set of compilers is described during the
AFP 2004 summerschool.
Lab exercises
Exercise 1: Extending the html example from the preschool presentation
The AG file
Main.ag implements the html generation from the
preschool tutorial. It produces (for test nr 5) the output found
here.
- Make a mistake in the input file, and notice how the parser combinators that are being used inside AG try to correct your input.
- Comment out the largest part of the file, and inspect the generated code. Pay especially attention to the automatically generated copy rules.
- Adapt Main.ag so that it creates a html file with prev/next links, as the example output here shows.
- Extend the html generation further with an up/down button. The up button leads to a section one level higher, if present. The down button leads to the first subsection of a section, if present.
Compile and run the given Main.ag by
% uuagc -a Main.ag
% ghc -package uust --make -o html Main.hs
% ./html 5
The compilation requires the uust library (see EH compilers for installation instructions) which is installed on all Unix lab machines.
Exercise 2: Pretty printing
The file
Slides.ag is the starting point of this exercise. It was constructed out of the text of the Pretty Printing paper (with a few small corrections with respect to the paper version).
- Change the attribute grammar so it will never put more than ribbon width data on a line. This is to avoid unpleasingly long lines.
- Check the functionality by experimenting with the width w.
- Add the possibility to add vertical composition, in which you can place text elements in a stacked way.
Compilation and running is similar to the previous exercise.
--
AtzeDijkstra - 19 Aug 2004