Skip to content
VUBuddy

CS606 Short Notes Lecture 7

Compiler Construction PDF 37 KBUpdated 23 Oct 2026
Quiz CS606 Short Notes Lecture 7 PDF 37 KB
vubuddy.com
Type
Quiz
Course
CS606 Compiler Construction
Size
PDF 37 KB
Updated
23 Oct 2026
Free download 0 of 3 used today
Download free · 37 KB

You get 3 free files a day on the website. Add the Chrome extension for 30 a day.

Unlimited downloads in the Android app Get it free on Google Play

Preview text

Text from pages 1, 2, 3 of 4. Download the file for all 4 pages.

Lecture 7

Table Encoding of FA

A FA can be encoded as a table. This is called a transition table. The following example shows a FA encoded as a table.

a · b · a · a · b · err · err · err

The rows correspond to states. The characters of the alphabet set Σ appear in columns. The cells of the table contain the next state. This encoding makes the implementation of the FA simple and efficient. It is equally simple to simulate or run the FA given an alphabet and a string of the language and its associated alphabet set Σ. The C++ code shows such a FA simulator.

int trans_table[NSTATES][NCHARS]; int accept_states[NSTATES]; int state = INITIAL; while(state != err){ c = input.read(); if(c == EOF ) break; state=trans_table[state][c];

return accept_states[state];

RE ? Finite Automata

We now have a strategy for building lexical analyzer. The tokens we want to recognize are encoded using regular expressions. If we can build a FA for regular expressions, we have our lexical analyzer. The question is can we build a finite automaton for every regular expression? The answer, fortunately, is yes – build FA inductively based on the definition of Regular Expression (RE). The actual algorithm actually builds Nondeterministic Finite Automaton (NFA) from RE. Each RE is converted into an NFA. NFA are joined together with ε-moves. The eventual NFA is then converted into a Deterministic Finite Automaton (DFA) which can be encoded as a transition table. Let us discuss how this happens.

Nondeterministic Finite Automaton (NFA)

An NFA can have multiple transitions for one input in a given state. In the following NFA, and input of 1 can cause the automaton to go to state B or C.

A B C

It can also have e–moves; the automaton machine can move from state A to state B without consuming input.

ε

A B

The operation of the automaton is not completely defined by input. A NFA can choose whether to make ε-moves and which of multiple transitions to take for a single input. The acceptance of NFA for a given string is achieved if it can get in a final state.

Deterministic Finite Automaton (NFA)

In Deterministic Finite Automata (DFA), on the other hand, there is only one transition per input per state. There are no ε-moves. Upon execution of the automaton, a DFA can take only one path through the state graph and is therefore completely determined by input.

NFAs and DFAs recognize the same set of languages (regular languages). DFAs are easier to implement – table driven. For a given language, the NFA can be simpler than the DFA. DFA can be exponentially larger than NFA. NFAs are the key to automating RE ? DFA construction.

RE ? NFA Construction

The algorithm for RE to DFA conversion is called Thompson’s Construction. The algorithm appeared in CACM 1968. The algorithm builds an NFA for each RE term. The NFAs are then combined using ε-moves. The NFA is converted into a DFA using the subset construction procedure. The number of states in the resulting DFA are minimized using the Hopcroft’s algorithm.

Given a RE, we first create NFA pattern for each symbol and each operator. We then join them with ε-moves in precedence order. Here are examples of such constructions:

  1. NFA for RE ab.

The following figures show the construction steps. NFAs for RE a and RE b are made. These two are combined using an ε-move; the NFA for RE a appears on the left and is the source of the ε-transition.

ε

s0

a

s1 NFA for a

s0 a s1

NFA for ab s3 b s4 s3

b

s4 NFA for b

ε

s0 a s1

NFA for ab s3 b s4

  1. NFA for RE a|b

ε · s0 · s5 · s1 a · s2 · NFA for a | b · s3 b · s4 · ε · ε · ε

  1. NFA for RE a*

ε · s0 · s4 · s1 a · s2 · NFA for a* · ε · ε · ε

All CS606 files →
CS606 Compiler Construction All CS606 handouts, past papers, quizzes and MCQs in one place. Open course page

Get more out of VUBuddy, for free

Android app Free on Google Play
  • Unlimited downloads
  • The explanation behind every MCQ answer
  • Study offline on slow data
Get the Android app
Chrome extension Free on the Chrome Web Store
  • 30 downloads a day instead of 3
  • Sign in and buy Pro Semester here
Add to Chrome

One Pro Semester membership works in both the extension and the app.