CS/System software
[System software] (4) Macro processor
jac99
2023. 12. 11. 06:13
The most common used of macro processor is in assembler language programming. Besides: high-level programming lang, general-purpose processor( not tied to any lang)
Macro function
Commonly used group of instructions
- Definition:
macro-name arguments
body
MEND
- Call: macro-name actual-parameters
- Expanding: by macro processor
Macro processor
Replace each macro instruction with the corresponding group of souce instructions
⇒ 매크로 확장
Basic macro funtion
- Macro 정의. #define max(A,B) ((A)>(B)?(A):(B))
- 호출: x = max(p+q,r+s)
- 확장: x = ((p+q) > (r +s) ? (p+q):(r+s))
Macro processor algorithm
- Two pass macro processor:
- Pass 1: 매크로 정의 처리
- Pass 2: 매크로 확장
- Single-pass macro processor:
- Pass 1: 매크로 정의 처리& 확장(단, 매크로 호출보다 앞에 정의되어 있어야 함)
사용되는 자료구조:
- DEFTAB : 매크로 정의 문장들
- NAMTAB: {매크로이름, DEFTAB가리키는것}
- ARGTAB: 실제 전달되는 인수들