You are on page 1of 8

Context-free grammars

Context-free syntax is
specified with a
grammar, usually in
Backus-Naur form (BNF)

1.
2.
3.
4.
5.
6.
7.

<goal> := <expr>
<expr>:= <expr> <op> <term>
|
<term>
<term>
:= number
|
id
<op> := +
|

A grammar G = (S,N,T,P)
S is the start-symbol
N is a set of non-terminal symbols
T is a set of terminal symbols
P is a set of productions P: N (N T)*
Oscar Nierstrasz

Compiler Construction

Deterministic Finite Automata Definition


A Deterministic Finite Automaton (DFA)
consists of:

Q ==> a finite set of states


==> a finite set of input symbols (alphabet)
q0 ==> a start state
F ==> set of final states
==> a transition function, which is a
mapping between Q x ==> Q

A DFA is defined by the 5-tuple:


{Q, , q0,F, }

Regular Languages
Let L(A) be a language recognized by
a DFA A.
Then L(A) is called a Regular
Language.

Locate regular languages in the


Chomsky Hierarchy

Non-deterministic Finite Automata


(NFA)
A Non-deterministic Finite Automaton
(NFA)
is of course non-deterministic
Implying that the machine can exist in more
than one state at the same time
Transitions could be non-deterministic
1
qi
1

qj

qk

Each transition function therefore


maps to a set of states
4

Non-deterministic Finite Automata


(NFA)
A Non-deterministic Finite Automaton
(NFA) consists of:

Q ==> a finite set of states


==> a finite set of input symbols (alphabet)
q0 ==> a start state
F ==> set of final states
==> a transition function, which is a
mapping between Q x ==> subset of Q

An NFA is also defined by the 5-tuple:


{Q, , q0,F, }

11/15/15

Dr. S. Nadeem Ahsan, IQRAUniversity

NFA Construction
Automatic construction example

a(b*c)

a(b|c+)?
Build
Build aa Disjunction
Disjunction

Conversion Example
continued
(4)table for the DFA of:
This gives the transition
Input Symbol
State

C
D
C
E
C

A
B
C
D
E

B
B
B
B
B
b
C

b
start

B
a

D
a

b
a

You might also like