7.4.0.4
18 Some Language Gems
This week has shown us a lot of the nuts and bolts of building languages, focusing on the mechanisms and technical tools to able to build them. This lecture will show a few languages that have been built for various purposes to try to give a sense of the range of programming languages that are possible.
Let’s look at two of the languages used to build the
lecture notes. Here is a snippet of code that produced
the second lecture on Monday morning:
"Monday Morning Lecture"
#lang scribble/manual @(require "../shared.rkt") @title[#:tag "mon-mor-lab"]{Macro Expansion} @author{Matthias Felleisen} @goals[ @item{reading streams of characters into trees} @item{traversing and expanding trees} @item{core syntax} ] To understand Racket's approach to language extension and construction, we need to have a model of the front-end of a language implementation.
This code is in Scribble (see
Scribble: The Racket Documentation Tool), a
programming language designed for writing text. It
cooperates with other values,
including picts, allowing us to
use redex to generate the type rules in the Thursday
lectures directly from definitions of the type systems
and their auxiliary definitions. For example, here is the
grammar for the first Thursday morning lecture:
"Thursday Morning Lecture"
#lang racket (require redex) (define-language L (e ::= z b (op e e) (if e e e) the-input) (op ::= + / <=) (τ ::= Int Bool) (z ::= integer) (b ::= boolean))
There are a large number of languages built in Racket with more and less value but that show the range of Racket’s language defining mechanisms. See 2D Syntax, a syntax extension for two-dimensional syntax that is used in the implementation of Redex (search for unify* in the module redex/private/pat-unify). See also Enumerating Haiku, a language for specifying how to generate haiku.