Title: Programming Language
1Chapter 2.2
- Programming Language
- Definition
2Summary
- Syntax and Semantics
- Semantics definition
- Denotational Semantics
- Elementary actions
- Syntax definitions
- Backus-Naur Formalism
- Syntax diagrams
3Syntax 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 !!!
4Summary
- Syntax and Semantics
- Semantics definition
- Denotational Semantics
- Elementary actions
- Syntax definitions
- Backus-Naur Formalism
- Syntax diagrams
5Summary
- Syntax and Semantics
- Semantics definition
- Denotational Semantics
- Elementary actions
- Syntax definitions
- Backus-Naur Formalism
- Syntax diagrams
6Backus Naur Formalism (BNF)
- Terminal Symbols
- Appear literally in program text
- Examples a, 3, END, gt,
- Non-terminal Symbols
- Name given to set of terminal symbols
- Written between lt and gt
- Defined by a metalinguistic expression
- Examples ltLettergt , ltDigitgt,ltExpressiongt,ltModule
gt - Metalinguistic expression
- Formal definition () of a non-terminal symbol
- Contains terminal and non-terminal symbols
- Expresses juxtaposition or choice (the
operator) - Example ltDigitgt 0123456789
7Backus Naur Formalism (BNF)Examples
- ltUpperCaseLettergt ABCDE
XYZ - ltLowerCaseLettergt abcde
xyz - ltLettergt ltUpperCaseLettergt
ltLowerCaseLettergt - ltDigitgt 1234567890
- ltCardinalNumbergt ltDigitgt ltDigitgtltCardinalNum
bergt - ltIntegerNumbergt ltCardinalNumbergt
- ltCardinalNumbergt
- - ltCardinalNumbergt
- ltIdentifiergt ltLettergt
ltIdentifiergtltLettergt ltIdentifiergt ltDigitgt
8ltCardinalNumbergt ltDigitgt
ltDigitgtltCardinalNumbergt
- Is 123 a CardinalNumber ?
- Is it a digit ?
- Certainly not
9ltCardinalNumbergt ltDigitgt
ltDigitgtltCardinalNumbergt
- Is 123 a CardinalNumber ?
- Is it Digit followed by a CardinalNumber ?
- Is 23 a Cardinal Number ?
10ltCardinalNumbergt ltDigitgt
ltDigitgtltCardinalNumbergt
- Is 123 a CardinalNumber ?
- Is it Digit followed by a CardinalNumber ?
- Is 23 a Cardinal Number ?
- Is it a digit ?
- Certainly not
11ltCardinalNumbergt ltDigitgt
ltDigitgtltCardinalNumbergt
- 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 ?
12ltCardinalNumbergt ltDigitgt
ltDigitgtltCardinalNumbergt
- 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
13ltCardinalNumbergt ltDigitgt
ltDigitgtltCardinalNumbergt
- 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
14ltCardinalNumbergt ltDigitgt
ltDigitgtltCardinalNumbergt
- 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
15ltCardinalNumbergt ltDigitgt
ltDigitgtltCardinalNumbergt
- 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
16ltIdentifiergt ltLettergt ltIdentifiergtltLettergt
ltIdentifiergt ltDigitgt
- Correct identifiers
- Length, Width, Cost, ...
- MySalary, NumberOfStudents, Year1,
- X1, Y2, A1, A5,
- Incorrect identifiers
- My Salary, Number-of-students,
- 1stYear, ...
17Syntax Definition
Non-recursive BNF
Syntax diagram
BNF
Definition
Diagram
Choice
0 or 1 occurrence
0, 1 or many occurrences
18Syntax Definition
Non-recursive BNF
Syntax diagram
BNF
Definition
Diagram
Choice
0 or 1 occurrence
0, 1 or many occurrences
19Backus Naur Formalism (BNF)Examples
- ltUpperCaseLettergt ABCDE
XYZ - ltLowerCaseLettergt abcde
xyz - ltLettergt ltUpperCaseLettergt
ltLowerCaseLettergt - ltDigitgt 1234567890
- ltCardinalNumbergt ltDigitgt ltDigitgt
- ltIntegerNumbergt -ltCardinalNumbergt
- ltIdentifiergt ltLettergt ltLettergtltDigitgt
20Summary
- Syntax and Semantics
- Semantics definition
- Denotational Semantics
- Elementary actions
- Syntax definitions
- Backus-Naur Formalism
- Syntax diagrams
21Backus 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
22Syntax Definition
Non-recursive BNF
Syntax diagram
BNF
Definition
Diagram
Choice
0 or 1 occurrence
0, 1 or many occurrences
23Syntax DiagramsExamples
24Syntax DiagramsExamples
Digit
ltDigitgt 0123456789
CardinalNumber
ltCardinalNumbergt ltDigitgt ltDigitgt
Digit
Digit
25Syntax DiagramsExamples
IntegerNumber
ltIntegerNumbergt - ltCardinalNumbergt
CardinalNumber
26Syntax DiagramsExamples
Identifier
ltIdentifiergt ltLettergt ltLettergtltDigitgt
27Syntax DiagramsExample from the Modula 2 syntax