Commit | Line | Data |
---|---|---|
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 | ||
7 | @page | |
8 | @node LALR(1) Parsing | |
9 | @section LALR(1) Parsing | |
10 | ||
11 | The @code{(system base lalr)} module provides the | |
12 | @uref{http://code.google.com/p/lalr-scm/, @code{lalr-scm} LALR(1) parser | |
13 | generator by Dominique Boucher}. @code{lalr-scm} uses the same algorithm as GNU | |
14 | Bison (@pxref{Introduction, Introduction to Bison,, bison, Bison@comma{} The | |
15 | Yacc-compatible Parser Generator}). Parsers are defined using the | |
16 | @code{lalr-parser} macro. | |
17 | ||
18 | @deffn {Scheme Syntax} lalr-parser [@var{options}] @var{tokens} @var{rules}... | |
19 | Generate an LALR(1) syntax analyzer. @var{tokens} is a list of symbols | |
20 | representing the terminal symbols of the grammar. @var{rules} are the grammar | |
21 | production rules. | |
22 | ||
23 | Each rule has the form @code{(@var{non-terminal} (@var{rhs} ...) : @var{action} | |
24 | ...)}, where @var{non-terminal} is the name of the rule, @var{rhs} are the | |
25 | right-hand sides, i.e., the production rule, and @var{action} is a semantic | |
26 | action associated with the rule. | |
27 | ||
28 | The generated parser is a two-argument procedure that takes a @dfn{tokenizer} | |
29 | and a @dfn{syntax error procedure}. The tokenizer should be a unary procedure | |
30 | taking a port and returning a lexical token as produced by | |
31 | @code{make-lexical-token}. The syntax error procedure may be called with at | |
32 | least an error message (a string), and optionally the lexical token that caused | |
33 | the error. | |
34 | @end deffn | |
35 | ||
36 | Please refer to the @code{lalr-scm} documentation for details. |