인터프리터 / 컴파일러는 어떻게 작동합니까?
인터프리터 / 컴파일러는 어떻게 작동합니까? 인터프리터와 컴파일러의 차이점은 무엇입니까?
컴파일러
컴파일러는 작성된 최초의 번역 프로그램이었습니다. 아이디어는 간단합니다. 프로그램을 작성한 다음이를 번역하는 컴파일러에 넘깁니다. 그런 다음 결과를 실행합니다.
통역사
인터프리터는 또한 높은 수준의 언어를 낮은 수준의 언어로 번역하는 프로그램이지만 프로그램이 실행되는 순간에 수행합니다. 텍스트 편집기 또는 유사한 것을 사용하여 프로그램을 작성한 다음 인터프리터에게 프로그램을 실행하도록 지시합니다. 프로그램을 한 번에 한 줄씩 가져 와서 실행하기 전에 각 줄을 번역합니다. 첫 번째 줄을 번역하고 실행 한 다음 두 번째 줄을 번역하고 실행합니다.
컴파일러 특성 :
- 프로그램을 분석하고 처리하는 데 많은 시간을 소비합니다.
- 결과 실행 파일은 특정 형태의 기계 별 바이너리 코드입니다.
- 컴퓨터 하드웨어가 결과 코드를 해석 (실행)합니다.
- 프로그램 실행이 빠르다
통역사 특성 :
- 프로그램을 분석하고 처리하는 데 소요되는 시간이 비교적 적습니다.
- 결과 코드는 일종의 중간 코드입니다.
- 결과 코드는 다른 프로그램에서 해석됩니다.
- 프로그램 실행이 상대적으로 느립니다.
번역가 란 무엇입니까?
S는 -> T 역자 소스 언어 S 표현 코드를 수용하고, 다른 (목표) T. 언어로 표현 된 코드 등가로 변환
번역자의 예 :
- 컴파일러-고수준 코드를 저수준 코드로 변환합니다 (예 : Java-> JVM).
- 어셈블러-어셈블리 언어 코드를 기계어 코드로 변환합니다 (예 : x86as-> x86).
- 고급 변환기-하나의 PL에서 다른 PL로 코드를 변환합니다 (예 : Java-> C).
- 디 컴파일러-저수준 코드를 고수준 코드로 변환합니다 (예 : Java JVM 바이트 코드-> Java).
통역사는 무엇입니까?
S 인터프리터 언어 S 표현 코드를 받아들이고, 즉시 그 코드를 실행한다. 한 번에 하나의 명령을 가져오고, 분석하고, 실행하여 작동합니다.
사용자가 대화식으로 명령어를 입력하고 (Python을 생각하면) 다음 명령어를 입력하기 전에 출력을 얻고 싶을 때 좋습니다. 프로그램이 한 번만 실행되거나 이식 가능해야하는 경우에도 유용합니다.
- 프로그램 해석은 원시 기계 코드를 실행하는 것보다 훨씬 느립니다.
- 고급 언어 해석은 ~ 100 배 더 느립니다.
- 중간 수준 (예 : JVM 바이트 코드) 언어 해석은 ~ 10 느립니다.
- 명령이 반복적으로 호출되면 반복적으로 분석되므로 시간이 많이 걸립니다!
- 코드를 컴파일 할 필요가 없습니다.
차이점
행동
컴파일러는 소스 코드를 기계 코드로 변환하지만 소스 또는 개체 코드를 실행하지 않습니다.
인터프리터는 소스 코드를 한 번에 하나씩 명령을 실행하지만 소스 코드를 번역하지는 않습니다.
공연
- 컴파일러는 소스 프로그램을 원시 기계 코드로 변환하는 데 시간이 오래 걸리지 만 후속 실행은 빠릅니다.
- 인터프리터가 소스 프로그램 실행을 즉시 시작하지만 실행 속도가 느립니다.
해석 컴파일러
인터 프리 티브 컴파일러는 컴파일러와 인터프리터 간의 좋은 절충안입니다. 소스 프로그램을 가상 머신 코드로 변환 한 다음 해석합니다.
해석 컴파일러는 다음과 같은 경우 빠른 번역과 적당히 빠른 실행을 결합합니다.
- VM 코드는 소스 언어보다 낮지 만 원시 기계 코드보다 높습니다.
- VM 명령어는 간단한 형식을 가짐 (통역사가 빠르게 분석 할 수 있음)
예 : JDK는 Java 용 해석 컴파일러를 제공합니다.
컴파일러 는 한 컴퓨터 언어의 소스 코드를 다른 언어로 변환합니다.
Interpreter 는 소스 코드를 직접 실행합니다 (일반적으로 자체 가상 머신 내부에서).
(출처 : answers.com )
일반적으로 인터프리터는 성능이 비쌉니다.
인터프리터와 컴파일러의 차이점은 무엇입니까?
컴파일러는 제 프로그램 전체를 스캔하고 컴퓨터 프로세서에 의해 실행될 머신 코드로 변환한다.
통역 을 실행하고 다음 문장을 진행, 기계 언어로 하나 개의 문장을 변환합니다.
예 : 컴파일러는 거의 모든 오류를 한 번에 제공하지만 인터프리터는 사용자가 잘못 작성한 명령까지 실행됩니다.
인터프리터 / 컴파일러는 어떻게 작동합니까?
- 미리 기계어로 번역되는 컴파일 된 언어와는 다릅니다 (오른쪽).
- 해석 된 언어는 런타임에 번역됩니다.
- dBASE 및 BASIC 인터프리터 (중간)는 원본 소스 코드를 번역합니다.
- Java 및 Visual Basic (왼쪽) 인터프리터 는 원본 소스 코드 에서 컴파일 된 중간 언어 인 바이트 코드를 번역 합니다 .
차이점과 작동 방식
Q: What are Compilers and interpreters used for ?
A: Most programs are written in High-level languages (c#,java...). High-level languages are which contain understandable words and phrases. On the other hand computer (by the time I wrote this article that is) understand machine code which is 0's and 1's only aka Binary/Machine Code. Therefore we need to convert the High-level code into source code which is (Machine code/binary). Hence the word converting.
So we conclude a Compiler/interpreter job is to Translate high-level code into machine code.
But both have a different way of 'Translating' the code
Difference:
Compiler:
converts source code to some kind of intermediate form. For static language, a compiler usually converts the source code to assembly, which usually did not get stored to disk, then the assembler is invoked to convert the assembly to binary code, which is usually stored as object file(.o or .obj suffix usually), then linker is invoked to link object file(s) to binary executable. Also it is common to refer to this whole process of compiling, assembling, linking as compiling. So you may call gcc a compiler, but it actually invokes cc1 which is the compiler to compile, as which is the assembler to assemble, ld which is the linker to link.
Interpreter:
language which has a intermediate so called bytecode form, the source code is first converted to byte code, this process can be called compiling, javac serves as an example. Bytecode cannot be run on host machines, it needs a program, which is actually the process from the viewpoint of OS, to interpret the bytecode to the host machine, this program is called a interpreter, think of java. Some language, like python, do the compiling and interpreting work with a single
— both from: https://www.quora.com/What-are-the-differences-between-a-compiler-an-interpreter-and-an-assembler-Provide-examples
Comparing
Interpreter
- It takes less amount of time to analyze the source code but the overall execution time is slower.
- No intermediate object code is generated, hence are memory efficient.
- Continues translating the program until the first error is met, in which case it stops. Hence debugging is easy.
Compiler
- It takes large amount of time to analyze the source code but the overall execution time is comparatively faster.
- Generates intermediate object code which further requires linking, hence requires more memory.
- It generates the error message only after scanning the whole program. Hence debugging is comparatively hard.
— from: https://www.programiz.com/article/difference-compiler-interpreter
Examples with Languages
Interpreted
- Python
- Ruby
- PHP
- JAVA(Almighty)
- Perl
- R
- Powershell
compiled
- C
- C++
- C#
- Objective-C
- SWIFT
- Fortran
Compilers - A compiler translates a source language to a target language. Then the target language takes input and gives output.
Compiler produces a target code by compiling source code
then target code then takes input and gives output
Interpreters - Instead of generating a target code, Interpreter appears to take input directly along with source code and gives output.
Interpreter maps input to output using the source program
Then machine-language targeted program produced by the compiler is much faster than the interpreter at mapping inputs to output. However, since interpreter executes source program line by line it gives better error diagnostics than compiler.
Reference - Compilers: Principles, Techniques, and Tools by Aho aka the dragon book
What is the difference between interpreter and compiler.
To put it directly and intuitively:
Compiler is what translates the human-readable source code into machine code which the computer could read and execute.
Interpreter is what pretends to be or simulates a computer to read and execute the source code directly.
Look at PLAI book, it's the best intro to dymanic language realization I found ever:
Programming Languages: Application and Interpretation (c) Shriram Krishnamurthi
- [home] https://cs.brown.edu/~sk/Publications/Books/ProgLangs/2007-04-26/
- [html] http://cs.brown.edu/courses/cs173/2012/book/
- [pdf] http://www.cs.brown.edu/courses/cs173/2012/book/book.pdf
This book centers on writing interpreter for dynamic language in Scheme (dr.Racket), using it you can write your own interpreter for any language, and add some tips on OOP from
- [OOP PLAI] https://users.dcc.uchile.cl/~etanter/ooplai/ (c) Éric Tanter
및 SmallTalk 및 SOM : 단순 개체 시스템 :
모든 최신 인터프리터에는 컴파일러가 포함되어 있습니다. 상위 요소 를 하위 수준이지만 이식 가능한 바이트 코드로 컴파일하거나 JIT를 사용하여 기계 코드를 RAM으로 컴파일합니다.
추신 : 누군가 Python으로 SmallTalk 시스템을 작성하고 싶다면 저를 주목하십시오.
참고 URL : https://stackoverflow.com/questions/2377273/how-does-an-interpreter-compiler-work
'Programing' 카테고리의 다른 글
같은 페이지에서 다른 버전의 jQuery를 어떻게 실행합니까? (0) | 2020.11.08 |
---|---|
Clojure의 Let 대 바인딩 (0) | 2020.11.08 |
언제 stdClass를 사용해야하고 언제 PHP oo 코드에서 배열을 사용해야합니까? (0) | 2020.11.08 |
Xcode : 헤더 복사 : 공개 vs. 비공개 vs. 프로젝트? (0) | 2020.11.08 |
플렉스 아이템이 텍스트로 인해 넘치지 않게하는 방법은 무엇입니까? (0) | 2020.11.08 |