Augustana University College

COMPUTING SCIENCE 370 -- Programming Languages


BNF and EBNF



Syntactic Structures

Lexics
rules by which characters are combined to form tokens (words, symbols)

Examples:

Syntax
rules by which tokens are combined to form language structures (expressions, statements, etc.)

Examples:

Semantics
the meaning attached to syntactic structures

Examples:

Formal Methods of Syntax Specification

  1. Backus-Naur Form (BNF), a metalanguage, gives a formula for constructing legal strings (but looks like examples of strings)

    Examples:

    <simpleExpr> ::= <term> | <sign><term> | <simpleExpr> <addOp> <term>
    
    <addOp> ::= + | - | or
    
    <unsigned integer> ::= <digit> | <unsigned integer><digit>
    

    where:

    Note that the last example above is a recursive definition. This is the standard way of specifying sequences of elements in BNF, and for describing nested syntax, as in:

    <statement> ::= <unconditional statement>
    
                 | if <expression> then <unconditional statement>
    
                 | if <expression> then <unconditional statement> else <statement>
    

    BNF was first used in the Algol-60 Report. (Backus had used a previous version to describe Algol-58.)

    Extended BNF improves the readability and conciseness of BNF through extensions:

  2. Syntax diagrams show legal strings in diagram form

    Syntax diagrams were first used in the Pascal User Manual and Report by Jensen and Wirth.

Exercises

  1. Give the equivalent of the syntax diagram above in EBNF.
     

  2. Consider the following BNF grammar rules:
    <pop> ::= [<bop>, <pop>] | <bop>

    <bop> ::= <boop> | (<pop>)

    <boop> ::= a | b | c

    Note that, since this is BNF, not EBNF, square brackets are terminal symbols.

    For each of the strings listed below, indicate all the syntactic categories of which it is a member, if any.

    1. c
    2. (a)
    3. [b]
    4. ([a,b])
    5. [(a),b]
    6. [(a),[b,a]]

Some Links

. Definition of Oberon 2 in EBNF

. Some Pascal syntax diagrams

Copyright © 2000 Jonathan Mohr