Download presentation
Presentation is loading. Please wait.
Published byMalakai Haskell Modified over 9 years ago
1
CSC 313 – Advanced Programming Topics
2
Today’s Goal Make you forget reading that was assigned I went back & reviewed others; none like this one Highlight process used by modern compilers Consider steps taken & how design works Where optimizations occur will be discussed Review a kick-ass design honed through years Understand decisions to see good design in action See design process that results in design patterns
3
Translations Translating docs from English to other language But all of this material selected from college library Undecipherable & meaningless documents included Workers highly-trained & so saving time (& $$) critical Reject untranslatable documents & explain why Need to give workers chance to correct mistakes Money important, so limit time on these documents
4
Translations Translating docs from English to other language But all of this material selected from college library Undecipherable & meaningless documents included Workers highly-trained & so saving time (& $$) critical Reject untranslatable documents & explain why Need to give workers chance to correct mistakes Money important, so limit time on these documents How can we do this?
5
What Errors Can Occur?
6
Document read in unreadable or not English Has “words”, but grammatically incorrect Meaningless jumble means cannot translate
7
What Errors Can Occur? Document read in unreadable or not English αυηθι μςτ ϕϖ κλσροπ χψτν γδζεεθ μςτυ Has “words”, but grammatically incorrect Meaningless jumble means cannot translate
8
What Errors Can Occur? Document read in unreadable or not English αυηθι μςτ ϕϖ κλσροπ χψτν γδζεεθ μςτυ Has “words”, but grammatically incorrect 4 u 2 c I sent U pix. ty Meaningless jumble means cannot translate
9
What Errors Can Occur? Document read in unreadable or not English αυηθι μςτ ϕϖ κλσροπ χψτν γδζεεθ μςτυ Has “words”, but grammatically incorrect 4 u 2 c I sent U pix. ty Meaningless jumble means cannot translate Mary flow over the swimming pizza
10
How To Translate?
12
Money, money, money! This project useful for many languages Different alphabet or punctuation may be used Will need to adjust to different grammar rules Change in scoping rules & variable declaration types
13
Money, money, money!
14
This project useful for many languages Different alphabet or punctuation may be used Will need to adjust to different grammar rules Change in scoping rules & variable declaration types Could translate to many different languages (Unless written by Microsoft or in Alabama)
15
How To Translate?
16
How To Translate? (Redux) Split translations process into multiple layers Lexical analyzer will check legal words & punctuation Grammar errors found by parser (syntactic analysis) Semantic analysis will check document meaningful Optimizations happen here, since program is valid Code generator “lowers” results into new language
17
All About the Benjamins Most layers’ actions language-dependent Reusing details hard, but algorithms very similar Between layers, pass language-independent data Define protocols specifying how layers interact Each layer independent & can change easily Limit rewriting, instead reuse whenever possible Must follow protocols, but these set out clearly Popular approach: gcc, XCode, Google Translate
18
Planning Data & Interactions Data to be passed depends on work layers do Individual words & punctuation output by lexer Parser goes through this data & find sentences Build paragraphs by checking sentences meaningful Interactions based on input size needed Item-by-item analyses needed to build sentences Semantic analysis works by using whole module Entire program needed for optimizations & output
19
Planning Data & Interactions Data to be passed depends on work layers do Individual words & punctuation output by lexer Parser goes through this data & find sentences Build paragraphs by checking sentences meaningful Interactions based on input size needed iteration Item iteration needed to build sentences Semantic analysis works by using whole module Entire program needed for optimizations & output
20
Resulting Design Lexer is an Iterator for words & punctuation Illegal characters found & reported as errors Parser builds syntax trees for each module Function, class, or file may be language’s module Must be conservative: outputs result for entire file Good syntax tree output by semantic analysis When use found, variable linked to declaration & type Match calls with functions & all checked if legal HIR Result called Higher-order Intermediate Representation
21
Lexical Analysis In Detail Creates “tokens” from file being compiled While it does this, checks characters are legal Keywords identified ( for, int, while …) in input Code parsed to identify literals (strings, numbers) Does not understand code; only splitting it out Only layer looking at code, so skips comments
22
How Does Lexer Work? Regular expressions defined for items to find They’re back!! Turned into big finite state machine Defines enum or hierarchy for returned data struct Symbol { Token type; String value; } enum Token { NUMBER, STRING, WORD, GT,,... }
23
Why Use State Machines? Limits knowledge needed for coding a lexer Machine has set of states connected by edges State determines next state, given an input Need to know initial & accepting states only States define language; processing unchanged
24
Why Use State Machines? Limits knowledge needed for coding a lexer Machine has set of states connected by edges State determines next state, given an input Need to know initial & accepting states only States define language; processing unchanged Obviously, this is part of State design pattern (Covered later in term, in case you wondering) Maximizes reuse of code within lexical analysis Limits rework to developing regular expressions
25
For Next Lecture Read pages 37 – 55 in book Get back into easier code & design patterns 1-to-many communication is problem why? Why is this critical to all event-based coding? Lindsay Lohan's secret to success related to this?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.