Hi All,
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
numbers.
* 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 [input:0]
| 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
debugger.
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
file.
Finally a change log is at end.
Thoughts=3F
Enjoy!
David
------- Change Log
* semantic-grammar.el
(semantic-grammar-automaton)
(semantic-grammar-keywords, semantic-grammar-tokens)
(emantic-grammar-setup-semantic): Re-generated.
* wisent/wisent-awk.el
(wisent-awk-automaton)
(wisent-awk-keywords, wisent-awk-tokens)
(wisent-awk-setup-parser): Re-generated.
* wisent/wisent-calc.el
(wisent-calc-automaton, wisent-calc-tokens)
(wisent-calc-setup-parser): Re-generated.
* wisent/wisent-cim.el
(wisent-cim-automaton)
(wisent-cim-keywords, wisent-cim-tokens)
(wisent-cim-default-setup): Re-generated.
* wisent/wisent-comp.el
(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
item numbers.
(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
actions.
(wisent-parse-grammar): Intern generated symbols.
(wisent-compiled-grammar-p): Removed.
(wisent-compile-grammar): Doc fix. Use `wisent-automaton-p'.
(wisent-byte-compile-grammar)
(wisent-byte-compile-automaton): New functions.
* wisent/wisent-grammar.el
(wisent-grammar-parsetable-builder): Ensure that the grammar
[byte-]compiler is available to handle byte-compilation of the
grammar.
* wisent/wisent-java-tags.el
* wisent/wisent-java.el
(wisent-java-parser-tables)
(wisent-java-keywords, wisent-java-tokens)
(wisent-java-default-setup): Re-generated.
* wisent/wisent-python.el
(wisent-python-parser-tables)
(wisent-python-keywords, wisent-python-tokens)
(wisent-python-default-setup): Re-generated.
* wisent/wisent.el
(autoload 'wisent-compile-grammar): Removed.
(wisent-automaton-p): New.
(wisent-translate, wisent-untranslate): Removed.
(wisent-parse): Use new automaton format.
* wisent/wisent-debug.el
New file.
* wisent/Project.ede
(ede-proj-target-elisp "wisent"): Added wisent-debug.el.
* wisent/Makefile
Re-generated.
|