1 Installation
2 Examples
5.3.1.5

esc: Extensible Syntax Compiler

Erik Silkensen <[email protected]>

 (require (planet esilkensen/esc:1:=0))

This is a project for an extensible parsing system that aims to provide a user-friendly method for designing composable DSLs.

Languages are defined in modules by CFGs written in standard BNF notation. DSLs can be built on top of the Racket programming language by writing type-oriented grammar rules as function or macro signatures followed by Racket code for their implementation.

For example, the rule

    Integer ::= "|" s:Set "|" = (set-count s);

defines syntax for set cardinality, which is implemented by Racket’s set-count function.

1 Installation

To try out the tool, first download and install Racket from http://racket-lang.org. Then start the Racket interpreter, and enter (require (planet esilkensen/esc)). This installs an esc command to the raco program.

At the command line,

    raco esc [<source-file>] ...

will compile a sequence of extensible files into Typed Racket code.

2 Examples

Included in the examples directory is a module for giving ML-like syntax to several Typed Racket forms (ML.es), and another for basic set operations such as the one above (Sets.es).

"abc.es"

import ML, Sets;

let A = {1, 2, 3} {

  let B = {2, 3, 4} {

    let C = {3, 4, 5} {

      print |A & C|;

      print A | B & C

    }

  }

}

The above program (abc.es) can be compiled and run with the following commands:

    raco esc examples/abc.es

    racket -I typed/racket examples/abc.rkt

The output of the program is

    1

    #<set: 1 2 3 4>