수정입니다
Compilers Overview 본문
The move to higher-level lanuages
Machine => Assembly => Higher-level languages
=====================================> more people friendly, easier to develop
More human-friendly = Less computer-friendly
컴퓨터가 어떻게 high-level 로 작성된 걸 실행시킬 수 있을까?
=> Language translation(additional process) is required
The major role of language processors (compiler도 이것의 일종)
1. Language translation
- source code => semantically-equivalent target code (assembly / machine lang)
2. Error detection
- translation 과정 중 error를 잡아서 messages를 던짐
Two repersentative strategies for language processing
Compilation | Interpretation | |
What to translate | An entire source program | One statement of a source program |
When to translate | Once before the program runs | Every time when the statement is executed |
Translation result | A target program | Target code |
Examples | C, C++ | Javascript, python |
![]() |
![]() |
Compilation | Interpretation | |
Runtime Performance |
before execution, make target program => no run time overhead => fast |
require some run-time overhead => slow |
Portability / flexibility | each OS have own language ISA => translation as each in different machine language => portability, flexibility ↓ |
just install program in any kind of computer => portability, flexibility ↑ |
Debugging / development | Better when fixing a lot of things (no need to fix it one by one) |
Better when fixing a little part of long code (only check needed part) |
** Variation : Hybrid compilers
- compiler make intermediate program that is easy to traslation into target program
- => reduce run-tiem overhead
- intermediate program can use any type of computer
- => indepentdent of computer type
Requirements for designing good compilers
1. Correctness(mandatory)
==> 반드시!! source pgm 을 target pgm으로 semantically equivalent하게 잘 바꿔야함
2. Performance improvement(optional)
3. Reasonable compilation time(optional)
Structure of modern compilers
Lexical analyzer
- divides the stream of characters into meaningful sequences and produces a set of tokens
- A = B+C ===> A, =, B, +, C
Syntax analyzer
- creates a tree-like intermediate representation
Semantic analyzer
- checks the source pgm for semantic consistency with the language definition
- ex) type checking/conversion
Intermediate code generator
- easy to produce and easy to translate into a target machine code
- ex) t1 = inttofloat(C), t2 = t1+B, A = t2
Code optimizer(optional)
- ex) t1 = inttofloat(C), A = t1+B
Code generator
- maps an intermediate source into the target language
'전공 > 컴파일러' 카테고리의 다른 글
Code optimization (0) | 2024.06.09 |
---|---|
Intermediate code generator (1) | 2024.06.08 |
Semantic Analyzer (1) | 2024.06.08 |
Syntax Analyzer (Parser) (1) | 2024.06.08 |
Lexical Analysis (1) | 2024.04.18 |