Commit d52715ac authored by Erick Gallesio's avatar Erick Gallesio

Added documentation for new usage of stklos-genlex

parent 242257df
......@@ -15,12 +15,13 @@
.\" .br insert line break
.\" .sp <n> insert n1 empty lines
.\" for manpage-specific macros, see man(7)
stklos-genlex \- lexical analyzer generation for STklos
stklos-genlex lex-file output-file constructor
stklos-genlex source-file output-file
......@@ -29,8 +30,12 @@ can be used to make lexical analyzers with
.B STklos.
It is a simple front-end to the Danny Dubé
.B SILex
tool. This command always takes three parameters which are described
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:
.IP "\fIlex-file\fR"
is the input file which contains the lex-like rules describing the
analyzer to be built
......@@ -48,6 +53,16 @@ object which contains the automaton. To fetch the next token of the
input stream, programs must use the \fIlexer-next-token\fR. procedure.
See the example below for details.
Another usage of the \fBstklos-genlex\fR can be to use the
\fIdefine-regular-grammar\fR 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, \fBstklos-genlex\fR 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 \fIdefine-regular-grammar\fR have
been replaced by the code of the analyzer.
Suppose that the lexical rules are in the file \fIrules.l\fR. One can
......@@ -65,6 +80,40 @@ The following piece of code show how to use the produced analyzer.
(display (lexer-next-token lex))
This example uses the second form of \fBstklos-genlex\fR
usage. Here is an analyzer which skips lines starting with
2 slashes. Suppose that we have a file \fIlex.stk\fR which is:
(define-regular-grammar skip-//-lines
;; The arguments
;; The macros
space [ \\9]
eol \\n
;; The grammar
{space}*//.*{eol} (yycontinue)
^.*{eol} yytext
<<EOF>> (eof-object)
<<ERROR>> (error "invalid token")
(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 \fIana.stk\fR
stklos-genlex lex.stk ana.stk
.BR stklos (1)
......@@ -21,7 +21,7 @@
;;;; Author: Erick Gallesio []
;;;; Creation date: 12-Dec-2003 11:29 (eg)
;;;; Last file update: 25-Apr-2007 18:17 (eg)
;;;; Last file update: 2-Jun-2007 10:38 (eg)
......@@ -120,7 +120,7 @@
((4) (lex-generate (cadr args)
(caddr args)
(cadddr args)))
(else (die (string-append
"Usage: " (program-name) "<lex-file> <output-file> <constructor>\n"
" " (program-name) "<src-file> <output-file>\n")))))
(else (let ((prog (basename (program-name))))
(die (string-append
"Usage: " prog "<lex-file> <output-file> <constructor>\n"
" " prog "<src-file> <output-file>\n"))))))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment