I am about to check-in a big change to Wisent!
Here is a summary:
- The internal data structure of LALR automatons is improved.
* The goto table is filled with nonterminal symbols instead of item
* The vector of semantic action lambda expressions is replaced by an
obarray. Each semantic action is now represented by a symbol
interned in that obarray. `symbol-function' on a semantic action
symbol return the semantic action lambda expression.
A semantic action symbol name has the form NONTERMINAL:INDEX, where
NONTERMINAL is the name of the nonterminal symbol the action
belongs to, and INDEX is an action sequence number within the scope
of NONTERMINAL. For example, this nonterminal definition:
| input line
(format "%s %s" $1 $2) [input:1]
will produce two semantic actions, and associated symbols:
`input:0', a default action that returns $1.
`input:1', that returns `(format "%s %s" $1 $2)'.
* The action table is filled with semantic action symbols instead of
negative item numbers.
* An automaton is now a vector:
[action-table goto-table start-alist semantic-actions-obarray].
- The LR parser engine benefits of the above changes. It no more
needs to handle translation of item numbers, and it can directly
call semantic actions. Consequently it should be faster!
- Grammar compilation follows normal Emacs Lisp byte-compilation
strategy. That is, when a `wisent-compile-grammar' form is
evaluated it produces a LALR automaton without semantic actions
byte-compiled. When byte-compiled it produces byte-code for the
whole automaton, including semantic actions.
- I introduced a new library: wisent-debug.el, that takes advantage of
new automaton data structure and byte-compilation strategy, to
provide some debugging features for wisent. For now, I implemented
low level debugging of semantic actions, using the standard Emacs
Mainly three commands are available:
`wisent-debug-on-entry'/`wisent-cancel-debug-on-entry', that mimic
`debug-on-entry'/`cancel-debug-on-entry' for semantic actions.
`wisent-debug-show-entry' that shows the code of a semantic action.
Unfortunately, the new automaton format is incompatible with the
current one. It will be necessary to update .el files from .wy
grammars, and to recompile them :-(
If you want to try it, I attached a tarball that includes a big patch
to semantic (from today CVS version), and the new wisent-debug.el
Finally a change log is at end.
------- Change Log
(wisent-defcontext semantic-actions): Moved before first use.
(wisent-token-actions): Create new semantic actions obarray. Fill
the action table with semantic action symbols instead of negative
(wisent-goto-actions): Fill the goto table with nonterminal
symbols instead of item numbers.
(wisent-semantic-action): Store code of action in the function
cell of a symbol interned in the semantic actions obarray. Return
that symbol. The new semantic action variable `$action' is bound
to the name of that symbol.
(wisent-semantic-actions, wisent-token-translations): Removed.
(wisent-parser-automaton): Return a vector of 4 elements: the
action table, the goto table, the alist of start symbols, and the
semantic actions obarray.
(wisent-parse-nonterminals): Produce symbolic location of semantic
(wisent-parse-grammar): Intern generated symbols.
(wisent-compile-grammar): Doc fix. Use `wisent-automaton-p'.
(wisent-byte-compile-automaton): New functions.
(wisent-grammar-parsetable-builder): Ensure that the grammar
[byte-]compiler is available to handle byte-compilation of the
(autoload 'wisent-compile-grammar): Removed.
(wisent-translate, wisent-untranslate): Removed.
(wisent-parse): Use new automaton format.
(ede-proj-target-elisp "wisent"): Added wisent-debug.el.