Dana Vrajitoru
C311 Programming Languages

Regular Grammars, Scanners, DFA

DFA versus NFA

NFA to DFA

Example: NFA (top) and equivalent DFA (bottom)

Regular Expressions

Examples

Finite States Machines

Scanner / Parser

Scanner in Context

  • A scanner that works in the context of a program in which it recognizes individual units.
  • It can be written to recognize the termination of a unit by a character that is not part of it.
  • We can replace:
    UN => digit UN
    UN => digit
    with:
    UN => digit UN
    UN => e

    Table Driven Scanner
    If the grammar is equivalent to a DFA, then we can organize the rules in a table:

    I => letter J
    I => _ J
    J => letter J
    J => digit J
    J => _ J
    J => - J
    J => e
    
    Table:
    letter digit _ - else
    I J err J err err
    J J J J J end