Monday 24 June 2013

BNF Backus-Naur Form

The similarity of our "productions" with the computer BNF is shown
in the following example.
Variables can be any string, we use uppercase letters and numbers.
Terminals are enclosed in apostrophes.
Colon, :, replaces arrow, ->
Vertical bar, |, is "or"

  Computer BNF                       Production
  file type  .y                      file type  .g

S : 'a'                            S -> a
  | 'a' S                          S -> aS

                                   S -> a | aS
                         
              

term : var '*' var                     
T1   : V1  '*' V1                  T1 -> V1*V1  when * in Sigma


B :                                B -> epsilon | Bab | Bb
  | B 'a' B
  | B 'b'


Additional actions/output/statements can be used in computer BNF, { stuff }

C : 'c'    
           { printf("found a 'c' \n); }
  | 'c" C  
           { printf("here comes more 'c' \n); }

Thus, formatting, put "|" under ":". May also need or use ";"

No comments:

Post a Comment