Programming Language - PowerPoint PPT Presentation

1 / 27
About This Presentation
Title:

Programming Language

Description:

... by a metalinguistic expression. Examples : Letter , Digit , Expression , Module Metalinguistic expression. Formal definition ... Metalinguistic expression ... – PowerPoint PPT presentation

Number of Views:20
Avg rating:3.0/5.0
Slides: 28
Provided by: dtwma
Category:

less

Transcript and Presenter's Notes

Title: Programming Language


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, 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

7
Backus 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

8
ltCardinalNumbergt ltDigitgt
ltDigitgtltCardinalNumbergt
  • Is 123 a CardinalNumber ?
  • Is it a digit ?
  • Certainly not

9
ltCardinalNumbergt ltDigitgt
ltDigitgtltCardinalNumbergt
  • Is 123 a CardinalNumber ?
  • Is it Digit followed by a CardinalNumber ?
  • Is 23 a Cardinal Number ?

10
ltCardinalNumbergt ltDigitgt
ltDigitgtltCardinalNumbergt
  • Is 123 a CardinalNumber ?
  • Is it Digit followed by a CardinalNumber ?
  • Is 23 a Cardinal Number ?
  • Is it a digit ?
  • Certainly not

11
ltCardinalNumbergt 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 ?

12
ltCardinalNumbergt 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

13
ltCardinalNumbergt 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

14
ltCardinalNumbergt 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

15
ltCardinalNumbergt 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

16
ltIdentifiergt ltLettergt ltIdentifiergtltLettergt
ltIdentifiergt ltDigitgt
  • Correct identifiers
  • Length, Width, Cost, ...
  • MySalary, NumberOfStudents, Year1,
  • X1, Y2, A1, A5,
  • Incorrect identifiers
  • My Salary, Number-of-students,
  • 1stYear, ...

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
Backus Naur Formalism (BNF)Examples
  • ltUpperCaseLettergt ABCDE
    XYZ
  • ltLowerCaseLettergt abcde
    xyz
  • ltLettergt ltUpperCaseLettergt
    ltLowerCaseLettergt
  • ltDigitgt 1234567890
  • ltCardinalNumbergt ltDigitgt ltDigitgt
  • ltIntegerNumbergt -ltCardinalNumbergt
  • ltIdentifiergt ltLettergt ltLettergtltDigitgt

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
Non-recursive BNF
Syntax diagram
BNF


Definition
Diagram
Choice
0 or 1 occurrence

0, 1 or many occurrences

23
Syntax DiagramsExamples
  • Letter

24
Syntax DiagramsExamples
Digit
ltDigitgt 0123456789
CardinalNumber
ltCardinalNumbergt ltDigitgt ltDigitgt
Digit
Digit
25
Syntax DiagramsExamples
IntegerNumber
ltIntegerNumbergt - ltCardinalNumbergt
CardinalNumber
26
Syntax DiagramsExamples
Identifier
ltIdentifiergt ltLettergt ltLettergtltDigitgt
27
Syntax DiagramsExample from the Modula 2 syntax
Write a Comment
User Comments (0)
About PowerShow.com