The file lalr.scm
declares a macro called lalr-parser
:
(lalr-parser [tokens] tokens rules ...)
To use this macro, you must first load lalr.scm
in your Scheme
system using either load
or the include
special form in Gambit-C.
This macro, when given appropriate arguments, generates an LALR(1) syntax analyzer. The macro accepts at least two arguments. The first is a list of symbols which represent the terminal symbols of the grammar. The remaining arguments are the grammar production rules. See section The grammar format for further details.
The parser generated by the lalr-parser
macro is a function that
takes two parameters. The first parameter is a lexical analyzer while
the second is an error procedure.
The lexical analyzer is zero-argument function (a thunk) invoked each
time the parser needs to look-ahead in the token stream. A token is
usually a pair whose car
is the symbol corresponding to
the token (the same symbol as used in the grammar definition). The
cdr
of the pair is the semantic value associated with the
token. For example, a string token would have the car
set
to 'string
while the cdr
is set to the
string value "hello"
.
Once the end of file is encountered, the lexical analyzer must always
return the symbol '*eoi*
each time it is invoked.
The error procedure must be a function that accepts at least two parameters.