Web for lex/yacc


From:     Don Hosek
Date: 19 May 1995
Has anyone extended any c-web to allow for inclusion of lex and yacc code? It'd be really handy to be able to include the code for a lexer and parser in the same source file as the supporting c code.


From:     Norman Ramsey
Date: 21 May 1995
noweb, nuweb, FunnelWeb, and FWEB all have this ability. Some are more recommended than others. If you want this indexed automatically, you're stuck with noweb. Try
noweave -autodefs c -autodefs yacc
If you want is prettyprinted, and you want the lex and yacc prettyprinted in a way different from the C, you're out of luck. If you want everything prettyprinted in C style (reasonable), you could try Kostas Oikonomou's prettyprinters with noweb.


From:     Don Hosek
Date: 22 May 1995
Norman Ramsey writes: noweb, nuweb, FunnelWeb, and FWEB all have this ability. Some are more recommended than others. If you want this indexed automatically, you're stuck with noweb. Try
noweave -autodefs c -autodefs yacc
If you want is prettyprinted, and you want the lex and yacc prettyprinted in a way different from the C, you're out of luck. If you want everything prettyprinted in C style (reasonable), you could try Kostas Oikonomou's prettyprinters with noweb.

Now forgive me if things have changed in the meantime, but... I dismissed noweb out of hand when the original TUGboat article was published for one simple reason: It doesn't allow me to have the code presented in a different order than the compiler wants to see it.

In actuality, as I have thought about the problem, what I would really like to be able to do is to have a multilingual web. I have not thought too much about semantics yet, but here's a first thought off the top of my head. Including the language directive at the start of a file or module name makes that the language for the whole file or module. One can also have inlined code in other languages (e.g., inlined SQL or assembly code).

@ This section will generate the yacc file
@(@%yacc@>foo.y@>=
etc.

@ This section will generate the lex file
@(@%lex@>foo.l@>=
%{
    @%c@>
    @<Inlined C code for lex definition section@>
    @)  
%}
@<Lex definitions@>
%%
@<Lex patterns@>
%%
@%c@>
@<Support code for the lexer@>
@)

@ Language modes should be inherited. This will automatically be in
lex mode
@<Lex patterns@>=
...

@ This will automatically be in C mode
@<Inlined C code for lex...@>=
...


From:     Sven Utcke
Date: 22 May 1995
Don Hosek writes: I dismissed noweb out of hand when the original TUGboat article was published for one simple reason: It doesn't allow me to have the code presented in a different order than the compiler wants to see it.

Are you sure you aren't confusing this with cnoweb? cnoweb (by, if I remember correctly, the same author) is nothing more than a clever hack to enable you to use TeX-documentation within your C-program. Not what one would really call literate programming. noweb, on the other hand, is a full grown literate programming tool quite similar to the one proposed in your article, and does indeed allow for the reordering of code. It is well worth trying (although I use FWEB 1.40, which can do what you want but, to my knowledge, is still beta).


From:     Norman Ramsey
Date: 23 May 1995
Don Hosek writes: I dismissed noweb out of hand when the original TUGboat article was published for one simple reason: It doesn't allow me to have the code presented in a different order than the compiler wants to see it.

ALERT! noweb != cnoweb

You have confused noweb with another tool having a similar name. noweb has never been written up in TUGboat. The only article written about it appeared in the November 1994 IEEE Software. noweb meets all of Thimbleby's criteria for literate programming, including: flexible order of elaboration (code in any order), ``verisimilitude'' (derive code and documentation from one source), and automatic indexing and table of contents. Automatic indexing is available for a limited number of languages; for other languages noweb supports Preston Briggs's ``semi-automatic'' indexing (which produces better results when applied with fanatical discipline).

In actuality, as I have thought about the problem, what I would really like to be able to do is to have a multilingual web... Including the language directive at the start of a file or module name makes that the language for the whole file or module.

Others have suggested labeling only the ``root chunk'' and having that carry forward to the whole refinement. Whether the labeling should be embedded in or external to the source file is a subject of debate.

Sven Utcke writes: Are you sure you aren't confusing [noweb] with cnoweb? cnoweb (by, if I remember correctly, the same author)

noweb and cnoweb are unrelated tools with different authors.