Presentation is loading. Please wait.

Presentation is loading. Please wait.

7.2 Programming Languages - An Introduction to Informatics - 2008. 11. 17 WMN Lab. Hye-Jin Lee.

Similar presentations


Presentation on theme: "7.2 Programming Languages - An Introduction to Informatics - 2008. 11. 17 WMN Lab. Hye-Jin Lee."— Presentation transcript:

1 7.2 Programming Languages - An Introduction to Informatics - 2008. 11. 17 WMN Lab. Hye-Jin Lee

2 outline Grammar of Languages Syntax and Semantics Backus-Naur Form BNF Definition

3 Grammar of Languages languages  a set of sentences sentence  subject predicate  subject predicate conjunctive sentence subject  noun | pronoun predicate  verb | verb prepositional-phrase noun  MARY | SCHOOL | TOWN pronoun  HE verb  DRIVES | WALKS | GOES prepositional-phrase  preposition noun preposition  TO | FROM e.g., {HE, MARY,DRIVES, WALKS, GOES, TO, FROM, TOWN, SCHOOL}

4 Grammar of Languages HE DRIVES FROMS SHOOL pronoun verb preposition noun prepositional-phrase subject predicate sentence Figure 7-7 (a) Simple Sentence

5 Syntax and Semantics The Syntax of a language is given by a set of composition rules called a grammar that defines the elements and structure of any well-formed sentence. The Semantics depends on both the particular words in the sentence and the structure of the sentence. syntax semantics programming language

6 Backus-Naur Form John Backus and Peter Naur developed a formal notation for specifying programming language syntax (in 1959/1960) –Defines the language sentence generated production rule. –Production rule Left side – defined target Right side – representation for the target definition.

7 BNF Definition For example ::= | ::= + | − ::= | ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 Notational convention –Nonterminal symbols is distinguished by enclosing them by brackets “ ”. –::=  “is defined as”, “generates”, “produces”, “may be rewritten as”, and “consists of”. –Elements of the vocabulary, sometimes called terminal symbols, appear only in the right parts of rules. –|  “or”

8 BNF Definition − 3 6 9 Figure 7-8 parse of an Integer

9 BNF Definition A grammar should be designed not only to produce the correct sentences of the language but also to have syntactic categories that correspond to the semantics of the language. For example – A + B X C + (E − F) ::= | | ::= | ::= | | ( ) ::= + | - ::= x | / ::= | ::= 0|1|2|3|4|5|6|7|8|9 ::= | | ::= A|B| … | Z

10 BNF Definition ( ( ) ( ) ) ( ) Fiqure 7-9 : Parse of a Parenthesis String A + B x C + ( E - F ) l ao l mo l ao l ao l v v v v v f f f f f t t e t e e e f t e

11 Syntax Charts Visual expression of the grammar –Terminals –Non-Terminals –Optional –Zero-Or-More Repititions + number


Download ppt "7.2 Programming Languages - An Introduction to Informatics - 2008. 11. 17 WMN Lab. Hye-Jin Lee."

Similar presentations


Ads by Google