1. What is a programming language?
telling computer what to do?
Programing Language also can be a mean to communicate an algorithm or to describe a process
프로그래밍 언어는 단순히 컴퓨터에게 할 일을 지시하기 위한 도구가 아니라
어떤 작업의 순서, 과정을 설명하는 의사소통 수단으로의 역할을 한다.
2. How can machine understand a programming language?
CPU only understand assembly language consist of 0 and 1.
Compiler which is also a program translate a programming language into executable binary
compiler | interpreter |
Source code -> compiler -> machine code -> output | source code -> interpreter -> output |
* Interpreter : translate and execute a programing language
* Transpiler : translate a programing language to another programing language
컴퓨터, CPU는 고급 언어인 프로그래밍 언어를 바로 이해하지 못한다.
따라서 프로그래밍 언어의 종류에 따라서 compiler, interpreter의 도움을 받아 cpu가 이해할 수 있는 실행가능한 바이너리로 변환하여야 한다.
컴파일과정을 거치는 언어의 경우 Source code -> compiler -> machine code -> output 과정을 거친다.
translation에 시간이 소요되지만 실행시간은 매우 빠르다.

인터프리터는 즉시 source code의 한줄 한줄을 읽어서 바로 실행한다. source code -> interpreter -> output
translation과정이 따로 없었기 때문에 실행시간이 느리다.
3. Compilation process(phase)

(1) Let’s say there’s a code
int age = 26;
(2) Lexical analyzer breaks this line of code into int/age/=/26/;, we call these broken words as lexical units or lexeme. each lexeme has its own token,
int is Type
age is identifier
= is assignment
26 is int
; is semi-colon
This process is called tokenization
(3) Next, syntax analyzer make a parse tree with lexemes

(4) This parse tree will be transferred into “IR code generator”. and finally produce IR code
From programming language to IR is front-end, and from IR to Machine code is back-end
3.1. Hybrid(JIT, just in time) Implementation process
Java is one of the language which use compiler and interpreter (hybrid model) At Java we call IR as Java Byte code

자바 코드를 실행하기 위해서는 아래와 같은 과정이 필요하다.
1. 자바 파일(.java)을 자바 컴파일러(javac)를 통해 바이트코드 파일(.class)로 컴파일한다. 즉, 자바 컴파일러는 자바 소스코드를 JVM을 위한 기계어로 변환한다. (compile)
2. JVM의 실행 엔진 내에 있는 자바 인터프리터를 통해 바이트코드를 특정 환경의 기계어로 번역하고 실행한다. (interprete)
3.2. Pure interpreter implementation

4. What we are gonna study in this lecture is...
how a language can be translated into what cpu can understand.
Let's see the overview of this process
Source code(bytes) -> Lexer(tokens) -> Parser(parse tree) -> Semantic Analysis(analyze if the tree make sense)
Syntax : What is the valid program look like?
Semantics : What does it mean for a program to be valid? (type, define var before usage etc..)
Correctness : Is the program the correct one for the job? (success on every test case? etc...)
5. Von Neurmann Architecture

1. program counter points the next address of the instruction to be executed (not just increasing 1 by 1)
2. control unit fetch the instruction pointed by the counter from the momory
3. increase program counter
4. load instruction into cache and register
5. logic unit decode & exectute the instruction
컴퓨터의 구조, 소프트웨어 디자인 패턴은 프로그래밍 언어의 구조에 많은 영향을 미쳤다.
폰 노이만 구조에서는 cpu실행시간에 비해 분리되어있는 메모리로부터 데이터를 가져오는 시간이 오래걸린다. (bottleneck)
6. Preprocessor
Before compilation, expand embedded preprocessor macros (include codes from other files)
#include
#macro statements
xxx.c : source code
---------preprocessing---------
xxx.i
--------- compile ---------
xxx.s : assembly code
--------- assemble ---------
xxx.o : machine code
--------- Link ---------
xxx.exe
7. Linking
We have these two C++ files.
- xx.h
- xx.cpp
Each file will be translated into machine code but they don’t know each other, they are produced separately
so we have to go through linking process to let them know each other
'ComputerScience > Principle of programing language' 카테고리의 다른 글
PL6. Syntax Analysis - top down parsing (0) | 2023.10.06 |
---|---|
PL5. Dynamic semantics : Axiomatic (0) | 2023.10.04 |
PL4. Dynamic semantics : Operational, Denotational (0) | 2023.09.27 |
PL3. Static semantic (0) | 2023.09.15 |
PL2. Syntax (0) | 2023.09.14 |