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.

Slides:



Advertisements
Similar presentations
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.
Advertisements

ISBN Chapter 3 Describing Syntax and Semantics.
Honors Compilers An Introduction to Grammars Feb 12th 2002.
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 Program translation1 Chapt. 3 Language Translation Syntax and Semantics Translation phases Formal translation models.
Chapter 3 Describing Syntax and Semantics Sections 1-3.
Programming Languages An Introduction to Grammars Oct 18th 2002.
COMP205 Comparative Programming Languages Part 1: Introduction to programming languages Lecture 2: Structure of programs and programming languages as communication.
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.
Specifying Languages CS 480/680 – Comparative Languages.
(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.
ITEC 380 Organization of programming languages Lecture 2 – Grammar / Language capabilities.
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.
Syntax: 10/18/2015IT 3271 Semantics: Describe the structures of programs Describe the meaning of programs Programming Languages (formal languages) -- How.
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.
Grammars CPSC 5135.
3-1 Chapter 3: Describing Syntax and Semantics Introduction Terminology Formal Methods of Describing Syntax Attribute Grammars – Static Semantics Describing.
ProgrammingLanguages Programming Languages Language Syntax This lecture introduces the the lexical structure of programming languages; the context-free.
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.
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.
CPS 506 Comparative Programming Languages Syntax Specification.
D Goforth COSC Translating High Level Languages.
Chapter 3 Describing Syntax and Semantics
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 © Curt Hill Other Trees Applications of the Tree Structure.
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.
Parser: CFG, BNF Backus-Naur Form is notational variant of Context Free Grammar. Invented to specify syntax of ALGOL in late 1950’s Uses ::= to indicate.
©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:
Describing Syntax and Semantics Chapter 3: Describing Syntax and Semantics Lectures # 6.
Chapter 3: Describing Syntax and Semantics
Chapter 3 – Describing Syntax
Chapter 3 – Describing Syntax
Syntax (1).
Automata and Languages What do these have in common?
Syntax versus Semantics
Context-Free Grammars
ENERGY 211 / CME 211 Lecture 15 October 22, 2008.
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
BNF 23-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
Programming Languages 2nd edition Tucker and Noonan
Presentation transcript:

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 (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 a notation for context-free grammars 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. 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. ::= + | - This is all there is to “plain” BNF; but we will discuss extended BNF (EBNF) later in this lecture

BNF uses recursion ::= | or ::= | Recursion is all that is needed (at least, in a formal sense) "Extended BNF" allows repetition as well as recursion Repetition is usually better when using BNF to construct a compiler

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

BNF Examples II ::= | ::= | + | -

BNF Examples III ::= | | ::= { } ::= |

BNF Examples IV ::= | | | | | | | |...

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

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 easy way to describe ranges, such as 1 to 31 No way at all 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