api-lalr.texi 1.6 KB

123456789101112131415161718192021222324252627282930313233343536
  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, 2017
  4. @c Free Software Foundation, Inc.
  5. @c See the file guile.texi for copying conditions.
  6. @node LALR(1) Parsing
  7. @section LALR(1) Parsing
  8. The @code{(system base lalr)} module provides the
  9. @uref{https://github.com/schemeway/lalr-scm/, @code{lalr-scm} LALR(1) parser
  10. generator by Dominique Boucher}. @code{lalr-scm} uses the same algorithm as GNU
  11. Bison (@pxref{Introduction, Introduction to Bison,, bison, Bison@comma{} The
  12. Yacc-compatible Parser Generator}). Parsers are defined using the
  13. @code{lalr-parser} macro.
  14. @deffn {Scheme Syntax} lalr-parser [@var{options}] @var{tokens} @var{rules}...
  15. Generate an LALR(1) syntax analyzer. @var{tokens} is a list of symbols
  16. representing the terminal symbols of the grammar. @var{rules} are the grammar
  17. production rules.
  18. Each rule has the form @code{(@var{non-terminal} (@var{rhs} ...) : @var{action}
  19. ...)}, where @var{non-terminal} is the name of the rule, @var{rhs} are the
  20. right-hand sides, i.e., the production rule, and @var{action} is a semantic
  21. action associated with the rule.
  22. The generated parser is a two-argument procedure that takes a
  23. @dfn{tokenizer} and a @dfn{syntax error procedure}. The tokenizer
  24. should be a thunk that returns lexical tokens as produced by
  25. @code{make-lexical-token}. The syntax error procedure may be called
  26. with at least an error message (a string), and optionally the lexical
  27. token that caused the error.
  28. @end deffn
  29. Please refer to the @code{lalr-scm} documentation for details.