Presentation is loading. Please wait.

Presentation is loading. Please wait.

報告者:會計四 簡思佳 95303043. The process of converting a program written in a high-level language into a machine-executable form. language implementation Ex.C++

Similar presentations


Presentation on theme: "報告者:會計四 簡思佳 95303043. The process of converting a program written in a high-level language into a machine-executable form. language implementation Ex.C++"— Presentation transcript:

1 報告者:會計四 簡思佳 95303043

2 The process of converting a program written in a high-level language into a machine-executable form. language implementation Ex.C++ 、 JAVA… 一串 0 和 1 的排列 high-level language machine- executable form

3 The process of converting a program from one language to another. The program in its original form. The translated version.

4 Lexical analyzer Parser Code generator The translation process consists of three activities. Performed by the translator - lexical analyzer. Performed by the translator - parser. Performed by the translator - code generator. Source Object Program tokens parse trees program

5 The process of recognizing which strings of symbols from the source program represent a single entity, or token(lexical units). ex. 3 symbols 153 should be recognized as representing a numeric value. apple means rather than a-p-p-l-e. Lexical analyzer Parser Code generator

6 The lexical analyzer reads the source program symbol by symbol, identifying which groups of symbols represent tokens, and classifying those tokens according to whether they are numeric values, words, arithmetic operators. Lexical analyzer Parser Code generator

7 The process of identifying the grammatical structure of the program and recognizing the role of each component. The parser’s job is to group lexical units into statements. Each program statement is positioned in a particular manner. The position of statements is not criticals. Lexical analyzer Parser Code generator

8 A programmer is able to organize the written program in a way that enhances readability from a human’s point of view. ex. if Cost < CashOnHand then pay with cash else use credit card. if Cost < CashOnHand then pay with cash else use credit card. Lexical analyzer Parser Code generator

9 Most free-format languages use punctuation marks such as semicolons to mark the end of statements, as well as key words such as if, then, and else to mark the beginning of individual phrases. Pictorial representations of a language’s grammatical structure. if else then Boolean expression statement Lexical analyzer Parser Code generator

10 Expression Term Factor Lexical analyzer Parser Code generator + - x z y Term Expression ÷ × Factor Term

11 Parse tree x y z Lexical analyzer Parser Code generator Expression Term Expression FactorTerm Factor

12 The process of parsing a program is essentially that of constructing a parse tree for the source program. A grammar that does allow two distinct parse tree for one string is said to be an ambiguous grammar. ex. if B1 then if B2 then S1 else S2. if B1 if B1 then (if B2 then S1 ) and then (if B2 then S1 else S2 else S2 ) Lexical analyzer Parser Code generator

13 if then else B1 S2 if then B2 S1 Lexical analyzer Parser Code generator statement Boolean expression Boolean expression statement

14 if then B1 if then else B2 S1 S2 Lexical analyzer Parser Code generator statement Boolean expression Boolean expression

15 Symbol table contains such information as the name of the variables appearing in the program as well as what data types and data structures are associated with those variables. ex. z ← x + y; Lexical analyzer Parser Code generator

16 Implicit conversion between types. ex. z ← x + y; x is of type integer and y is of type float. The parser might choose to have the code generator build the instructions to convert one value to the other type and then perform the addition. Lexical analyzer Parser Code generator

17 Most modern languages are strongly typed, which means that all activities requested by a program must involve data of agreeable types. Java allows coercion as long as it is a type promotion, meaning that it involves converting a low precision value to a higher precision value. Lexical analyzer Parser Code generator

18 The process of constructing the machine-language instructions to implement the statements recognized by the parser. ‧ producing efficient machine-language versions ex. Code optimization Lexical analyzer Parser Code generator x ← y + z; w ← x + z;

19 The lexical analyzer begins by reading characters from the source program and identifying the first token. The parser receives a token and analyzes the grammatical structure being read. The code generator build machine instructions that are added to the object program. Lexical analyzer Parser Code generator

20 ~ E n d ~


Download ppt "報告者:會計四 簡思佳 95303043. The process of converting a program written in a high-level language into a machine-executable form. language implementation Ex.C++"

Similar presentations


Ads by Google