CSE443 Compilers Dr. Carl Alphonce alphonce@buffalo.edu 343 Davis - - PowerPoint PPT Presentation

cse443 compilers
SMART_READER_LITE
LIVE PREVIEW

CSE443 Compilers Dr. Carl Alphonce alphonce@buffalo.edu 343 Davis - - PowerPoint PPT Presentation

CSE443 Compilers Dr. Carl Alphonce alphonce@buffalo.edu 343 Davis Hall http:/ /www.cse.buffalo.edu/faculty/alphonce/SP17 /CSE443/index.php https:/ /piazza.com/class/iybn4ndqa1s3ei Syllabus Posted on website Covered most last class


slide-1
SLIDE 1

CSE443 Compilers

  • Dr. Carl Alphonce

alphonce@buffalo.edu 343 Davis Hall

http:/ /www.cse.buffalo.edu/faculty/alphonce/SP17 /CSE443/index.php https:/ /piazza.com/class/iybn4ndqa1s3ei

slide-2
SLIDE 2

Syllabus

Posted on website Covered most last class Academic Integrity

slide-3
SLIDE 3

Departmental Policy on Violations of Academic Integrity (AI)

The CSE Department has a zero-tolerance policy regarding academic integrity (AI) violations. When there is a potential violation of academic integrity in a course, the course director shall first notify the concerned students. This notification begins the review and appeals process defined in the University's Academic Integrity statement: http:/ /catalog.buffalo.edu/policies/course/integrity.html Upon conclusion of the review and appeals process, if the department, school, and university have determined that the student has committed a violation, the following sanctions will be imposed upon the student: § 1. Documentation. The department, school, and university will record the student's name in departmental, decanal, and university-level academic integrity violations databases. § 2. Penalty Assessment. The standing policy of the Department is that all students involved in an academic integrity violation will receive an F grade for the course. The course director may recommend a lesser penalty for the first instance of academic integrity violation, and the adjudication committees that hear the appeal at the department, decanal and provost level may recommend a lesser or greater penalty.

slide-4
SLIDE 4

Phases of a compiler

Figure 1.6, page 5 of text

Lexical structure

slide-5
SLIDE 5

Lexical Analysis

Lexical structure described by regular grammar Deterministic finite state machine performs analysis

slide-6
SLIDE 6

LANGUAGE operations

If L and M are regular, so are:

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 = {ℇ}

slide-7
SLIDE 7

Given an alphabet ∑ REGular EXpression (regex) Inductive definition

ℇ is a regex 𝓜(ℇ) = {ℇ} For each a ∈ ∑, a is a regex 𝓜(a) = {a}

slide-8
SLIDE 8

Regular expressions (regex) Inductive definition

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 )

slide-9
SLIDE 9

Algebraic laws

Assume r and s are regexes. Commutativity r|s = s|r Associativity r|(s|t) = (r|s)|t and r(st) = (rs)t Disributivity r(s|t) = rs|rt and (s|t)r = sr|tr Identity ℇr = rℇ = r Idempotency r** = r*

slide-10
SLIDE 10

We can describe a regular language using a regular expression

slide-11
SLIDE 11

A regular expression can be recognized using a finite state machine. Machines: NFA non-deterministic finite automaton DFA deterministic finite automaton

slide-12
SLIDE 12

Process of building lexical analyzer

language

1) spell out the language

slide-13
SLIDE 13

Process of building lexical analyzer

language regex

2) formulate a regular expression

slide-14
SLIDE 14

Process of building lexical analyzer

language regex NFA

3) build an NFA

slide-15
SLIDE 15

Process of building lexical analyzer

DFA

4) transform NFA to DFA

language regex NFA

slide-16
SLIDE 16

Process of building lexical analyzer

DFA

5) transform DFA to a minimal DFA

DFA language regex NFA

slide-17
SLIDE 17

Process of building lexical analyzer

DFA character stream token stream

lexical analyzer 5) The minimal DFA is

  • ur lexical analyzer

DFA language regex NFA

slide-18
SLIDE 18

Focus for today

regex NFA

slide-19
SLIDE 19

Nondeterministic Finite Automata (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)

slide-20
SLIDE 20

Deterministic Finite Automata (DFA)

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)

slide-21
SLIDE 21

Regex -> NFA

1 ℇ 1 a

N(s) N(t)

1 for each a ∈ ∑ S | t ℇ ℇ ℇ ℇ

slide-22
SLIDE 22

Regex -> NFA

N(s) N(s)

1

N(t)

1 ℇ ℇ ℇ ℇ St S*

slide-23
SLIDE 23

Simple example

static

slide-24
SLIDE 24

Simple example

static 1 2 3 4 5 6 s t a t i c

slide-25
SLIDE 25

Simple example

static struct 1 2 3 4 5 6 s t a t i c 7 8 9

10 11 12 13

s t r u c t i

F

ℇ ℇ ℇ ℇ