Here are some things I didn't mention in section. Reading this will motivate you to study regular expressions and finite automata, and hopefully help you to understand more about FAs. This article will also be linked from my homepage at http://xcf.berkeley.edu/~alice/cs164-sp99/ Outline 1. the big picture 2. more on the difference between DFAs and NFAs Content 1. the big picture Q: Why do we want to do lexical analysis in the first place? And why regular expressions? A: The typical programming language constructs are: a. keywords and operators, e.g. "if", "else", "+", "=", etc. b. identifiers, e.g. "i", "j", "num1", "int", etc. c. numbers, d. grouping constructs, e.g. '{', '}', ';', '"', etc. e. quoted strings, f. comments. Our first goal in analyzing a program is to give it structure, and thus dividing it up into sizeable little chunks. This is best achieved by looking for keywords. The naive method here would be to do string comparison between each word in the source program and the set of keywords in the programming language. That would be painfully slow. The less naive method notices that there are patterns in the strings of characters. For instance, a simple description of a number would be a string of numbers 0-9, followed by a decimal point, followed by another string of numbers. Thus we develop the notion of regular expressions, which concisely describe certain patterns. There are also patterns that regular expressions are powerless to describe. An example of non-regular expressions is sequences of balanced parentheses. These will have to be taken care of in the next phase of the compiler, with the help of context-free grammars. We will talk about that when we get there. DFA/NFA are used to present alternative representations of regular expressions. The reason why we study them in a compilers course is because they can be easily translated into programs that recognize those patterns. DFA, NFA, and regular expressions are all equivalent in power. One can freely convert any one of the three to the other two, although sometimes going one direction is easier than another. 2. Difference between DFAs and NFAs NFA simulations can be in more than one state at any given time. This is a direct result of epsilon-transitions, and multiple transitions out of one state on the same input. In order to convert an NFA to a DFA, one needs to analyze all the possible routes through the automaton, and encode them in a new set of states and transitions. The resulting DFA usually has more states than NFAs. This is a classic trade-off between time and space. NFAs take up less space to store, but more time to simulate. DFAs are easy to similate, but are usually less intuitive to construct directly, and takes up more space to describe. Hope this helps.