Prev Up Next
Go backward to Error Recovery
Go up to Top
Go forward to References

Example Session

To see all this in action, we work through a little example involving one of the provided example grammars. First, to start the system, type

% scheme48 -i essence.image -h 8000000
at the shell prompt. The mechanism to define a grammar are available from structure grammar (see *). To open the structure type
> ,open grammar
to the Scheme48 system, followed by
> ,load examples/toy-grammars.scm
to load the definitions for some simple grammars.

Loading the corresponding inputs requires enumerated values, hence

> ,open enumerated
> ,load examples/toy-inputs.scm
defines the example inputs.

As indicated in Sec. *, the input to the parser comes in form of a stream. To open the stream module type

> ,open stream

Open the parser module by typing

> ,open cps-lr
to gain access to the parse function (see Sec. *).

As a sample run, consider the grammar g10 which specifies arithmetic expressions. The terminals l and r stand for opening and closing brackets, whereas n stands for a number.

> (parse g10 1 'lr (list->stream i10-1))
147

To specialize a parser requires to open the structure cps-lr-generate:

> ,open cps-lr-generate
The generate-parser function from this structure (see Sec. *) performs the specialization:
> (generate-parser g10 1 'lr 'expr-parser)

To perform the same specialization task via the command line interface type

% ./essence -g expr-parser -m lr -l 1 \
            examples/toy-grammars.scm g10 /tmp/expr-parser.scm

Mike Sperber, Peter Thiemann

Prev Up Next