DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Parsing with yacc

Input style

It is difficult to provide rules with substantial actions and still have a readable specification file. The following are a few style hints.

  1. Use all uppercase letters for token names and all lowercase letters for nonterminal names. This is useful in debugging.

  2. Put grammar rules and actions on separate lines. It makes editing easier.

  3. 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.

  4. 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.

  5. Indent rule bodies by one tab stop and action bodies by two tab stops.

  6. Put complicated actions into subroutines defined in separate files.

``A simple example'' is written following this style, as are the examples in this section (where space permits). The central problem is to make the rules visible through the morass of action code.


Next topic: Left recursion
Previous topic: Hints for preparing specifications

© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005