1 / 11

7.2 Programming Languages - An Introduction to Informatics -

7.2 Programming Languages - An Introduction to Informatics -. 2008. 11. 17 WMN Lab. Hye -Jin Lee. outline. Grammar of Languages Syntax and Semantics Backus-Naur Form BNF Definition. Grammar of Languages. languages  a set of sentences sentence  subject predicate

cruz-chen
Download Presentation

7.2 Programming Languages - An Introduction to Informatics -

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. 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 programming language semantics

  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 <integer> ::= <sign><digit sequence> | <digit sequence> <sign> ::= + | − <digit sequence> ::= <digit><digit sequence> | <digit> <digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 • Notational convention • Nonterminal symbols is distinguished by enclosing them by brackets “<” and “>”. • ::= “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 <sign> <digit> <digit> <digit> <digit sequence> <digit sequence> <digit sequence> <integer> 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) <expression> ::= <term> | <addop><term> | <expression><addop><term> <term> ::= <factor> | <term><multop> <factor> <factor> ::= <unsigned integer> | <variable> | (<expression>) <addop> ::= + | - <multop> ::= x | / <unsigned integer> ::= <digit> | <unsigned integer> <digit> <digit> ::= 0|1|2|3|4|5|6|7|8|9 <variable> ::= <letter> | <variable><letter> | <variable><letter> <letter> ::= A|B| … | Z

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

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

More Related