This is wisitoken-user_guide.info, produced by makeinfo version 6.7 from
wisitoken-user_guide.texinfo.
Copyright (C) 2014-2015, 2017, 2018, 2020 Stephen Leake.
Permission is granted to copy, distribute and/or modify this
document under the terms of the GNU Free Documentation License,
Version 1.3 or any later version published by the Free Software
Foundation; with no Invariant Sections, no Front-Cover Texts and no
Back-Cover Texts. A copy of the license is included in the section
entitled "GNU Free Documentation License".
INFO-DIR-SECTION Parser generators
START-INFO-DIR-ENTRY
* wisitoken-bnf-generate: (wisitoken-bnf-generate). Ada and Elisp parser generator
END-INFO-DIR-ENTRY
File: wisitoken-user_guide.info, Node: Top, Next: Overview, Up: (dir)
WisiToken User Guide
********************
Copyright (C) 2014-2015, 2017, 2018, 2020 Stephen Leake.
Permission is granted to copy, distribute and/or modify this
document under the terms of the GNU Free Documentation License,
Version 1.3 or any later version published by the Free Software
Foundation; with no Invariant Sections, no Front-Cover Texts and no
Back-Cover Texts. A copy of the license is included in the section
entitled "GNU Free Documentation License".
* Menu:
* Overview::
* Common grammar problems::
* Grammar File Syntax::
File: wisitoken-user_guide.info, Node: Overview, Next: Common grammar problems, Prev: Top, Up: Top
1 Overview
**********
WisiToken is a parser and parser generator toolkit, supporting
generalized LR (both LALR and LR1) and packrat parsers; the LR parser
provides robust error recovery. The grammar can be expressed as either
Ada source code statements, or in an EBNF file. The parser generator
generates Ada, either plain or assuming the Emacs wisi package.
At one point, "wisi" was short for "Wisent Indentation engine"; the
Emacs 'wisi' package implements an indentation engine that used to be
based on the Emacs wisent parser. However, that parser has now been
replaced by the WisiToken parser, so "wisi" is just a name.
* Menu:
* Install::
File: wisitoken-user_guide.info, Node: Install, Up: Overview
1.1 Install
===========
WisiToken is available as source code only, although a subset is
available in the GNU ELPA package 'wisi'.
You will also need to install a lexer generator. WisiToken supports
re2c, and other lexers can be added.
re2c is available from ; it is also packaged in
Mingw64 and Debian. WisiToken requires at least version 1.3. WisiToken
assumes the executable 're2c' is in '$PATH'.
File: wisitoken-user_guide.info, Node: Common grammar problems, Next: Grammar File Syntax, Prev: Overview, Up: Top
2 Common grammar problems
*************************
LALR grammars are tricky. Here we describe some common problems people
run into.
* Menu:
* Empty choice in list::
File: wisitoken-user_guide.info, Node: Empty choice in list, Up: Common grammar problems
2.1 Empty choice in list
========================
Many programming languages have lists in the grammar. For example, Ada
has lists of declarations:
package_body
: PACKAGE name IS declaration_list BEGIN statement_list END SEMICOLON
;
declaration_list
: declaration
| declaration_list declaration
;
declaration
: object_declaration
| subprogram_declaration
;; ...
;
Note that the above grammar fragment does not allow an empty
declaration_list. But Ada does, so the question is how can we add that
to the grammar.
There are four choices:
1. Add an empty declaration choice to declaration_list:
declaration_list
: ;; empty list
| declaration
| declaration_list declaration
;
This is now redundant; since declaration_list can be empty, the
second choice is not needed:
declaration_list
: ;; empty list
| declaration_list declaration
;
2. Add an empty declaration choice to declaration:
declaration
: ;; empty declaration
| object_declaration
| subprogram_declaration
;; ...
;
3. Add another rule with the empty production:
package_body
: PACKAGE name IS declarative_part BEGIN statement_list END SEMICOLON
;
declarative_part
: ;; empty
| declaration_list
;
declaration_list
: declaration
| declaration_list declaration
;
declaration
: object_declaration
| subprogram_declaration
;; ...
;
4. Add another choice in package_body that leaves out
declaration_list:
package_body
: PACKAGE name IS declaration_list BEGIN statement_list END SEMICOLON
| PACKAGE name IS BEGIN statement_list END SEMICOLON
;
Choice 1 is redundant, giving parse errors at parse time. Consider
the following statements, where "" is used to indicate an empty
declaration:
1) package One is begin end ; 2) package One is package One
is begin end ; begin end ; 3) package One is package One
is begin end ; begin end ;
In parsing 3), the second 'package' causes a shift/reduce conflict;
shift to start the nested declaration (as in 2), reduce to the empty
declaration. Both are correct according to the grammar.
Choice 2 leads to a shift/reduce conflict in the production for
package_body; implementing the wisi parser as a generalized LALR parser
allows it to handle this option.
Choice 2 is the preferred choice for Ada, since it involves the least
modifications to the original Ada grammar in the Ada reference manual.
File: wisitoken-user_guide.info, Node: Grammar File Syntax, Prev: Common grammar problems, Up: Top
3 Grammar File Syntax
*********************
The grammar file syntax is based on Gnu bison syntax with some additions
and deletions (*note Bison: (bison)Top.).
(The grammar is specified in the WisiToken grammar file
'wisitoken_grammar.wy').
The top level file structure is a list of declarations and
nonterminals.
Comments are started by ';;' and terminated by end of line.
* Menu:
* Declarations::
* Nonterminals::
* Conditional code::
File: wisitoken-user_guide.info, Node: Declarations, Next: Nonterminals, Up: Grammar File Syntax
3.1 Declarations
================
Declarations declare terminal tokens, conflicts, and other parser
parameters.
* Menu:
* Raw Code::
* Keywords::
* Tokens::
* Error recovery::
* Other declarations::
File: wisitoken-user_guide.info, Node: Raw Code, Next: Keywords, Up: Declarations
3.1.1 Raw code
--------------
%code { actions | copyright_license } [spec | body | context | pre | post]... %{