You are on page 1of 1

CS3005D - Compiler Design

Sheet 1 — Tutorial 1
Lexical Analysis

1. Draw a transition diagram for recognizing whitespace in a language. Note that a whites-
pace can be a combination of spaces, tabs or newline characters. Which token should
the lexical analyzer return when it encounters a whitespace?

2. Draw the transition diagram for recognizing a floating point number in your favourite
programming language.

3. Write a code for a lexical analyzer for the following grammar:

expr → expr + term|expr − term|term

term → term ∗ f actor|term/f actor|f actor

f actor → digit|(expr)

Note that digit may be any valid integer constant.

Page 1 of 1

You might also like