stklos-genlex source-file output-file
When this command is called with three parameters, it takes a standard SILex input file as input and generate an analyzer. These parameters are described below:
Another usage of the stklos-genlex can be to use the define-regular-grammar special form directly in a source file. This form takes the name of the analyzer, the arguments which are passed to the analyzer, the macros part and rules part of the analyzer. In this case, stklos-genlex is called with the source file and the name of the output file. The output file, will contain a copy of the source file where the define-regular-grammar have been replaced by the code of the analyzer.
stklos-genlex rules.l out.stk my-make-lexThe following piece of code show how to use the produced analyzer.
(load "out.stk") ... (let ((lex (my-make-lex "foo"))) ;; Display the first token of file foo (display (lexer-next-token lex)) ...)
This example uses the second form of stklos-genlex usage. Here is an analyzer which skips lines starting with 2 slashes. Suppose that we have a file lex.stk which is:
(define-regular-grammar skip-//-lines ;; The arguments () ;; The macros #<<%EOM space [ \9] eol \n %EOM ;; The grammar #<<%EOG {space}*//.*{eol} (yycontinue) ^.*{eol} yytext <<EOF>> (eof-object) <<ERROR>> (error "invalid token") %EOG ) (define (copy in out) (let ((reader (make-regular-reader skip-//-lines in))) (let loop ((line (reader))) (unless (eof-object? line) (display line out) (loop (reader))))))The following command will produce an analyzer in file ana.stk
stklos-genlex lex.stk ana.stk