Groundhog's Day

BNF

  • A set of symbols including:
  • a set of rules for producing strings in the language.
  • Postal Example:
  • Grammar for a simple assignment statements:
    <assign> -> <id> = <expr>
    <id> -> A | B | C
    <expr> -> <ID> + <expr>
              | <id> * <expr>
              | (<expr>)
              | <id>
    
    
    A = B * (A + C)
    

  • Fix the OP:
    <assign> -> <id> = <expr>
    <id> -> A | B | C
    <expr> -> <ID> + <term>
                  | <term>
    <term> -> <term> * <factor>
                  | <factor>
    <factor> -> (<expr>)
    	      |<id>
    
  • BNF rules for Java
  • Non-recursive
  • Recursive
  • Whitespace -
    FORTRAN treated blanks as completely insignificant in the body of a statement. This could sometimes be convenient, e.g., to make numbers and variable names more readable.

    Two Equivalent Forms

    HIVAL = 14713678923
    HI VAL = 14 713 678 923

    However, ignoring blanks can sometimes cause problems. For example, consider the looping statement:

    DO 3 I = 1,3

    Suppose this were mistakenly coded with a period instead of a comma.

    Two Equivalent Forms
    DO 3 I = 1.3 DO3I = 1.3

    The interpretation would be as a variable assignment.

    Unfortunately, exactly this kind of error occurred in the control program for a Mariner spacecraft to Venus, resulting in its loss. (Annals of the History of Computing, 1984, 6(1), page 6).

  • Some of Rocky's Ross's Research, Webworks a animated tool for showing Context Free Grammars

    Sample Questions: