A Tool for Specifying Reversible LALR(1) Parsers

Zebu is a LALR(1) parser generator similar to YACC, but for Common Lisp. Its features include the ability to define several grammars and parsers simultaneously, a framework for specifying the semantics, meta-grammars management and generation of unparsers. It also contains a lexer that groks (a subset of) Emacs Lisp regexps.

The latest known version is 3.5.5, but some older versions are also available from the CMU AI Repository. Chun Tian has found a tarball of zebu 3.5.5 from a Gentoo mirror and created a GitHub repository for it.

A "nano-howto", with a patch, to install and run zebu-3.5.5 on clisp-2.30, and two example grammars can be found at http://informatimago.free.fr/archives/develop/lisp/pjb-zebu-clisp.tar.gz.

Note that Zebu does not seem to have a way for the user to control operator precedence and associativity, making it hard to use it to generate a parse for all but the simplest languages. Not meaning to slam Zebu, but it may be more effective to use CL-Yacc or even Bovine or Wisent running under Emacs until Zebu is made more featureful (see also my contribution to the license argument below). -- Joe Corneli


Some denizens of comp.lang.lisp have tried to contact the author, but did not succeed so far. Zebu is NOT under the GPL - sadly, it's non-free. Someone should contact both authors and get permission to re-issue it under a nicer license.

[Zebu _IS_ under the GPL. It says so explicitly in the file COPYRIGHT.]

[Just noticing that it is "(c) Copyright 1992, Hewlett-Packard Company". Perhaps HP will change the license. Anyone reading this on good terms with Bruce Perens (he works at HP)?]

[I just browsed the file COPYRIGHT included with the source of Zebu and for all I can tell it's an old version of the GPL. Ergo it's Free. - James A. Crippen]

[It is true that the GPL is cited in many places but there are a couple of dozen source files which contain the following notice and no mention of the GPL: So it is not clear what the effective legal status is.]

[It's as clear as can be! There is a file COPYRIGHT which states explicitly that permission is granted under the General Public License to use modify and redistribute. How much clearer do you want it? It is NOT required that the GPL be cited in full in every file. You can find dozens of GNU packages which have copyright messages but no GPL in some files.]


With all the license arguments, it seems that the end result is that Zebu is probably under the GPL, but even so you may not want to adopt it in your software distribution or sell it commercially. Just in case. Other than that, it's quite obvious that the original intent was to distribute Zebu, so there's certainly no reason that you can't use it all you want.

[JAC: I just had another thought. Recall that American copyright laws require that the holder of copyright defend their copyright to retain it. Is this perhaps a situation where the lack of defense or follow-through on copyright could nullify it? A question for lawyers...]

[BM: Not so, AFAIR the above is for trademarks not for copyright]

Just to throw in a little extra information. I contacted William Wells a couple years ago about the copyright notices of his, which granted permission for non-commercial use. I asked him if he would consider granting permission to use the code under GPL and on Aug 23, 2001 he responded, in part: "Souds[sic] like a fine plan to me." If it is those notices that are causing concern, then I think we are okay. -- Russell Senior

I think it would be good to repackage Zebu in a fully GPL-compliant way. Probably the right thing to do would be to get in touch with Hewlett Packard about this. Until the licensing terms are cleared up, I think Zebu will suffer badly, because people won't be willing to work on it or even use it much until it is clear that it is free software. -- Joe Corneli

What good is it to have a GPL parser generator? Is my application written using Zebu not automatically GPL'd, because I need the Zebu runtime?

Agreed that it would be better to get the licensing cleared up on this one, if possible. (Oct. 2005, just to give this a time scale) Also, ideally Zebu itself could be GPL (if that's what is desired) but the use of output wouldn't be constrained to GPL. For Modified BSD licensed code (for example) that could be a real problem. Any effort going on right now to resolve this?

Quick assessment (2023-03-29)

  • The zebu system compiles and loads successfully.
  • The zebu-compiler system is rejected by ASDF.

Error while defining system: multiple components are given same name "zebu-kb-domain".

Quick fixes (2023-04-15)

Loading the compiler—with the meta-grammar being automatically compiled—looks like this in MKCL:

> (asdf:load-system :zebu-compiler)

; Zebu Compiling (Version 3.5.5)
; #P"C:\\Users\\mulle\\common-lisp\\zebu\\zebu-mg.zb" to #P"C:\\Users\\mulle\\common-lisp\\zebu\\zebu-mg.tab"

Reading grammar from C:\Users\mulle\common-lisp\zebu\zebu-mg.zb

Start symbols is: META-GRAMMAR

34 productions, 37 symbols
[<MORE-RHS>] derives the empty string
[<CONSTITUENT-LIST>] derives the empty string
[<RHS1>] derives the empty string
[<RHS>] derives the empty string
[<LABEL-VALUE-PAIRS>] derives the empty string
[<PRINT-FUNCTION>] derives the empty string
.........................................................57 item sets
Generating domain source code onto file: C:\Users\mulle\common-lisp\zebu\zmg-dom.lisp
Writing domain to C:\Users\mulle\common-lisp\zebu\zmg-dom.lisp

Dumping parse tables to C:\Users\mulle\common-lisp\zebu\zebu-mg.tab

Loading "C:\\Users\\mulle\\common-lisp\\zebu\\zebu-mg.tab"
Loading domain file "C:\\Users\\mulle\\common-lisp\\zebu\\zmg-dom.fas"
;;; Loading "C:\\Users\\mulle\\common-lisp\\zebu\\zmg-dom.fas"

Compiling an example grammar is similar:

> (zb:zebu-compile-file "home:common-lisp;zebu;test;ex1.zb")

; Zebu Compiling (Version 3.5.5)
; #P"HOME:COMMON-LISP;ZEBU;TEST;EX1.ZB" to #P"C:\\Users\\mulle\\common-lisp\\zebu\\test\\ex1.tab"

Reading grammar from HOME:COMMON-LISP;ZEBU;TEST;EX1.ZB

Start symbols is: EE

11 productions, 15 symbols
................16 item sets
Generating domain source code onto file: C:\Users\mulle\common-lisp\zebu\test\ex1-dom.lisp
Writing domain to C:\Users\mulle\common-lisp\zebu\test\ex1-dom.lisp

Dumping parse tables to C:\Users\mulle\common-lisp\zebu\test\ex1.tab

Then the parsing table can be loaded:

> (zb:zebu-load-file *)

Loading "C:\\Users\\mulle\\common-lisp\\zebu\\test\\ex1.tab"
Loading domain file "C:\\Users\\mulle\\common-lisp\\zebu\\test\\ex1-dom.fas"
;;; Loading "C:\\Users\\mulle\\common-lisp\\zebu\\test\\ex1-dom.fas"
<Zebu Grammar: ex1>

Parsing a string looks like this:

> (zb:read-parser "1/2" :grammar (zb:find-grammar "ex1")) (EXPRESSION (TERM (FACTOR 1/2))) 3

The secondary value is where parsing ended. The read-parser function takes a :junk-allowed option:

> (zb:read-parser "1.2+12*1/2junk" :grammar (zb:find-grammar "ex1") :junk-allowed t) (+OP (EXPRESSION (TERM (FACTOR 1.2))) (*-OP (TERM (FACTOR 12)) (FACTOR 1/2))) 10

The main limitation is that the regular expression engine assumes 8-bit characters.