Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

BNF and EBNF: The Evolution of Formal Grammar Notations, Lecture notes of Programming Languages

BNF (Backus-Naur Form) and EBNF (Extended Backus-Naur Form) are formal grammar notations used to specify context-free grammars. the origins, differences, and extensions of these notations. BNF was first introduced by John Backus for Algol 60, while EBNF was later proposed by Niklaus Wirth to add syntactic sugar for more convenient grammar definitions. Both notations are widely used in defining programming languages.

Typology: Lecture notes

2021/2022

Uploaded on 09/12/2022

linden
linden 🇬🇧

4.4

(8)

217 documents

1 / 22

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
BNF and EBNF
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16

Partial preview of the text

Download BNF and EBNF: The Evolution of Formal Grammar Notations and more Lecture notes Programming Languages in PDF only on Docsity!

BNF and EBNF

What is BNF?

  • It stands for Backus-Naur Form• It is a formal, mathematical way to specify

context-free grammars

  • It is precise and unambiguous• Before BNF, people specified

programming languages ambiguously, i.e.,with English

Who was John Backus?

-^

Backus invented FORTRAN (“FORMulaTRANslator”), the first high-level language ever

, circa 1954

-^

Major influence on the invention offunctional programming in 1970’s

-^

Won the 1977 Turing Award for BNF andFORTRAN

Who was Peter Naur?

  • Danish astronomer turned computer

scientist

  • Born in 1928; picture on left is from 1968

What does BNF look like?

  • Like this: ::= | ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 • “::=” means “is defined as” (some variants use

“:=” instead)

  • “|” means “or”• Angle brackets mean a nonterminal• Symbols without angle brackets are terminals

More BNF Examples

  • ::= while ( )

  • ::= =

  • ::= |

  • ::= |

Origin of EBNF

  • Stands for “Extended Backus-Naur Form”• After BNF appeared with Algol 60, lots of

people added their own extensions

  • Niklaus Wirth wanted to see one form, so

he published “What Can We Do About theUnnecessary Diversity of Notation forSyntactic Definitions” in Communicationsof the ACM in 1977

  • He suggested the use of “[ .. ]” for optional

symbols (0 or 1 occurrences), “{ .. }” for 0or more occurrences.

  • Did not mention “EBNF” or Kleene cross

Who was Niklaus Wirth?

-^

Born in Switzerland, 1934

-^

Desgined Pascal (1970),Modula, Modula-2 (1980),and Oberon (1988)

-^

Won the Turing Award in 1984

-^

Won the IEEE ComputerPioneer Award in 1987

What are the Extensions?

  • They vary, but often are derived from

regular expression syntax

” (The Kleene Star): means 0 or more occurrences

” (The Kleene Cross): means 1 or more occurrences

”: means 0 or 1 occurrences (sometimes “[ … ]” used instead)

  • Use of parentheses for grouping

BNF vs EBNF

  • Grammar for decimal numbers in plain

BNF:

::= '-' | ::=

| '.'

::=

|

::= '0' | '1' | '2' | '3' |

'4' | '5' | '6' | '7' | '8' | '9'

Simple Conversions

  • If you have a rule such as: ::= ::=

|

-^

You can replace it with: ::= +

More Simple Conversions

  • If you have a rule such as: ::= | empty •^

You can replace it with: ::= *

EBNF for Lisp

s_expression ::= atomic_symbol

| "(" s_expression "." s_expression ")"| list

list ::= "(" s_expression ")"atomic_symbol ::= letter atom_partatom_part ::= empty*

| letter atom_part| number atom_part

letter ::= "a" | "b" | " ..." | "z"number ::= "1" | "2" | " ..." | "9"

Summary-BNF

-^

BNF uses following notations:

(i) Non-terminals enclosed in

<

and

>

.

(ii) Rules written as

X

::=

Y

(1)

X

is LHS of rule and can only be a NT.

(2)

Y

is RHS of rule:

Y

can be

(a) a terminal, nonterminal, or concatenation of terminal

and nonterminals, or (b) a set of strings separated by alternation symbol

|.

Example: < S >

::=

a < S > |a

-^ Notation

ε

: : Used to represent an empty string (a string of

length 0).