10/27-W7
Abstract Syntax Trees
- 直接將 代碼 轉換成 樹狀 的方式表示
- 打包工具 與 代碼編譯 的核心原理
- 要能夠從記錄的資料還原成原始資料。
- example: 右圖為轉換為 AST 之後的樣子(JaveScript)
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Abstract Syntax Trees
Design of an AST
⬢ Rule of thumb: It should be possible to
unparse an AST.
⬢ The implementation of an AST should be
decoupled from the essential information
represented within the AST.
⬢ There is no single glass hierarchy that can
serve to describe AST nodes for all purposes.
Three-Address Code
- Three address code in Compiler
- It makes use of at most three addresses and one operator (on the right side of an instruction) to represent an expression
that is, no built-up arithmetic expressions are permitted.
- And the value computed at each instruction is stored in temporary variable generated by compiler.
Example: a+a*(b–c)+(b–c)*d
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Addresses
An address can be:
⬢ A name
⬢ A constant
⬢ A compiler-generated temporary
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Implementation of Three Address Code
- 3 representations of three address code namely
- Quadruple
- Triples
- Indirect Triples
1. Quadruple
2. Triples
3. Indirect Triples
Summing up (Example of Implementation of Three Address Code)
Question – Write quadruple, triples and indirect triples for following expression :
(x + y) * (y + z) + (x + y + z)
Answer -
The three address code is:
t1 = x + y
t2 = y + z
t3 = t1 * t2
t4 = t1 + z
t5 = t3 + t4
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- requires that each variable be assigned exactly once.
- every variable be defined before it is used.
Quiz6