elisp @@ macro
[bpt/guile.git] / doc / ref / api-lalr.texi
CommitLineData
2115b8eb
LC
1@c -*-texinfo-*-
2@c This is part of the GNU Guile Reference Manual.
3@c Copyright (C) 1996, 1997, 2000, 2001, 2002, 2003, 2004, 2007, 2009, 2010
4@c Free Software Foundation, Inc.
5@c See the file guile.texi for copying conditions.
6
2115b8eb
LC
7@node LALR(1) Parsing
8@section LALR(1) Parsing
9
10The @code{(system base lalr)} module provides the
11@uref{http://code.google.com/p/lalr-scm/, @code{lalr-scm} LALR(1) parser
12generator by Dominique Boucher}. @code{lalr-scm} uses the same algorithm as GNU
13Bison (@pxref{Introduction, Introduction to Bison,, bison, Bison@comma{} The
14Yacc-compatible Parser Generator}). Parsers are defined using the
15@code{lalr-parser} macro.
16
17@deffn {Scheme Syntax} lalr-parser [@var{options}] @var{tokens} @var{rules}...
18Generate an LALR(1) syntax analyzer. @var{tokens} is a list of symbols
19representing the terminal symbols of the grammar. @var{rules} are the grammar
20production rules.
21
22Each rule has the form @code{(@var{non-terminal} (@var{rhs} ...) : @var{action}
23...)}, where @var{non-terminal} is the name of the rule, @var{rhs} are the
24right-hand sides, i.e., the production rule, and @var{action} is a semantic
25action associated with the rule.
26
01a4f0aa
LC
27The generated parser is a two-argument procedure that takes a
28@dfn{tokenizer} and a @dfn{syntax error procedure}. The tokenizer
29should be a thunk that returns lexical tokens as produced by
30@code{make-lexical-token}. The syntax error procedure may be called
31with at least an error message (a string), and optionally the lexical
32token that caused the error.
2115b8eb
LC
33@end deffn
34
35Please refer to the @code{lalr-scm} documentation for details.