cvs commit: src/bin/sh arith.h arith.y arith_lex.l shell.h

Diomidis Spinellis dds at aueb.gr
Sun Sep 7 07:40:25 PDT 2003


Bruce Evans wrote:
> Thanks.  I don't know of any style rules for lex and yacc sources other
> than very general ones, but it looks reasonable now.

Amazingly, style rules for yacc appear in the original Steve Johnson's
paper "Yacc: yet Another Compiler-Compiler", contributed by Brian
Kernighan, no less.  The paper was part of the 7th edition Unix
Programmer's Manual, Volume 2, Supplementary Documents (PSD), which is
available in PDF format at
<http://www.cs.bell-labs.com/7thEdMan/v7vol2b.pdf>.

"Input Style

It is difficult to provide rules with substantial actions and still have
a readable specification file. The following style hints owe much to
Brian Kernighan. 

a. Use all capital letters for token names, all lower case letters for
nonterminal names. This rule comes under the heading of ``knowing who to
blame when things go wrong.'' 

b. Put grammar rules and actions on separate lines. This allows either
to be changed without an automatic need to change the other. 

c. Put all rules with the same left hand side together. Put the left
hand side in only once, and let all following rules begin with a
vertical bar. 

d. Put a semicolon only after the last rule with a given left hand side,
and put the semicolon on a separate line. This allows new rules to be
easily added. 

e. Indent rule bodies by two tab stops, and action bodies by three tab
stops. 
"

Diomidis - dds@


More information about the cvs-src mailing list