BNF 23-Feb-19.

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.
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.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 2 Syntax A language that is simple to parse.
Chapter 2 Syntax. Syntax The syntax of a programming language specifies the structure of the language The lexical structure specifies how words can be.
ISBN Chapter 3 Describing Syntax and Semantics.
ALGOL 60 Design by committee of computer scientists: Naur, Backus, Bauer, McCarthy, van Wijngaarden, Landin, etc. Design by committee of computer scientists:
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.
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.
(2.1) Grammars  Definitions  Grammars  Backus-Naur Form  Derivation – terminology – trees  Grammars and ambiguity  Simple example  Grammar hierarchies.
Programming Languages
Chapter 2 Syntax A language that is simple to parse for the compiler is also simple to parse for the human programmer. N. Wirth.
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
Syntax and Backus Naur Form
1 Chapter 3 Describing Syntax and Semantics. 3.1 Introduction Providing a concise yet understandable description of a programming language is difficult.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 2 Syntax A language that is simple to parse.
Grammars CPSC 5135.
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.
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.
CPS 506 Comparative Programming Languages Syntax Specification.
ISBN Chapter 3 Describing Syntax and Semantics.
Syntax and Grammars.
The Interpreter Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
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.
©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.
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.
Regular Expressions, Backus-Naur Form and Reverse Polish Notation
Chapter 3: Describing Syntax and Semantics
Chapter 3 – Describing Syntax
Chapter 3 – Describing Syntax
Syntax (1).
What does it mean? Notes from Robert Sebesta Programming Languages
Automata and Languages What do these have in common?
Syntax versus Semantics
Compiler Construction (CS-636)
Backus Naur form.
Programming Languages 2nd edition Tucker and Noonan
Context-Free Grammars
Programming Languages 2nd edition Tucker and Noonan
R.Rajkumar Asst.Professor CSE
Context–free Grammar CFG is also called BNF (Backus-Naur Form) grammar
Context-Free Grammars 1
CSCE 330 Programming Language Structures Ch.2: Syntax and Semantics
Recognizers 16-Jan-19.
Recognizers 22-Feb-19.
What are the names of the Meta Languages you have used?
Syntax vs Semantics Backus-Naur Form Extended BNF Derivations
Chapter 3 Describing Syntax and Semantics.
BNF 9-Apr-19.
High-Level Programming Language
Chapter 10: Compilers and Language Translation
Programming Languages 2nd edition Tucker and Noonan
Presentation transcript:

BNF 23-Feb-19

Metalanguages A metalanguage is a language used to talk about a language (usually a different one) We can use English as its own metalanguage (e.g. describing English grammar in English) It is essential to distinguish between the metalanguage terms and the object language terms

BNF BNF stands for either Backus-Naur Form or Backus Normal Form BNF is a metalanguage used to describe the grammar of a programming language BNF is formal and precise BNF is essential in compiler construction There are many dialects of BNF in use, but… …the differences are almost always minor

BNF < > indicate a nonterminal that needs to be further expanded, e.g. <variable> Symbols not enclosed in < > are terminals; they represent themselves, e.g. if, while, ( The symbol ::= means is defined as The symbol | means or; it separates alternatives, e.g. <addop> ::= + | -

BNF uses recursion <integer> ::= <digit> | <integer> <digit> or <integer> ::= <digit> | <digit> <integer> Many people find recursion confusing "Extended BNF" allows repetition as well as recursion Repetition is often more efficient when using BNF to construct a compiler

BNF Examples I <digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 <if statement> ::= if ( <condition> ) <statement> | if ( <condition> ) <statement> else <statement>

BNF Examples II <unsigned integer> ::= <digit> | <unsigned integer> <digit> <integer> ::= <unsigned integer> | + <unsigned integer> | - <unsigned integer>

BNF Examples III <identifier> ::= <letter> | <identifier> <letter> | <identifier> <digit> <block> ::= { <statement list> } <statement list> ::= <statement> | <statement list> <statement>

BNF Examples IV <statement> ::= <block> | <assignment statement> | <break statement> | <continue statement> | <do statement> | <for loop> | <goto statement> | <if statement> | . . .

Extended BNF The following are pretty standard: [ ] enclose an optional part of the rule Example: <if statement> ::= if ( <condition> ) <statement> [ else <statement> ] { } mean the enclosed can be repeated any number of times (including zero) Example: <parameter list> ::= ( ) | ( { <parameter> , } <parameter> )

Variations The preceding notation is the original and most common notation BNF was designed before we had boldface, color, more than one font, etc. A typical modern variation might: Use boldface to indicate multi-character terminals Quote single-character terminals (because boldface isn’t so obvious in this case) Example: if_statement ::= if "(" condition ")" statement [ else statement ]

Limitations of BNF No easy way to impose length limitations, such as maximum length of variable names No way to impose distributed requirements, such as, a variable must be declared before it is used Describes only syntax, not semantics Nothing clearly better has been devised

The End