manpagez: man pages & more
info bison
Home | html | info | man
[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.3.2 Empty Rules

A rule is said to be empty if its right-hand side (components) is empty. It means that result can match the empty string. For example, here is how to define an optional semicolon:

semicolon.opt: | ";";

It is easy not to see an empty rule, especially when | is used. The %empty directive allows to make explicit that a rule is empty on purpose:

semicolon.opt:
  %empty
| ";"
;

Flagging a non-empty rule with %empty is an error. If run with ‘-Wempty-rule’, bison will report empty rules without %empty. Using %empty enables this warning, unless ‘-Wno-empty-rule’ was specified.

The %empty directive is a Bison extension, it does not work with Yacc. To remain compatible with POSIX Yacc, it is customary to write a comment ‘/* empty */’ in each rule with no components:

semicolon.opt:
  /* empty */
| ";"
;

This document was generated on December 1, 2013 using texi2html 5.0.

© manpagez.com 2000-2017
Individual documents may contain additional copyright information.