1 / 0

6.4 Language Implementation

6.4 Language Implementation. CH.6 Programming Langueges. 報告者:會計四 簡思佳  95303043. The process of converting a program written in a high-level language into a machine-executable form . language implementation Ex.C ++ 、 JAVA… 一串 0 和 1 的排列.

heaton
Download Presentation

6.4 Language Implementation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 6.4 Language Implementation

    CH.6 Programming Langueges 報告者:會計四 簡思佳 95303043
  2. The process of converting a program written in a high-level languageinto a machine-executable form. language implementation Ex.C++ 、JAVA… 一串0和1的排列 Language Implementation high-levellanguage machine-executable form
  3. The translation progress The process of converting a program from one language to another. The program in its original form. The translated version. Translation Source program Object program
  4. The translation progress 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 Lexical analysis Parsing Code generation Lexical analyzer Parser Code generator
  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 analysis 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 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. Parsing Fixed-format language Free-format language 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 < CashOnHandthen pay with cash else use credit card. if Cost < CashOnHand thenpay with cash elseuse credit card. Advantage of Free-format language Indentation 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. Syntax of Free-format language Syntax diagrams Lexical analyzer Parser Code generator Boolean expression statement statement if then else
  10. Expression Term Factor + Expression Term Term Factor - × ÷ x Lexical analyzer Parser Code generator y z
  11. Parse tree x y z Expression Expression Term Factor Term Factor Term Lexical analyzer Parser Code generator 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. ifB1then ifB2 then S1 elseS2. ifB1ifB1 then (ifB2 then S1 ) and then (ifB2 then S1 elseS2 elseS2 ) Lexical analyzer Parser Code generator
  13. if then else B1 S2 if then B2 S1 statement Boolean expression statement statement Lexical analyzer Boolean expression Parser Code generator statement
  14. if then B1 if then else B2 S1 S2 statement Boolean expression statement Boolean expression statement statement Lexical analyzer Parser Code generator
  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; Symbol table 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. Coercion 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. Strongly typed 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 Code generation x ← y + z; w← x + z; Lexical analyzer Parser Code generator
  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. Object-oriented paradigm Lexical analyzer Parser Code generator
  20. ~ E n d ~
More Related