BNF. What is BNF? BNF stands for “Backus-Naur Form,” after the people who invented it BNF is a metalanguage--a language used to describe another language.

Slides:



Advertisements
Similar presentations
15-Dec-14 BNF. Metalanguages A metalanguage is a language used to talk about a language (usually a different one) We can use English as its own metalanguage.
Advertisements

Chapter 2 Syntax A language that is simple to parse for the compiler is also simple to parse for the human programmer. N. Wirth.
Chapter Chapter Summary Languages and Grammars Finite-State Machines with Output Finite-State Machines with No Output Language Recognition Turing.
ISBN Chapter 3 Describing Syntax and Semantics.
CS 330 Programming Languages 09 / 13 / 2007 Instructor: Michael Eckmann.
Chapter 3 Describing Syntax and Semantics Sections 1-3.
Chapter 3 Describing Syntax and Semantics Sections 1-3.
Slide 1 Chapter 2-b Syntax, Semantics. Slide 2 Syntax, Semantics - Definition The syntax of a programming language is the form of its expressions, statements.
PHYS 2020 Making Choices; Arrays. Arrays  An array is very much like a matrix.  In the C language, an array is a collection of variables, all of the.
Chapter 3 Describing Syntax and Semantics Sections 1-3.
30-Jun-15 BNF. Metalanguages A metalanguage is a language used to talk about a language (usually a different one) We can use English as its own metalanguage.
Dr. Muhammed Al-Mulhem 1ICS ICS 535 Design and Implementation of Programming Languages Part 1 Fundamentals (Chapter 4) Compilers and Syntax.
Chapter 2 Syntax A language that is simple to parse for the compiler is also simple to parse for the human programmer. N. Wirth.
Describing Syntax and Semantics
1 Syntax and Semantics The Purpose of Syntax Problem of Describing Syntax Formal Methods of Describing Syntax Derivations and Parse Trees Sebesta Chapter.
Chpater 3. Outline The definition of Syntax The Definition of Semantic Most Common Methods of Describing Syntax.
CS 355 – PROGRAMMING LANGUAGES Dr. X. Topics Introduction The General Problem of Describing Syntax Formal Methods of Describing Syntax.
Definition A string is a sequence of symbols. Examples “Hi, Mom.” “YAK” “abbababba” Question In what ways do programmers use strings?
Syntax Specification and BNF © Allan C. Milne Abertay University v
CS Describing Syntax CS 3360 Spring 2012 Sec Adapted from Addison Wesley’s lecture notes (Copyright © 2004 Pearson Addison Wesley)
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 2 Syntax A language that is simple to parse.
3-1 Chapter 3: Describing Syntax and Semantics Introduction Terminology Formal Methods of Describing Syntax Attribute Grammars – Static Semantics Describing.
C H A P T E R TWO Syntax and Semantic.
ISBN Chapter 3 Describing Syntax and Semantics.
TextBook Concepts of Programming Languages, Robert W. Sebesta, (10th edition), Addison-Wesley Publishing Company CSCI18 - Concepts of Programming languages.
Lecture 3: The parts of a C++ program Professor: Dr. Miguel Alonso Jr. Fall 2008 CGS2423/COP1220.
Copyright © by Curt Hill Grammar Types The Chomsky Hierarchy BNF and Derivation Trees.
1 Syntax In Text: Chapter 3. 2 Chapter 3: Syntax and Semantics Outline Syntax: Recognizer vs. generator BNF EBNF.
Programming Paradigms Backus Naur Form and Syntax Diagrams.
Course Title: Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
CPS 506 Comparative Programming Languages Syntax Specification.
Chapter 3 Describing Syntax and Semantics. Chapter 3: Describing Syntax and Semantics - Introduction - The General Problem of Describing Syntax - Formal.
D Goforth COSC Translating High Level Languages Note error in assignment 1: #4 - refer to Example grammar 3.4, p. 126.
Chapter 3 Describing Syntax and Semantics
May 2008CLINT-LIN Regular Expressions1 Introduction to Computational Linguistics Regular Expressions (Tutorial derived from NLTK)
ISBN Chapter 3 Describing Syntax and Semantics.
Syntax and Grammars.
Syntax and Semantics Form and Meaning of Programming Languages Copyright © by Curt Hill.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 2 Syntax A language that is simple to parse.
9/15/2010CS485, Lecture 2, Fall Lecture 2: Introduction to Syntax (Revised based on the Tucker’s slides)
C H A P T E R T W O Syntax and Semantic. 2 Introduction Who must use language definitions? Other language designers Implementors Programmers (the users.
BY: JAKE TENBERG & CHELSEA SHIPP PROJECT REVIEW: JGIBBERISH.
©SoftMoore ConsultingSlide 1 Context-Free Grammars.
1 Context Free Grammars Xiaoyin Wang CS 5363 Spring 2016.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Syntax.
7.2 Programming Languages - An Introduction to Informatics WMN Lab. Hye-Jin Lee.
Organization of Programming Languages Meeting 3 January 15, 2016.
BNF A CFL Metalanguage Some Variations Particular View to SLK Copyright © 2015 – Curt Hill.
Chapter 3 – Describing Syntax CSCE 343. Syntax vs. Semantics Syntax: The form or structure of the expressions, statements, and program units. Semantics:
Syntax(1). 2 Syntax  The syntax of a programming language is a precise description of all its grammatically correct programs.  Levels of syntax Lexical.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Regular Expressions, Backus-Naur Form and Reverse Polish Notation
Chapter 3 – Describing Syntax
Chapter 3 – Describing Syntax
Concepts of Programming Languages
Syntax (1).
Automata and Languages What do these have in common?
Backus Naur form.
Syntax One - Hybrid CMSC 331.
Context-Free Grammars
CSE 311: Foundations of Computing
R.Rajkumar Asst.Professor CSE
Context-Free Grammars 1
BNF 23-Feb-19.
What are the names of the Meta Languages you have used?
Chapter 3 Describing Syntax and Semantics.
BNF 9-Apr-19.
High-Level Programming Language
Understanding Variables
Variables and Constants
Presentation transcript:

BNF

What is BNF? BNF stands for “Backus-Naur Form,” after the people who invented it BNF is a metalanguage--a language used to describe another language BNF is a precise way of describing the syntax of a computer language BNF is really, really easy!

The syntax of BNF Any word or words enclosed in angle brackets,, is a nonterminal -- it stands for some string (it’s like a string variable) The symbol ::= means “is defined as” The symbol | means “or” Anything else is a terminal -- it stands for itself That’s all!

Examples ::= a | e | i | o | u ::= b | c | d | f | g | h | j | k | l | m | n | p | q | r | s | t | v | w | x | y | z ::= | ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 ::= | a | b | c | d | e | f

Recursion Suppose that an “unsigned integer” consists of one or more digits (but there is no limit to the number of digits) ::= | BNF makes heavy use of recursion

More examples Suppose that (in some computer language) a variable consists of letters, digits, and underscores, but must begin with a letter ::= | | | _

Length limitations Suppose that a variable is as before, but can only be six characters long ::= | | | | | ::= | | _ BNF isn’t great for setting limits on lengths!

Recursive structures A while loop can contain any number of other statements, including other while loops ::= while ( ) { } ::= |...other statements... ::= | ::=

What BNF cannot do BNF can only describe local syntax; it cannot refer to another part of the program –Example: BNF cannot say that variables must be declared before they are used BNF cannot do numeric comparisons –Example: BNF cannot say that int values must be between and

Extended BNF After 40 years, BNF is still the preferred way of describing syntax There are two commonly used extensions: –[ ] to indicate the bracketed thing is optional –{ } to indicate zero or more of the enclosed thing Example: ::= [+ | -] { }

Trivial Variations Sometimes different fonts are used to distinguish terminals from nonterminals (instead of marking nonterminals with ) Sometimes different symbols are used, such as = for ::= Sometimes definitions end with a period However you write it, it’s still BNF!

The End