CSE443 Compilers
- Dr. Carl Alphonce
CSE443 Compilers Dr. Carl Alphonce alphonce@buffalo.edu 343 Davis - - PowerPoint PPT Presentation
CSE443 Compilers Dr. Carl Alphonce alphonce@buffalo.edu 343 Davis Hall Team formation Please sit with your teams starting next week. C vs SML? Lexical Phases of structure a compiler Figure 1.6, page 5 of text languages & grammars
Figure 1.6, page 5 of text
Formally, a grammar is defined by 4 items:
G = (N, ∑, P, S)
N, a set of non-terminals ∑, a set of terminals (alphabet) N ∩ ∑ = {} P, a set of productions of the form (right linear) X -> a X -> aY X -> ℇ X ∈ N, Y ∈ N, a ∈ ∑, ℇ denotes the empty string S, a start symbol S ∈ N
L ∪ M = { s | s ∈ L or s ∈ M } union LM = { st | s ∈ L and t ∈ M } concatenation L* = ∪i=0,∞ Li Kleene closure
By definition, L0 = {ℇ}
Assume r and s are regexes. r|s is a regex denoting 𝓜(r)∪𝓜(s) rs is a regex denoting 𝓜(r)𝓜(s) r* is a regex denoting (𝓜(r))* (r) is a regex denoting 𝓜(r) Precedence: Kleene closure > concatenation > union Associativity: all left-associative (minimize use of parentheses: (r|s)|t = r|s|t )
language
language regex
language regex NFA
DFA
language regex NFA
DFA
DFA language regex NFA
DFA character stream token stream
DFA language regex NFA
regex NFA
A finite set of states S An alphabet ∑, ℇ ∉ ∑ 𝛆 ⊆ S X (∑ ∪ {ℇ}) X 𝒬(S) (transition function) s0 ∈ S (a single start state) F ⊆ S (a set of final or accepting states)
A finite set of states S An alphabet ∑, ℇ ∉ ∑ 𝛆 ⊆ S X ∑ X S (transition function) s0 ∈ S (a single start state) F ⊆ S (a set of final or accepting states)
N(s) N(t)
Initial state: arrow from nowhere pointing in. Often labelled state 0. Final state: drawn with a double circle Arrows are labeled with ℇ
N(s) N(t)
N(s) N(s)
N(t)
10 11 12 13
F