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