1 / 27

Chapter 2.2

Chapter 2.2. Programming Language Definition. Syntax and Semantics Semantics definition Denotational Semantics Elementary actions Syntax definitions Backus-Naur Formalism Syntax diagrams. Summary. Syntax = form Semantics = meaning Example My beer is on the table Syntax : OK

stormy
Download Presentation

Chapter 2.2

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. Chapter 2.2 Programming Language Definition

  2. Syntax and Semantics Semantics definition Denotational Semantics Elementary actions Syntax definitions Backus-Naur Formalism Syntax diagrams Summary

  3. 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

  4. Syntax and Semantics Semantics definition Denotational Semantics Elementary actions Syntax definitions Backus-Naur Formalism Syntax diagrams Summary

  5. Syntax and Semantics Semantics definition Denotational Semantics Elementary actions Syntax definitions Backus-Naur Formalism Syntax diagrams Summary

  6. 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>,<Module> 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 Backus Naur Formalism (BNF)

  7. <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> Backus Naur Formalism (BNF)Examples

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

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

  10. Is 123 a CardinalNumber ? Is it Digit followed by a CardinalNumber ? Is 23 a Cardinal Number ? Is it a digit ? Certainly not <CardinalNumber> ::= <Digit> | <Digit><CardinalNumber>

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

  12. Is 123 a CardinalNumber ? Is it Digit followed by a CardinalNumber ? Is 23 a Cardinal Number ? Is it Digit followed by a CardinalNumber ? Is 3 a Cardinal Number ? Is it a digit ? YES <CardinalNumber> ::= <Digit> | <Digit><CardinalNumber>

  13. Is 123 a CardinalNumber ? Is it Digit followed by a CardinalNumber ? Is 23 a Cardinal Number ? Is it 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>

  14. Is 123 a CardinalNumber ? Is it Digit followed by a CardinalNumber ? Is 23 a Cardinal Number ? Is it 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>

  15. Is 123 a CardinalNumber ? Is it Digit followed by a CardinalNumber ? Is 23 a Cardinal Number ? Is it 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>

  16. 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>

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

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

  19. <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>} Backus Naur Formalism (BNF)Examples

  20. Syntax and Semantics Semantics definition Denotational Semantics Elementary actions Syntax definitions Backus-Naur Formalism Syntax diagrams Summary

  21. 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

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

  23. 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

  24. 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

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

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

  27. Syntax DiagramsExample from the Modula 2 syntax

More Related