1 / 25

Lecture 1 1: Semester Review

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

Télécharger la présentation

Lecture 1 1: Semester Review

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 11: Semester Review COMP3100 Dept. Computer Science and Technology United International College

  2. Introduction • Compilation vs. Interpretation • Compilation stages

  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

  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.

  5. Convert the following regular expression to a DFA • 1(0|1)*101

  6. Construct an NFA from it.

  7. Obtain an equivalent DFA

  8. Minimization

  9. 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

  10. 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

  11. Exercise • Given the following grammar S->a|^|(T) T->T,S|S • Eliminate the left-recursion in the grammar. • Build the LL(1) parsing table

  12. Left-recursion Elimination

  13. Parsing table construction

  14. 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)

  15. 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

  16. Given the following grammar S->AS|b A->SA|a (1) Build the full LR(0) DFA (2) Is it an SLR(1) grammar?

  17. 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).

  18. Semantic Analysis • Syntax-directed definition • Semantic actions • Synthesized attribute • Inherited attribute • lexical, syntax, semantic errors • Symbol table construction • Type derivation

  19. Intermediate Code Generation • Translate high-level to low-level sentences • 4 Distinct Regions of Memory • Execution Stack • Activation record/frame

  20. Running time organization • Parameter passing modes • Value • Reference • Value/result • Name

  21. 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]); • }

  22. Mark Distribution

  23. Good Luck!

More Related