1 / 9

September 13 th

September 13 th. Grammars. Grammars. They are a way of describing the syntax of programming languages We will be using BNF grammar (as in Mini-Language Core) Syntax diagrams (in Pascal) BNF grammar Was invented in 1958 as a way of describing Algol 58 by John Backus. BNF grammars .

willey
Download Presentation

September 13 th

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. September 13th Grammars

  2. Grammars • They are a way of describing the syntax of programming languages • We will be using • BNF grammar (as in Mini-Language Core) • Syntax diagrams (in Pascal) • BNF grammar • Was invented in 1958 as a way of describing Algol 58 by John Backus

  3. BNF grammars • BNF grammar is context-free grammar • Noam Chomsky – classified grammars • Context-free grammar • Regular grammar • Context-sensitiver grammar • …

  4. Characteristics of grammar • A grammar consists of • A four-tuple • A set of terminals • A set of non-terminals • A set of rules (or productions) • A start (or goal) symbol

  5. Uses of grammars • It can be used to generate legal sentences in a programming language • It can be used to determine whether a given sentence in a programming language is correct • parsing

  6. What did we learn from Mini-Language Core’s BNF • It described the language well enough for most of us to write a program in an unfamiliar language • We could determine whether a given statement we wrote in Mini-Language Core was correct • It really only told us about syntax, not about semantics • There were a number of things that we could not determine from the grammar

  7. Terminology • Lexemes – lowest level syntactic units • Token – is a category of lexemes • index = 2 * count + 17; • Index, count are identifiers • =, *, + are operators • 2, 17 are integer literals • ; is a separator or terminator • Metalanguage – is a language used to describe other languages • Aside: identifiers can reference variables, constants, methods, programs, etc.

  8. Potential Problems • A grammar may be ambiguous • Two different parse trees may be generated for the same expression.

  9. Sections 3.4 and later • Less important in this class – read to be able to answer homework questions but don’t agonize over the material in axiomatic and denotational semantics.

More Related