a.pptx
Transcript of a.pptx
© Oscar Nierstrasz Compiler Construction
Context-free grammars
1. <goal> := <expr>2. <expr> := <expr> <op> <term>3. | <term>4. <term> := number5. | id6. <op> := +7. | -
Context-free syntax is specified with a grammar, usually in Backus-Naur form (BNF)
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)*
1
2
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, δ }
3
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
4
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
qi
1
1
qj
qk
… • Each transition function therefore maps to a set of states
5
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, δ }
22.04.2023 Dr. S. Nadeem Ahsan, IQRA-University 6
NFA Construction
• Automatic construction example
• a(b*c)
• a(b|c+)?Build a Disjunction
Conversion Example – continued (4)
StateInput Symbol
a b
A B C B B D C B C
E B C D B E
A
C
B D Estart bb
b
b
b
aa
a
a
This gives the transition table for the DFA of: