DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

(bison.info) Rules

Info Catalog (bison.info) Symbols (bison.info) Grammar File (bison.info) Recursion
 
 Syntax of Grammar Rules
 =======================
 
    A Bison grammar rule has the following general form:
 
      RESULT: COMPONENTS...
              ;
 
 where RESULT is the nonterminal symbol that this rule describes and
 COMPONENTS are various terminal and nonterminal symbols that are put
 together by this rule ( Symbols.).
 
    For example,
 
      exp:      exp '+' exp
              ;
 
 says that two groupings of type `exp', with a `+' token in between, can
 be combined into a larger grouping of type `exp'.
 
    Whitespace in rules is significant only to separate symbols.  You
 can add extra whitespace as you wish.
 
    Scattered among the components can be ACTIONS that determine the
 semantics of the rule.  An action looks like this:
 
      {C STATEMENTS}
 
 Usually there is only one action and it follows the components.  
 Actions.
 
    Multiple rules for the same RESULT can be written separately or can
 be joined with the vertical-bar character `|' as follows:
 
      RESULT:   RULE1-COMPONENTS...
              | RULE2-COMPONENTS...
              ...
              ;
 
 They are still considered distinct rules even when joined in this way.
 
    If COMPONENTS in a rule is empty, it means that RESULT can match the
 empty string.  For example, here is how to define a comma-separated
 sequence of zero or more `exp' groupings:
 
      expseq:   /* empty */
              | expseq1
              ;
      
      expseq1:  exp
              | expseq1 ',' exp
              ;
 
 It is customary to write a comment `/* empty */' in each rule with no
 components.
 
Info Catalog (bison.info) Symbols (bison.info) Grammar File (bison.info) Recursion
automatically generated byinfo2html