1 / 41

Troisième Partie Chapitre 1 Les supports à la programmation

Troisième Partie Chapitre 1 Les supports à la programmation. Programming languages. Source code. C++. High Level Language. Assembler. Low Level Languages. Object code. Machine Language. HARDWARE. Data Memory. 100: ND. 102: SC. Arithmetic Unit. 1:KFL . 3:DDA. 1. 2. 3.

schuyler
Télécharger la présentation

Troisième Partie Chapitre 1 Les supports à la programmation

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. Troisième Partie Chapitre 1 Les supports à la programmation

  2. Programming languages Source code C++ High Level Language Assembler Low Level Languages Object code Machine Language HARDWARE

  3. Data Memory 100: ND 102: SC Arithmetic Unit 1:KFL 3:DDA 1 2 3 Control Unit 2:KDA 4 5 6 Program Memory (from 11) 7 8 9 10 0 100 10 * 0 # 11 0 102 10 12 1 0 12 40 13 102 10 102 22 14 20 102 2 102 15 0 1 10 16 101 1 101 20 17 101 3 12 41 18 2 321 10 41 19 1 3 10 20 10 47 Machine Language

  4. Assembler Language

  5. 1 2 3 4 5 6 7 8 9 * 0 # High Level language Main() {int sc = 0; const int Key = 321; bool *KFL = 1; int *KDA = KFL+1; bool *DDA = 3; while (true) {for (int nd=1;nd<=3;++nd) {while (*KFL == 0); sc = sc*10+*KDA; } if (sc == Key) *DDA = 1; } } KFL = DDA = KDA =

  6. Source Code (LLL or HLL) Translator Object Code INTERPRETER HARDWARE Transforming Source Code

  7. Translators Translate the entire program at once Program execution very fast Poor run-time error messages Interpreters Translate and execute statement after statement Very slow execution Good run-time error messages Translators vs. Interpreters

  8. LDA +7,U LDB +5,U MUL STD +2,U LDA +6,U LDB +5,U MUL ADD +1,U STD +1,U LDA +6,U LDB +5,U MUL ADD +1,U ... MULB MDEF LDA &1 LDB &2 MUL MEND … MULB +7,U;+5,U STD +2,U MULB +6,U;+5,U ADD +1,U STD +1,U MULB +6,U;+5,U ADD +1,U ... Macros

  9. /* The Program: */ main(void) { # include “one” } /* file one */ printf(“ from 1.\n”); # include “two” /* file two */ printf(“ from 2.\n”); from 1. from 2. Macros in HLL

  10. Macro Expanders Source Main module Macro Library Macro Expander Expanded Source Code Assembler Compiler Object

  11. MACROS Static Expansion Waste of memory Fast Powerful parameter passing, even in assembler FUNCTIONS Dynamic Expansion Save memory space Slow Programmer friendly parameter passing not available in assembler Macros vs. Functions

  12. Source Code (HLL) COMPILER Object Code INTERPRETER HARDWARE Translating HLLs

  13. Syntax = form Semantics = meaning Example My beer is on the table Syntax : OK Semantics : OK My table is on the beer Syntax : OK Semantics : You had too many beers !!! Syntax and Semantics

  14. Terminal Symbols Appear literally in program text Examples : “a”, “3”, “END”, “>”, “:=” Non-terminal Symbols Name given to set of terminal symbols Written between < and > Defined by a metalinguistic expression Examples : <Letter> , <Digit>,<Expression>,<ifstatement> Metalinguistic expression Formal definition (::=) of a non-terminal symbol Contains terminal and non-terminal symbols Expresses juxtaposition or choice (the | operator) Example : <Digit> ::= 0|1|2|3|4|5|6|7|8|9 Syntax Definition :Backus Naur Formalism (BNF)

  15. <UpperCaseLetter> ::= A|B|C|D|E| |X|Y|Z <LowerCaseLetter> ::= a|b|c|d|e| |x|y|z <Letter> ::= <UpperCaseLetter> | <LowerCaseLetter> <Digit> ::= 1|2|3|4|5|6|7|8|9|0 <CardinalNumber> ::= <Digit> | <Digit><CardinalNumber> <IntegerNumber> ::= <CardinalNumber> | + <CardinalNumber> | - <CardinalNumber> <Identifier> ::= <Letter> | <Identifier><Letter> | <Identifier> <Digit> BNF Examples (1)

  16. Is 123 a <CardinalNumber> ? Is it a <Digit> ? Certainly not <CardinalNumber> ::= <Digit> | <Digit><CardinalNumber>

  17. Is 123 a <CardinalNumber> ? Is it a <Digit> followed by a <CardinalNumber> ? Is 23 a <CardinalNumber> ? <CardinalNumber> ::= <Digit> | <Digit><CardinalNumber>

  18. Is 123 a <CardinalNumber> ? Is it a <Digit> followed by a <CardinalNumber> ? Is 23 a <CardinalNumber> ? Is it a <Digit> ? Certainly not <CardinalNumber> ::= <Digit> | <Digit><CardinalNumber>

  19. Is 123 a <CardinalNumber> ? Is it a <Digit> followed by a <CardinalNumber> ? Is 23 a <CardinalNumber> ? Is it a <Digit> followed by a <CardinalNumber> ? Is 3 a <CardinalNumber> ? <CardinalNumber> ::= <Digit> | <Digit><CardinalNumber>

  20. Is 123 a <CardinalNumber> ? Is it a <Digit> followed by a <CardinalNumber> ? Is 23 a <CardinalNumber> ? Is it a <Digit> followed by a <CardinalNumber> ? Is 3 a <CardinalNumber> ? Is it a <Digit> ? YES <CardinalNumber> ::= <Digit> | <Digit><CardinalNumber>

  21. Is 123 a <CardinalNumber> ? Is it a <Digit> followed by a <CardinalNumber> ? Is 23 a <CardinalNumber> ? Is it a <Digit> followed by a <CardinalNumber> ? Is 3 a <CardinalNumber> ? Is it a <Digit> ? YES As a consequence, 3 is a <CardinalNumber> <CardinalNumber> ::= <Digit> | <Digit><CardinalNumber>

  22. Is 123 a <CardinalNumber> ? Is it a <Digit> followed by a <CardinalNumber> ? Is 23 a <CardinalNumber> ? Is it a <Digit> followed by a <CardinalNumber> ? Is 3 a <CardinalNumber> ? Is it a <Digit> ? YES As a consequence, 3 is a <CardinalNumber> As a consequence, 23 is a <CardinalNumber> <CardinalNumber> ::= <Digit> | <Digit><CardinalNumber>

  23. Is 123 a <CardinalNumber> ? Is it a <Digit> followed by a <CardinalNumber> ? Is 23 a <CardinalNumber> ? Is it a <Digit> followed by a <CardinalNumber> ? Is 3 a <CardinalNumber> ? Is it a <Digit> ? YES As a consequence, 3 is a <CardinalNumber> As a consequence, 23 is a <CardinalNumber> As a consequence, 123 is a <CardinalNumber> <CardinalNumber> ::= <Digit> | <Digit><CardinalNumber>

  24. Correct identifiers Length, Width, Cost, ... MySalary, NumberOfStudents, Year1, … X1, Y2, A1, A5, … Incorrect identifiers My Salary, Number-of-students, … 1stYear, ... <Identifier> ::= <Letter> | <Identifier><Letter> | <Identifier> <Digit>

  25. Correct identifiers Length, Width, Cost, ... MySalary, NumberOfStudents, Year1, … X1, Y2, A1, A5, … Incorrect identifiers My Salary, Number-of-students, … 1stYear, ... <Identifier> ::= <Letter> | <Identifier><Letter> | <Identifier> <Digit>

  26. Syntax Definition Non-recursive BNF Syntax diagram BNF ::= ::= Definition Diagram Choice 0 or 1 occurrence [] 0, 1 or many occurrences {}

  27. Syntax Definition Non-recursive BNF Syntax diagram BNF ::= ::= Definition Diagram Choice 0 or 1 occurrence [ ] 0, 1 or many occurrences {}

  28. <UpperCaseLetter> ::= A|B|C|D|E| |X|Y|Z <LowerCaseLetter> ::= a|b|c|d|e| |x|y|z <Letter> ::= <UpperCaseLetter> | <LowerCaseLetter> <Digit> ::= 1|2|3|4|5|6|7|8|9|0 <CardinalNumber> ::= <Digit> {<Digit>} <IntegerNumber> ::= [+|-]<CardinalNumber> <Identifier> ::= <Letter> {<Letter>|<Digit>} BNF Examples (2)

  29. Terminal Symbols Non-terminal Symbols Metalinguistic expression Railroad diagrams with semaphores requiring specific symbols to grant passage. The defined non-terminal symbol leaves all its symbols, in the order of occurrence, at appropriate semaphores and reaches the exit with none left. Backus Naur Formalism (BNF) Terminal symbol Non-terminal symbol

  30. Syntax Definition Non-recursive BNF Syntax diagram BNF ::= ::= Definition Diagram Choice 0 or 1 occurrence [] 0, 1 or many occurrences {}

  31. UpperCaseLetter • LowerCaseLetter y A B C D E V W X Y a b c d e v w x Z z UpperCaseLetter LowerCaseLetter Syntax DiagramsExamples • Letter

  32. 6 8 5 4 3 7 1 0 9 2 Digit Syntax DiagramsExamples Digit <Digit> ::= 0|1|2|3|4|5|6|7|8|9 CardinalNumber <CardinalNumber> ::= <Digit> {<Digit>} Digit Digit

  33. + - Syntax DiagramsExamples IntegerNumber <IntegerNumber> ::= [ + | - ] <CardinalNumber> CardinalNumber

  34. Letter Digit Letter Syntax DiagramsExamples Identifier <Identifier> ::= <Letter> {<Letter>|<Digit>}

  35. Lexical analyzer Syntax analyzer Code generator Code optimizer COMPILER = Object Code HARDWARE The COMPILER Source Code (HLL)

  36. Recognizes lexical tokens such as: Identifiers Numbers : -200, 6.3E23, … Reserved words : for; if; Multi-character symbols : /*; */; == ; != ; ... Prepares the symbol table with all identifiers The Lexical Analyzer

  37. Recognizes non-terminal symbols such as: a program : a variable declaration : a function declaration : an expression Can be generated automatically by a parser generator, starting from the BNF syntax definitions Represents a program by a syntactical tree and a symbol table. The Syntax Analyzer(= syntax parser)

  38. Both the lexical and syntactical analyzer should check the source code against syntax errors. When an error has been found, the syntax analyzer should generate an error message and stop or generate an error message try to correct by guessing the programmers intentions resume the syntax analysis A compiler should never generate any code as long as syntax errors are present in the source code, even if the syntax analyzer has corrected them in order to continue the analysis. Error detection and correction

  39. Multi-pass compiler Source Lexical analysis Symbol table Int.1 Syntax analysis Int.1 Code generation Int.1 Object Optimization

  40. Syntax analysis Lexical analysis Code generation Single - pass compiler Source Symbol table Object

  41. Interpreters Syntax analysis Source Lexical analysis Symbol table Simulated code execution

More Related