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 8000000at the shell prompt. The mechanism to define a grammar are available from structure grammar (see *). To open the structure type
> ,open grammarto the Scheme48 system, followed by
> ,load examples/toy-grammars.scmto load the definitions for some simple grammars.
Loading the corresponding inputs requires enumerated values, hence
> ,open enumerated > ,load examples/toy-inputs.scmdefines 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-lrto 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-generateThe 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