220 likes | 359 Views
Compiler Construction. 1 장. 간략한 소개. Aho, Sethi and Ullman Kenneth C. Louden Thomas W. Parsons 관련 과목 Theories of programming languages Automata theory System programming (including O.S) Assembly language Data structures and File structures Programming techniques.
E N D
간략한 소개 • Aho, Sethi and Ullman • Kenneth C. Louden • Thomas W. Parsons • 관련 과목 • Theories of programming languages • Automata theory • System programming (including O.S) • Assembly language • Data structures and File structures • Programming techniques
Compilers and Interpreters • Compilers source program compiler target program |__ error messages • Interpreters source program interpreter result data __|
역사 • 컴파일러 역사 • John Backus : FORTRAN compiler • Backus-Naur Form and Algol • N. Wirth : Pascal • C : System programming language • Ada : Language Environment • Java, C#, ….
인터프리터 • Basic …. Bill Gates • APL … an intolerable complexity • Smalltalk … Object oriented languages • LISP … lambda calculus …. Incremental programming • Java … for ubiquitous computing, Internet • Embedded systems
New paradigm • For Internet, Home computing, Ubiquitous computing, embedded systems and so on • Languages and Compilers that are Small, Smart and Safe • Hybrid approach with concepts of compilers and interpreters • Java, C# • Virtual machine • Free University, Tannenbaum • 개념 설명
Java • Simple, Robust, Object-oriented, Platform-independent, multithreaded, dynamic, general-purpose programming environment • Write-once, Run Anywhere • Java virtual machine • Bytes codes : portability and platform independent • Java Runtime Environment
Software tools related to compilers • Structure editors • Pretty printers • Static checkers • Interpreters • Text formatters … tex, nroff, troff • Silicon compilers … System on chip • Query interpreter • Interpreters for HTML, XML, SGML
Fig. 1.3. A language-processing system preprocessor Skeletal source program Source program Target assembly program Relocatable machine code library, relocatable object files Absolute machine code compiler assembler Loader/link-editor
Lexical Analysis • Finite state machine Regular expression Regular grammar • Kleen closure • O(n) • Lex • Editor, pattern search • Perl : $x =~ thing
Lexical Analysis In a compiler, linear analysis is called lexical analysis or scannning. For example ,in lexical analysis the characters in the assignment statement position := initial + rate * 60 Would be grouped into the following tokens: 1. The identifier position. 2. The assignment symbol := 3. The identifier initial. 4. The plus sign. 5. The identifier rate. 6. The multiplication sign. 7. The number 60. The blanks separating the characters of these tokens would normally be eliminated during lexical analysis.
Syntax Analysis(Parsing) • Push-down automata Context-free grammar • BNF(Backus-Naur Form) • O(n3) • LL, LR parsing • PLs, XML, HTML … • Interpretation framework • YACC … syntax-directed translation engine
Syntax Analysis Fig. 1.4 Parse tree for position := initial + rate + 60
Semantic Analysis • Context-sensitive grammar bounded Turing machine • Unrestricted grammar Turing machine • Unsolvable problem …. Heuristic rules • Type checking, resolving overload, scope rule, binding, …. • Syntax-directed translation engine
Fig. 1.5. Semantic analysis inserts a conversion from integer to real.
Code optimization and generation • Speed, space • Data-flow analysis data flow engines • Two pass optimization • Pseudo code level : P-code, Bytes code • Target code level : register allocation, select efficient operations, efficient pipelining … • RISC machine의 실패(????) • Alpha chip • Free University’s approach, down loading • Automatic code generators
Fig. 1.11. The data structure in (b) is for the tree in (a).
(1.3) (1.4) (1.5)
Others • Portability • A라는 컴파일러가 M에서 수행될 때, N이라는 기계에 이식하는 방법: 먼저 M에서 intermediate code에서 N 기계의 machine code로 바꾸는 루틴을 작성하고, A로 A 컴파일러를 작성한 후, 이를 컴파일하고, intermediate code로 만든 후 N기계의 기계어를 생성한다. 그리고 이를 down load하여 사용… • 컴파일러 개발에서 사용하는 방법 • Multi-passes or single pass
Term project • Compiler 작성 • Java, C, XML, …선택 가능 • 최대한 도와줄 것임 …조교가 직접 자신이 짠 프로그램을 설명하고, code generation part는 강의에 포함하여 짤 수 있게 함 • Bytes code는 설명할 것임 • Java를 추천