1 / 13

C H A P T E R T W O

C H A P T E R T W O. Syntax. Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan. Chomsky’s formal model:. Naom Chomsky developed a formal model of language types in the late 1950s. Grammars were classified in a hierarchy of ascending complexity.

tyrell
Télécharger la présentation

C H A P T E R T W O

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. C H A P T E R T W O Syntax Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan

  2. Chomsky’s formal model: • Naom Chomsky developed a formal model of language types in the late 1950s. • Grammars were classified in a hierarchy of ascending complexity. • The original four classifications were: • Regular • Context-free • Context-sensitive • Unrestricted

  3. Backus-Naur Form (BNF): • Created by John Backus and Peter Naur in 1960 to assist them in creating the programming language Algol. • Based on Chomsky’s work. • BNF works to describe context-free grammars. • More powerful than regular expressions.

  4. Backus-Naur Form (BNF): BNF rules are used to rewrite nonterminal symbols into terminal symbols. Example rules: Integer -> Digit | Integer Digit Digit -> 0 | 1| 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9

  5. Parse Tree for 352 As an Integer Figure 2.1

  6. BNF and Lexical Analysis: • A programming language’s lexicon is the set of all grammatical categories that define strings (tokens) from which a program may be written. • Typical categories include: • Operators (+, -, *, /, etc.) • Separators (;, ., {, }, etc.) • Keywords ( for, else, if, int, etc.) • Literals (numbers and string constants) • Identifiers (variable and function names)

  7. A Program Fragment Viewed As a Stream of Tokens Figure 2.2

  8. A Simple Lexical Syntax for a Small Language, Jay Figure 2.3

  9. Major Stages in the Compiling Process Figure 2.4

  10. Skeleton Lexical Analysis Method That Returns Tokens Figure 2.5

  11. Regular Expressions and Lexical Analysis: • An alternative to BNF for specifying a language at the lexical level. • Widely used as a tool for lexical scanners (routines that create token strings). • Not powerful enough for more complex syntactic structures. • Regular expressions can describe regular languages, BNF can describe context-free languages.

  12. Conventions for Writing Regular Expressions Figure 2.6

  13. Next time… Syntactic Analysis

More Related