Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 2.2 Programming Language Definition. Summary Syntax and Semantics Semantics definition –Denotational Semantics –Elementary actions Syntax definitions.

Similar presentations


Presentation on theme: "Chapter 2.2 Programming Language Definition. Summary Syntax and Semantics Semantics definition –Denotational Semantics –Elementary actions Syntax definitions."— Presentation transcript:

1 Chapter 2.2 Programming Language Definition

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

3 Syntax and Semantics 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 !!!

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

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

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

7 Backus Naur Formalism (BNF) Examples ::= A|B|C|D|E| |X|Y|Z ::= a|b|c|d|e| |x|y|z ::= | ::= 1|2|3|4|5|6|7|8|9|0 ::= | ::= | + | - ::= | |

8 ::= | Is 123 a CardinalNumber ? Is it a digit ? Certainly not

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

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

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 ?

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

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

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

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

16 ::= | | Correct identifiers –Length, Width, Cost,... –MySalary, NumberOfStudents, Year1, … –X1, Y2, A1, A5, … Incorrect identifiers –My Salary, Number-of-students, … –1stYear,...

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

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

19 Backus Naur Formalism (BNF) Examples ::= A|B|C|D|E| |X|Y|Z ::= a|b|c|d|e| |x|y|z ::= | ::= 1|2|3|4|5|6|7|8|9|0 ::= { } ::= [ +|- ] ::= { | }

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

21 Backus Naur Formalism (BNF) 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. Terminal symbol Non-terminal symbol

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

23 Syntax Diagrams Examples UpperCaseLetter ABCDEVWXYZ Letter LowerCaseLetter abcdevwxyz UpperCaseLetter LowerCaseLetter

24 Syntax Diagrams Examples Digit 01234 56789 CardinalNumber ::= { } ::= 0|1|2|3|4|5|6|7|8|9 Digit

25 Syntax Diagrams Examples IntegerNumber ::= [ + | - ] CardinalNumber + -

26 Syntax Diagrams Examples Identifier ::= { | } Letter Digit Letter

27 Syntax Diagrams Example from the Modula 2 syntax


Download ppt "Chapter 2.2 Programming Language Definition. Summary Syntax and Semantics Semantics definition –Denotational Semantics –Elementary actions Syntax definitions."

Similar presentations


Ads by Google