lecture 1 1: semester review

Post on 30-Dec-2015

24 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

Lecture 1 1: Semester Review. COMP 310 0 Dept. Computer Science and Technology United International College. Introduction. Compilation vs. Interpretation Compilation stages. DFA and its equivalents. DFA&NFA Definition Accepted string Regular expression Notation Accepted string - PowerPoint PPT Presentation

TRANSCRIPT

112/04/19 Page 1

Lecture 11: Semester Review

COMP3100Dept. Computer Science and TechnologyUnited International College

112/04/19 2

Introduction

Compilation vs. Interpretation Compilation stages

112/04/19 3

DFA and its equivalents DFA&NFA

Definition Accepted string

Regular expression Notation Accepted string Convert to NFA and DFA

Regular grammar Definition

DFA=NFA=Regular expression=Regular grammar

112/04/19 4

Regular expression->DFA Start with a regular expression. Construct an NFA from it. Use a set of subsets construction to obtain

an equivalent DFA. Construct the minimal equivalent DFA.

112/04/19 5

Convert the following regular expression to a DFA

1(0|1)*101

112/04/19 6

Construct an NFA from it.

112/04/19 7

Obtain an equivalent DFA

112/04/19 8

112/04/19 9

Minimization

112/04/19 10

PDA and its relevant Context free languages

Definition PDA

Definition Difference between PDA and DFA How does it work?

A language is context-free iff a pushdown automata recognizes it

Non-deterministic PDA are more powerful than deterministic ones

112/04/19 11

Parser-Top down parsing Predicts a derivation

Matches non-terminal against token observed in input

How to parse given a parse table? First set, follow set Parse table construction LL(1) grammar Convert non-LL(1) grammar to LL(1)

grammar

112/04/19 12

Exercise

Given the following grammar S->a|^|(T) T->T,S|S

(1) Eliminate the left-recursion in the grammar.(2) Build the LL(1) parsing table

112/04/19 13

Left-recursion Elimination

112/04/19 14

Parsing table construction

112/04/19 15

Parser-Bottom up parsing

Right-most derivation – Backward Start with the tokens End with the start symbol Match substring on RHS of production,

replace by LHS Parsing given parsing table for LR(0) Parsing table construction for LR(0) Right-associative is not LR(0)

112/04/19 16

Parser-Bottom up parsing (2)

SLR Apply reduction only if C is in FOLLOW(X)

LR(1) LR(1) parsing table construction

LALR Constructs LR(1) DFA and then merge any 2

LR(1) states whose items are identical except lookahead

Classification of grammar

112/04/19 17

Given the following grammar S->AS|b A->SA|a

(1) Build the full LR(0) DFA (2) Is it an SLR(1) grammar?

112/04/19 18

112/04/19 19

For state I1, note that Follow(S’)={$}. Hence, the shift-reduce conflict in state I1 can be solved in SLR(1).

For state I6, note that Follow(A)={a,b}. Hence, there is a shift-reduce conflict in state I6 which cannot solved in SLR(1).

For state I7, note that Follow(S)={a,b,$}. Hence, there is a shift-reduce conflict in state I7 which cannot solved in SLR(1).

112/04/19 20

Semantic Analysis

Syntax-directed definition Semantic actions Synthesized attribute Inherited attribute

lexical, syntax, semantic errors Symbol table construction Type derivation

112/04/19 21

Intermediate Code Generation

Translate high-level to low-level sentences

4 Distinct Regions of Memory Execution Stack Activation record/frame

112/04/19 22

Running time organization

Parameter passing modes Value Reference Value/result Name

112/04/19 23

Parameter Passing Modes

int i; int A[3]; void Q(int B) { A[1] = 3; i = 2; write(B); B = 5; } int main() { i = 1; A[1] = 2; A[2] = 4; Q(A[i]); }

112/04/19 24

Mark Distribution

DFA, Regular language and Scanner 24

CFG and Parser 40

Semantic Analysis 19

Intermediate Code Generation 5

Runtime Organization 12

112/04/19 25

Good Luck!

top related