Page 210 - DCAP507_SYSTEM_SOFTWARE
P. 210

System Software




                    Notes          times be difficult to differentiate the BNF symbols from syntactic elements of the object language.
                                   This is one cause why some authors desire to include syntactic elements in quotation marks.
                                   There are numerous trivial variants of this notation. At times syntactic elements are included in
                                   quotation marks and the names of syntactic categories are written without the angle brackets.
                                   Sometimes an arrow of some sort is utilized in lieu of the ::= symbol.


                                          Example: Here's the tangible syntax of expressions of the -calculus:
                                   <lc-expression> ::= <lc-identifier>
                                   | ( lambda ( <lc-identifier> ) <lc-expression> )
                                   | ( <lc-expression> <lc-expression> )
                                   Dropping all of the fixed symbols provides us the equivalent abstract
                                   syntax:
                                   <lc-expression> ::= <lc-identifier>
                                   | <lc-identifier> <lc-expression>
                                   | <lc-expression> <lc-expression>
                                   When we construct our individual syntax trees in Scheme, we'll write a data type definition for
                                   every non-trivial syntactic category, with a variation for every rule. The right-hand side of the
                                   BNF rule informs us what the fields of the analogous variant should be-every field matches to
                                   one of the non-fixed constituents.
                                   It is hypothetically probable for the right-hand side of a BNF rule to be
                                   empty:
                                   <empty> ::=

                                   Practically, though, this possibility is rarely used. (For one thing, it messes up the association
                                   with syntax trees, as a node labelled with a syntactic category such as empty is technically a leaf
                                   node but gives no syntactic element to the noticeable text of the program.)

                                   13.2.3 Extensions


                                   Plain vanilla BNF is rather unwieldy. For convenient use, the notation is usually extended in
                                   different manners.
                                   It frequently occurs that two rules for the similar syntactic category vary only in the presence or
                                   absence of some optional constituent.


                                          Example: We show an example from Java:
                                   <break-statement> ::= break ;
                                   | break <identifier> ;
                                   Such a pair of rules can be united by including the possible component in braces and writing a
                                   question mark after it, therefore:
                                   <break-statement> ::= break {<identifier>}? ;

                                   Again, it frequently occurs that a constituent may include any number of consecutive components
                                   of the similar category. We'll state this in our comprehensive Backus-Naur formalism by including
                                   the repeatable constituent in braces and writing a star after it:
                                   <procedure-call> ::= ( <expression> {<expression>}* )



          204                               LOVELY PROFESSIONAL UNIVERSITY
   205   206   207   208   209   210   211   212   213   214   215