Presentation is loading. Please wait.

Presentation is loading. Please wait.

Organization of Programming Languages Meeting 3 January 15, 2016.

Similar presentations


Presentation on theme: "Organization of Programming Languages Meeting 3 January 15, 2016."— Presentation transcript:

1 Organization of Programming Languages Meeting 3 January 15, 2016

2 BNF Backus-Naur Form (or Backus Normal Form) – John Backus, developer of Fortran – Peter Naur – Revised Report on the Algorithmic Language Algol 60, Computer Journal, 5(1963), 349-367. Use for – Checking a symbol string for syntactic correctness – Generating a correct symbol string

3 Extended BNF ::=is defined as |or syntactic category, grammatical category [ ]optional item { }repetition of enclosed production phrase 0 or more times ( )clarify hierarchy

4 Context-Free Languages Defined by a context-free grammar Grammar expressed in BNF or some extension – Start symbol – Non-terminal symbols – Terminal symbols – Productions Grammar used – to check a string for inclusion in language L – to generate a string in the language L

5 Grammar of Expressions Using a simplified EBNF S ::= E E ::= T | E + T | E – T T ::= F | T*F | T/F F ::= (E) | I | D

6 Parse Tree A labeled rooted tree Root labeled with start symbol Interior nodes labeled with non-terminal symbols (syntactic categories) Leaves labeled with terminal symbols

7 Expression Parse Trees Your turn: 1.Build a parse tree for a+b*c 2.Build a parse tree for a-b-c Infer rules for associativity and distributivity from the structure of the grammar.

8 Pam Referring to the syntax of the programming language Pam, let’s determine: Its alphabet Details of its grammar – Terminal symbols – Non-terminal symbols – Start symbol – Productions

9 Pam (2) Exercises with Pam: 1.Write the shortest possible syntactically correct program in Pam. 2.Write a program in Pam that reads a positive integer n and writes the value of n! 3.Modify your program to allow the input to include 0.

10 Pam (3) 4.Modify your program to produce a table of the first p factorials. Read p as the input.

11 Homework Assignment Due Wednesday, January 20, at class time. Work individually, post to piazza if you have a question, answer posted questions if you know the correct answer. Sebesta, Exercises 3.7b, 7d, 10, 12 Beck, Syntax Exercises 3, 7, 8


Download ppt "Organization of Programming Languages Meeting 3 January 15, 2016."

Similar presentations


Ads by Google