45
What Does this Notation Mean Anyway? BNF-Style Notation as it is Used in Practice David Feller Supervisors: Fairouz Kamareddine and Joe Wells Heriot Watt University July 19, 2017 David Feller (Heriot Watt University) What Does this Notation Mean Anyway? July 19, 2017 1 / 30

What Does this Notation Mean Anyway?daf3/presentation.pdf · 2017-07-19 · BNF-Style Notation as it is Used in Practice David Feller Supervisors: Fairouz Kamareddine and Joe Wells

  • Upload
    others

  • View
    8

  • Download
    0

Embed Size (px)

Citation preview

Page 1: What Does this Notation Mean Anyway?daf3/presentation.pdf · 2017-07-19 · BNF-Style Notation as it is Used in Practice David Feller Supervisors: Fairouz Kamareddine and Joe Wells

What Does this Notation Mean Anyway?BNF-Style Notation as it is Used in Practice

David FellerSupervisors: Fairouz Kamareddine and Joe Wells

Heriot Watt University

July 19, 2017

David Feller (Heriot Watt University) What Does this Notation Mean Anyway? July 19, 2017 1 / 30

Page 2: What Does this Notation Mean Anyway?daf3/presentation.pdf · 2017-07-19 · BNF-Style Notation as it is Used in Practice David Feller Supervisors: Fairouz Kamareddine and Joe Wells

Motivation

No universal standard for how BNF-style notation is used in Practice.

Most existing standards relate only to languages as sets of ASCIIstrings.

BNF-style notation often ambiguous so must be augmented forchoosing between parse trees.

Not obvious that all uses are context free.

Syntax continues to be used in new ways.

Without a clear standard we cannot specify how BNF-Style syntax mustbe written to guarantee it meets an author’s requirements. We cannotknow the circumstances under which we might derive contradictions in thesystems it specifies unless another model is provided in a system that isclearly and unambiguously defined.

David Feller (Heriot Watt University) What Does this Notation Mean Anyway? July 19, 2017 2 / 30

Page 3: What Does this Notation Mean Anyway?daf3/presentation.pdf · 2017-07-19 · BNF-Style Notation as it is Used in Practice David Feller Supervisors: Fairouz Kamareddine and Joe Wells

Examples of BNF

Backus〈digit〉 :≡ O or 1 or 2 or 3 or 4 or 5 or 6 or

7 or 8 or 9〈integer〉 :≡ 〈digit〉 or 〈integer〉〈digit〉

Naur〈delimiter〉 ::= 〈operator〉 | 〈separator〉 |

〈bracket〉 | 〈declarator〉 | 〈specificator〉〈operator〉 ::= 〈arithmetic operator〉 |

〈relational operator〉 | 〈logical operator〉 |〈sequential operator〉

〈arithmetic operator〉 ::= +| − | × | / | ÷ | ↑〈relational operator〉 ::=< | ≤ | = | ≥ | > | 6=〈logical operator〉 ::= ≡ | ⊂ | ∨ | ∧ |¬〈sequential operator〉 ::= go to | if | then |

else | for | do〈separator〉 ::=, |.|I0| : |; | := | t | step | until |

while | comment〈bracket〉 ::= (|)|[|]|‘|’| begin | end

David Feller (Heriot Watt University) What Does this Notation Mean Anyway? July 19, 2017 3 / 30

Page 4: What Does this Notation Mean Anyway?daf3/presentation.pdf · 2017-07-19 · BNF-Style Notation as it is Used in Practice David Feller Supervisors: Fairouz Kamareddine and Joe Wells

Examples of BNF

Backus〈digit〉 :≡ O or 1 or 2 or 3 or 4 or 5 or 6 or

7 or 8 or 9〈integer〉 :≡ 〈digit〉 or 〈integer〉〈digit〉

Naur〈delimiter〉 ::= 〈operator〉 | 〈separator〉 |

〈bracket〉 | 〈declarator〉 | 〈specificator〉〈operator〉 ::= 〈arithmetic operator〉 |〈relational operator〉 | 〈logical operator〉 |〈sequential operator〉

〈arithmetic operator〉 ::= +| − | × | / | ÷ | ↑〈relational operator〉 ::=< | ≤ | = | ≥ | > | 6=〈logical operator〉 ::= ≡ | ⊂ | ∨ | ∧ |¬〈sequential operator〉 ::= go to | if | then |

else | for | do〈separator〉 ::=, |.|I0| : |; | := | t | step | until |

while | comment〈bracket〉 ::= (|)|[|]|‘|’| begin | end

20

17

-07

-19

What Does this Notation Mean Anyway?

Examples of BNF

Make clear Backus came first

Page 5: What Does this Notation Mean Anyway?daf3/presentation.pdf · 2017-07-19 · BNF-Style Notation as it is Used in Practice David Feller Supervisors: Fairouz Kamareddine and Joe Wells

EBNF/ABNF Variants

letter = “A” | “B” | “C” | “D” | “E” | “F”| “G” | “H” | “I” | “J” | “K” | “L” | “M”| “N” | “O” | “P” | “Q” | “R” | “S” | “T”| “U” | “V” | “W” | “X” | “Y” | “Z”;

vowel = “A” | “E” | “I” | “O” | “U”;consonant = letter − vowel;

v → l |rl → id([v(,v)∗])?

r → nat| “string” |array[v(,v)∗](v)

c → c&&c|c||c|v==v |v ! =v

::= may be written as =, :≡, ->, is, →, 7→, ←

| may be written as or, or, newline

Either terminals or non-terminals may be picked out, usually non-terminalsare surrounded by triangle brackets whereas terminals may be picked outwith quote marks or underlines.

My work is not concerned with these differences.

David Feller (Heriot Watt University) What Does this Notation Mean Anyway? July 19, 2017 4 / 30

Page 6: What Does this Notation Mean Anyway?daf3/presentation.pdf · 2017-07-19 · BNF-Style Notation as it is Used in Practice David Feller Supervisors: Fairouz Kamareddine and Joe Wells

EBNF/ABNF Variants

letter = “A” | “B” | “C” | “D” | “E” | “F”| “G” | “H” | “I” | “J” | “K” | “L” | “M”| “N” | “O” | “P” | “Q” | “R” | “S” | “T”| “U” | “V” | “W” | “X” | “Y” | “Z”;

vowel = “A” | “E” | “I” | “O” | “U”;consonant = letter − vowel;

v → l |rl → id([v(,v)∗])?

r → nat| “string” |array[v(,v)∗](v)

c → c&&c|c||c|v==v |v ! =v

::= may be written as =, :≡, ->, is, →, 7→, ←

| may be written as or, or, newline

Either terminals or non-terminals may be picked out, usually non-terminalsare surrounded by triangle brackets whereas terminals may be picked outwith quote marks or underlines.

My work is not concerned with these differences.20

17

-07

-19

What Does this Notation Mean Anyway?

EBNF/ABNF Variants

Right side Backus then Naur. Point out trivial differences. Put onoverhead all differences. 2 slides. List additional variants.

Left side EBNF/ABNF variants. Non terminals quoted + underlined.Some additional operators (choice, repetition, exclusion), but still reducestrivially to BNF

Page 7: What Does this Notation Mean Anyway?daf3/presentation.pdf · 2017-07-19 · BNF-Style Notation as it is Used in Practice David Feller Supervisors: Fairouz Kamareddine and Joe Wells

How Does BNF Work Normally?

〈DI〉 ::= - 〈PD〉 | 〈PD〉〈PD〉 := 〈DL〉 | 〈DL〉 . 〈DL〉〈DL〉 := 〈D〉 | 〈D〉 〈DL〉〈D〉 := 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9

Decimal integer 〈DI〉Positive decimal 〈PD〉Digit list 〈DL〉Digit 〈D〉

〈DI〉〈PD〉〈DL〉 . 〈DL〉〈D〉 . 〈DL〉3 . 〈DL〉3 . 〈D〉 〈DL〉3 . 1 〈DL〉3 . 1 〈D〉3 . 1 4

David Feller (Heriot Watt University) What Does this Notation Mean Anyway? July 19, 2017 5 / 30

Page 8: What Does this Notation Mean Anyway?daf3/presentation.pdf · 2017-07-19 · BNF-Style Notation as it is Used in Practice David Feller Supervisors: Fairouz Kamareddine and Joe Wells

How Does BNF Work Normally?

〈DI〉 ::= - 〈PD〉 | 〈PD〉〈PD〉 := 〈DL〉 | 〈DL〉 . 〈DL〉〈DL〉 := 〈D〉 | 〈D〉 〈DL〉〈D〉 := 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9

Decimal integer 〈DI〉Positive decimal 〈PD〉Digit list 〈DL〉Digit 〈D〉

〈DI〉〈PD〉〈DL〉 . 〈DL〉〈D〉 . 〈DL〉3 . 〈DL〉3 . 〈D〉 〈DL〉3 . 1 〈DL〉3 . 1 〈D〉3 . 1 42

01

7-0

7-1

9What Does this Notation Mean Anyway?

How Does BNF Work Normally?

Describe replacement process

An important thing to note when considering whether a piece of BNF-like syntax canbe readily converted into BNF is that BNF is a language for building sets of stringsand the only notion of equality it deals with easily is string equality. It is possible toderive a notion of tree equality from the parse trees generated by an EBNF grammar,but there is no guarantee that parse trees will be unambiguous. Unless an authorwrites their grammar with a parser in mind, inferring a sensible parse tree from a setof productions is non-trivial.

BNF does not deal with ambiguous strings w-out parsing conventions

Page 9: What Does this Notation Mean Anyway?daf3/presentation.pdf · 2017-07-19 · BNF-Style Notation as it is Used in Practice David Feller Supervisors: Fairouz Kamareddine and Joe Wells

Why did People Start Using BNF-Style NotationDifferently?

BNF only deals with strings. The only sets it deals with are sets ofstrings. The only notion of tree equality it supports comes from parsetrees, which may be ambiguous. The syntactic entities it recognisesare strings. Many authors want to use the notation to talk about treesand sets directly and use more complex expressions while doing so.

Many authors who use BNF-Style notation work with mathematicalobjects and want to be able to use mathematical conventions whendefining their grammars.

Sometimes authors invent notation which gets picked up more widely.

Authors often like to miss out pieces of syntax that are fairly standardin order to make their grammars easier for humans to read.

There a fairly consistent way in which BNF-style notation has come to beused in the literature which is particularly distinct from BNF. We call thisMath-BNF.

David Feller (Heriot Watt University) What Does this Notation Mean Anyway? July 19, 2017 6 / 30

Page 10: What Does this Notation Mean Anyway?daf3/presentation.pdf · 2017-07-19 · BNF-Style Notation as it is Used in Practice David Feller Supervisors: Fairouz Kamareddine and Joe Wells

Math BNF

Defines grammar-like structures. Written similarly to BNF.

◦ ::= �|...|�

Not about producing sets of strings.

Not precisely defined by any implementation or international standard.

Bypasses questions of parsing.

Incorporates portions of the general metalanguage of mathematics.

A simple example of Math-BNF:

e ::= x | λx .e | e e

David Feller (Heriot Watt University) What Does this Notation Mean Anyway? July 19, 2017 7 / 30

Page 11: What Does this Notation Mean Anyway?daf3/presentation.pdf · 2017-07-19 · BNF-Style Notation as it is Used in Practice David Feller Supervisors: Fairouz Kamareddine and Joe Wells

Roughly how is Math-BNF Evaluated?

Substitution of metavariables for instances of the things theyrepresent (shared with BNF).

Expansion and decomposition of lists into each of their instances(where lists are defined using ellipses or a similar method).

Evaluation of common mathematical notation (most commonly settheory notation).

Grouping together of metavariables and syntax operators (e.g. byusing brackets).

Production of structures representing equivalence of statements (e.gα-equivalence).

Each rule produces a collection of all the things which can be producedthrough its legal application within the smallest possible context and thevariable ranges over all such collections. Often the things produced bythese rules bear a resemblance to tree-like structures (although otherstructures are possible).

David Feller (Heriot Watt University) What Does this Notation Mean Anyway? July 19, 2017 8 / 30

Page 12: What Does this Notation Mean Anyway?daf3/presentation.pdf · 2017-07-19 · BNF-Style Notation as it is Used in Practice David Feller Supervisors: Fairouz Kamareddine and Joe Wells

Roughly how is Math-BNF Evaluated?

Substitution of metavariables for instances of the things theyrepresent (shared with BNF).

Expansion and decomposition of lists into each of their instances(where lists are defined using ellipses or a similar method).

Evaluation of common mathematical notation (most commonly settheory notation).

Grouping together of metavariables and syntax operators (e.g. byusing brackets).

Production of structures representing equivalence of statements (e.gα-equivalence).

Each rule produces a collection of all the things which can be producedthrough its legal application within the smallest possible context and thevariable ranges over all such collections. Often the things produced bythese rules bear a resemblance to tree-like structures (although otherstructures are possible).

20

17

-07

-19

What Does this Notation Mean Anyway?

Roughly how is Math-BNF Evaluated?

While Math-BNF has no standard which would formally tell us how to

interpret it, we point to a few strategies which are typically used when

working out what it says.

Page 13: What Does this Notation Mean Anyway?daf3/presentation.pdf · 2017-07-19 · BNF-Style Notation as it is Used in Practice David Feller Supervisors: Fairouz Kamareddine and Joe Wells

How does Math-BNF Abbreviate BNF Notation?

Terminal symbols not separated from metavariables.

Math-BNF e = x | λx .e | e eC = [ ]|λx .C |e C

“BNF” 〈e〉 = 〈x〉 | λ〈x〉.〈e〉 | 〈e〉〈e〉〈C 〉 = [ ] | λ〈x〉.〈C 〉|〈e〉〈C 〉

Some convention for separating metavariables from other syntax is needed.

David Feller (Heriot Watt University) What Does this Notation Mean Anyway? July 19, 2017 9 / 30

Page 14: What Does this Notation Mean Anyway?daf3/presentation.pdf · 2017-07-19 · BNF-Style Notation as it is Used in Practice David Feller Supervisors: Fairouz Kamareddine and Joe Wells

How does Math-BNF Abbreviate BNF Notation?

Terminal symbols not separated from metavariables.

Math-BNF e = x | λx .e | e eC = [ ]|λx .C |e C

“BNF” 〈e〉 = 〈x〉 | λ〈x〉.〈e〉 | 〈e〉〈e〉〈C 〉 = [ ] | λ〈x〉.〈C 〉|〈e〉〈C 〉

Some convention for separating metavariables from other syntax is needed.

20

17

-07

-19

What Does this Notation Mean Anyway?

How does Math-BNF Abbreviate BNFNotation?

These are fairly basic differences, we’ll explore more complex ones later

Page 15: What Does this Notation Mean Anyway?daf3/presentation.pdf · 2017-07-19 · BNF-Style Notation as it is Used in Practice David Feller Supervisors: Fairouz Kamareddine and Joe Wells

Other Abbreviations in the Math-BNF Grammar

Bracketing frequently omitted.

Conventions for choosing undefined metavariables.

Math-BNF e = x | λx .e | e eC = [ ]|λx .C |e C

“BNF” 〈x〉 = v |〈x〉′〈e〉 = 〈x〉 | (λ〈x〉.〈e〉) | (〈e〉〈e〉)〈C 〉 = [ ] | (λ〈x〉.〈C 〉)|(〈e〉〈C 〉)

David Feller (Heriot Watt University) What Does this Notation Mean Anyway? July 19, 2017 10 / 30

Page 16: What Does this Notation Mean Anyway?daf3/presentation.pdf · 2017-07-19 · BNF-Style Notation as it is Used in Practice David Feller Supervisors: Fairouz Kamareddine and Joe Wells

Other Abbreviations in the Math-BNF Grammar

Bracketing frequently omitted.

Conventions for choosing undefined metavariables.

Math-BNF e = x | λx .e | e eC = [ ]|λx .C |e C

“BNF” 〈x〉 = v |〈x〉′〈e〉 = 〈x〉 | (λ〈x〉.〈e〉) | (〈e〉〈e〉)〈C 〉 = [ ] | (λ〈x〉.〈C 〉)|(〈e〉〈C 〉)

20

17

-07

-19

What Does this Notation Mean Anyway?

Other Abbreviations in the Math-BNFGrammar

also bracketing automatically allowed even if not present in grammar

Page 17: What Does this Notation Mean Anyway?daf3/presentation.pdf · 2017-07-19 · BNF-Style Notation as it is Used in Practice David Feller Supervisors: Fairouz Kamareddine and Joe Wells

Tree Operations as Part of Syntax Evaluation

Unlike BNF, Math-BNF may include tree operations as part of theevaluation of its syntax.e = x | λx .e | e eA = [ ] | A[λx .A] e

@

[ ]

A λ

x A

e

David Feller (Heriot Watt University) What Does this Notation Mean Anyway? July 19, 2017 11 / 30

Page 18: What Does this Notation Mean Anyway?daf3/presentation.pdf · 2017-07-19 · BNF-Style Notation as it is Used in Practice David Feller Supervisors: Fairouz Kamareddine and Joe Wells

Tree Operations as Part of Syntax Evaluation

Unlike BNF, Math-BNF may include tree operations as part of theevaluation of its syntax.e = x | λx .e | e eA = [ ] | A[λx .A] e

@

[ ]

A λ

x A

e

20

17

-07

-19

What Does this Notation Mean Anyway?

Tree Operations as Part of Syntax Evaluation

Green concrete syntax (a bit like non terminal) + Math-BNF syntax,Blue metavars, black disambiguated metavar, Red syntax indicatingcomputation(dissapears in unparsing + needs to be constructed whenparsing).

Page 19: What Does this Notation Mean Anyway?daf3/presentation.pdf · 2017-07-19 · BNF-Style Notation as it is Used in Practice David Feller Supervisors: Fairouz Kamareddine and Joe Wells

Tree Operations as Part of Syntax Evaluation

Unlike BNF, Math-BNF may include tree operations as part of theevaluation of its syntax.e = x | λx .e | e eA = [ ] | A[λx .A] e

@

[ ]

A

[ ]

λ

x

x1

A

[ ]

e

x

x2

David Feller (Heriot Watt University) What Does this Notation Mean Anyway? July 19, 2017 12 / 30

Page 20: What Does this Notation Mean Anyway?daf3/presentation.pdf · 2017-07-19 · BNF-Style Notation as it is Used in Practice David Feller Supervisors: Fairouz Kamareddine and Joe Wells

Tree Operations as Part of Syntax Evaluation

Unlike BNF, Math-BNF may include tree operations as part of theevaluation of its syntax.e = x | λx .e | e eA = [ ] | A[λx .A] e

@

[ ]

A

[ ]

λ

x

x1

A

[ ]

e

x

x2

@

Root(A)

λ

x

x1

A

[ ]

e

x

x2

David Feller (Heriot Watt University) What Does this Notation Mean Anyway? July 19, 2017 13 / 30

Page 21: What Does this Notation Mean Anyway?daf3/presentation.pdf · 2017-07-19 · BNF-Style Notation as it is Used in Practice David Feller Supervisors: Fairouz Kamareddine and Joe Wells

Tree Operations as Part of Syntax Evaluation

Unlike BNF, Math-BNF may include tree operations as part of theevaluation of its syntax.e = x | λx .e | e eA = [ ] | A[λx .A] e

@

[ ]

A

[ ]

λ

x

x1

A

[ ]

e

x

x2

@

Root(A)

λ

x

x1

A

[ ]

e

x

x2

20

17

-07

-19

What Does this Notation Mean Anyway?

Tree Operations as Part of Syntax Evaluation

Red syntax disappears from tree when calculation performed

A parser reading the statements of the grammar (going the other way)

would have to spot where an A had been filled in. This syntax is very

parser-unfriendly.

Page 22: What Does this Notation Mean Anyway?daf3/presentation.pdf · 2017-07-19 · BNF-Style Notation as it is Used in Practice David Feller Supervisors: Fairouz Kamareddine and Joe Wells

Tree Operations as Part of Syntax Evaluation

Unlike BNF, Math-BNF may include tree operations as part of theevaluation of its syntax.e = x | λx .e | e eA = [ ] | A[λx .A] e

@

Root(A)

λ

x

x1

A

[ ]

e

x

x2

@

λ

x1 [ ]

x2

David Feller (Heriot Watt University) What Does this Notation Mean Anyway? July 19, 2017 14 / 30

Page 23: What Does this Notation Mean Anyway?daf3/presentation.pdf · 2017-07-19 · BNF-Style Notation as it is Used in Practice David Feller Supervisors: Fairouz Kamareddine and Joe Wells

Tree Operations as Part of Syntax Evaluation

Unlike BNF, Math-BNF may include tree operations as part of theevaluation of its syntax.e = x | λx .e | e eA = [ ] | A[λx .A] e

@

λ

x1 [ ]

x2

((λx1.[ ])x2)

David Feller (Heriot Watt University) What Does this Notation Mean Anyway? July 19, 2017 15 / 30

Page 24: What Does this Notation Mean Anyway?daf3/presentation.pdf · 2017-07-19 · BNF-Style Notation as it is Used in Practice David Feller Supervisors: Fairouz Kamareddine and Joe Wells

Do Tree Operations in Math-BNF have a BNF Equivalent?We consider the previous example:

e = x | λx .e | e e

A = [ ] | A[λx .A] e

We try writing the grammar as BNF with the hole filled in:

〈x〉 = var | 〈x〉′

〈e〉 = 〈x〉 | (λ〈x〉.〈e〉) | (〈e〉@〈e〉)

〈A〉 = [ ] | ((λ〈x〉.〈A〉)@〈e〉)

This will not deal with every statement of the grammar. Consider the casethe first A is ((λx .[ ])e) and the second is [ ]

(((λx .(λx .[ ]))e)e)

David Feller (Heriot Watt University) What Does this Notation Mean Anyway? July 19, 2017 16 / 30

Page 25: What Does this Notation Mean Anyway?daf3/presentation.pdf · 2017-07-19 · BNF-Style Notation as it is Used in Practice David Feller Supervisors: Fairouz Kamareddine and Joe Wells

Do Tree Operations in Math-BNF have a BNF Equivalent?We consider the previous example:

e = x | λx .e | e e

A = [ ] | A[λx .A] e

We try writing the grammar as BNF with the hole filled in:

〈x〉 = var | 〈x〉′

〈e〉 = 〈x〉 | (λ〈x〉.〈e〉) | (〈e〉@〈e〉)

〈A〉 = [ ] | ((λ〈x〉.〈A〉)@〈e〉)

This will not deal with every statement of the grammar. Consider the casethe first A is ((λx .[ ])e) and the second is [ ]

(((λx .(λx .[ ]))e)e)

20

17

-07

-19

What Does this Notation Mean Anyway?

Do Tree Operations in Math-BNF have a BNFEquivalent?

search for pumping lemma of context free languages

Say whether this can be done in BNF.

Page 26: What Does this Notation Mean Anyway?daf3/presentation.pdf · 2017-07-19 · BNF-Style Notation as it is Used in Practice David Feller Supervisors: Fairouz Kamareddine and Joe Wells

Math-BNF and α-equivalence

Unlike BNF which only produces sets of strings, statements produced usingMath-BNF can be evaluated as either strings or α-equivalence classes.

Church-Rosser property requires α-equality.

∀a, b, c ∈ S such that a*→ b and a

*→ c ∃d ∈ S with b*� d and c

*� d

(where*→ is a reduction system).

(λx .(λyx .xy)x)y →β (λxy .yx)y →β λz .zy

(λx .(λyx .xy)x)y →β (λyx .xy)y →β λx .xy

David Feller (Heriot Watt University) What Does this Notation Mean Anyway? July 19, 2017 17 / 30

Page 27: What Does this Notation Mean Anyway?daf3/presentation.pdf · 2017-07-19 · BNF-Style Notation as it is Used in Practice David Feller Supervisors: Fairouz Kamareddine and Joe Wells

Math-BNF and α-equivalence

Unlike BNF which only produces sets of strings, statements produced usingMath-BNF can be evaluated as either strings or α-equivalence classes.

Church-Rosser property requires α-equality.

∀a, b, c ∈ S such that a*→ b and a

*→ c ∃d ∈ S with b*� d and c

*� d

(where*→ is a reduction system).

(λx .(λyx .xy)x)y →β (λxy .yx)y →β λz .zy

(λx .(λyx .xy)x)y →β (λyx .xy)y →β λx .xy

20

17

-07

-19

What Does this Notation Mean Anyway?

Math-BNF and α-equivalence

Explain example at the bottom in detail

Page 28: What Does this Notation Mean Anyway?daf3/presentation.pdf · 2017-07-19 · BNF-Style Notation as it is Used in Practice David Feller Supervisors: Fairouz Kamareddine and Joe Wells

String Equality in Math-BNF

It is not enough to only evaluate Math-BNF statements underα-equivalence, discussion of subterms may require string equality.

A term N is a subterm of M if and only if one of the following conditionsarises:

M ≡ N

M ≡ λx .M ′ and N is a subterm of M ′

M ≡ PQ and N is a subterm of either P or Q

Is x a subterm of (λy .y)?

Yes — Does (λy .y) have all the variables as subterms? How wouldthis work?

No — Is y a subterm of (λy .y)?I Yes — Does this imply that (λx .x) 6= (λy .y)?I No — Does (λy .y) have any subterms that are smaller than it?

David Feller (Heriot Watt University) What Does this Notation Mean Anyway? July 19, 2017 18 / 30

Page 29: What Does this Notation Mean Anyway?daf3/presentation.pdf · 2017-07-19 · BNF-Style Notation as it is Used in Practice David Feller Supervisors: Fairouz Kamareddine and Joe Wells

How Difficult is it to Deal with α-equivalence inMath-BNF?

We look at some of the particular problems we might have in trying toevaluate arbitrary BNF-Grammars under α equivalence.

Lots of different notions of α-equality (e.g. λ and π calculus aredifferent). A general notion is needed.

The notion of a fresh variable may place unusual restrictions on whatset theory we can use (No AOC and a restricted powerset axiom).

BNF says nothing about α-equivalence classes. Binding also requiresthat we think about different representations when dealing withsyntax trees.

David Feller (Heriot Watt University) What Does this Notation Mean Anyway? July 19, 2017 19 / 30

Page 30: What Does this Notation Mean Anyway?daf3/presentation.pdf · 2017-07-19 · BNF-Style Notation as it is Used in Practice David Feller Supervisors: Fairouz Kamareddine and Joe Wells

How Difficult is it to Deal with α-equivalence inMath-BNF?

We look at some of the particular problems we might have in trying toevaluate arbitrary BNF-Grammars under α equivalence.

Lots of different notions of α-equality (e.g. λ and π calculus aredifferent). A general notion is needed.

The notion of a fresh variable may place unusual restrictions on whatset theory we can use (No AOC and a restricted powerset axiom).

BNF says nothing about α-equivalence classes. Binding also requiresthat we think about different representations when dealing withsyntax trees.

20

17

-07

-19

What Does this Notation Mean Anyway?

How Difficult is it to Deal with α-equivalencein Math-BNF?

We may wish to think of binding as joining the leaf nodes representing

variables of a tree to the position of their binder on the tree. This idea

breaks down when dealing with splicing operations such as the one we

looked at previously.

Page 31: What Does this Notation Mean Anyway?daf3/presentation.pdf · 2017-07-19 · BNF-Style Notation as it is Used in Practice David Feller Supervisors: Fairouz Kamareddine and Joe Wells

How does Math-BNF Incorporate Set Theory?

Unlike BNF, Math-BNF uses set theory notation as part of the syntax.

L ::= {m = Cm|m ∈ M}

In this example the reader is supposed to recognise that the ‘=’ inside theset is not a set theory ‘=’, but part of the syntax of the grammar beingdefined.

David Feller (Heriot Watt University) What Does this Notation Mean Anyway? July 19, 2017 20 / 30

Page 32: What Does this Notation Mean Anyway?daf3/presentation.pdf · 2017-07-19 · BNF-Style Notation as it is Used in Practice David Feller Supervisors: Fairouz Kamareddine and Joe Wells

Other Uses of Set Theory in Math-BNF Syntax

Here we examine how sets interact with other objects in the Math-BNFnotation as well as some variant syntax.

u∈UVar = a set of identifiersk ∈ CVar = a set of identifierslam ∈ Lam=ULam+CLamulam ∈ ULam::=(λe(u∗k)call)clam ∈ CLam::=(λγ(u∗)call)call ∈ Call = UCall + CCallucall ∈ UCall ::= (fe∗q)`ccall ∈ CCall ::= (q e∗)γe, f ∈ UExp = UVar + ULamq ∈ CExp = CVar + CLamψ ∈ Lab = ULab + CLab` ∈ ULab = a set of labelsγ ∈ CLab = a set of labelspr ∈ Pr = {ulam : ulam ∈ Ulam,

closed(ulam)}

Variant defining a set, ◦, and ametavariable, ∗, ranging over it.

∗ ∈ ◦ ::= �

= used to indicate set theoryevaluation, but set theory stillmixed with Math-BNF.

“Closed” doesn’t refer to normalset theoretic concept of closure.

UVar , CVar , ULab, CLab mustbe different + good size.

David Feller (Heriot Watt University) What Does this Notation Mean Anyway? July 19, 2017 21 / 30

Page 33: What Does this Notation Mean Anyway?daf3/presentation.pdf · 2017-07-19 · BNF-Style Notation as it is Used in Practice David Feller Supervisors: Fairouz Kamareddine and Joe Wells

Other Uses of Set Theory in Math-BNF Syntax

Here we examine how sets interact with other objects in the Math-BNFnotation as well as some variant syntax.

u∈UVar = a set of identifiersk ∈ CVar = a set of identifierslam ∈ Lam=ULam+CLamulam ∈ ULam::=(λe(u∗k)call)clam ∈ CLam::=(λγ(u∗)call)call ∈ Call = UCall + CCallucall ∈ UCall ::= (fe∗q)`ccall ∈ CCall ::= (q e∗)γe, f ∈ UExp = UVar + ULamq ∈ CExp = CVar + CLamψ ∈ Lab = ULab + CLab` ∈ ULab = a set of labelsγ ∈ CLab = a set of labelspr ∈ Pr = {ulam : ulam ∈ Ulam,

closed(ulam)}

Variant defining a set, ◦, and ametavariable, ∗, ranging over it.

∗ ∈ ◦ ::= �

= used to indicate set theoryevaluation, but set theory stillmixed with Math-BNF.

“Closed” doesn’t refer to normalset theoretic concept of closure.

UVar , CVar , ULab, CLab mustbe different + good size.

20

17

-07

-19

What Does this Notation Mean Anyway?

Other Uses of Set Theory in Math-BNF Syntax

Closed requires us to be able to interpret the grammar as it is beingproduced by the Math-BNF to determine the set theory constraint. It’s aconcept which relates to Math-BNF stuff not set stuff.

Math-BNF getting mixed with set theory in the definitions for example

pr , which is defined using set theory, uses ulam, defined using Math-BNF

etc.

Page 34: What Does this Notation Mean Anyway?daf3/presentation.pdf · 2017-07-19 · BNF-Style Notation as it is Used in Practice David Feller Supervisors: Fairouz Kamareddine and Joe Wells

Different Syntax Building Operators in Math-BNF

Unlike BNF, Math-BNF incorporates meta-level syntax for building lists ofproduction rules (e.g. ellipses, overbars)

τ+ ::= bool | τ−1 → τ+2 | {`1 : τ+

1 , ..., `n : τ+n } | α | τ+

1 t τ+2 |⊥| µα.τ

+

τ− ::= bool | τ+1 → τ−2 | {`1 : τ−1 , ..., `n : τ−n } | α |τ−1 u τ

−2 |>| µα.τ

Here a whole chunk of text is repeated and indexes on the variables areincreased by 1. For example we have:τ+ ::= {`1 : τ+

1 },τ+ ::= {`1 : τ+

1 , `2 : τ+2 },

τ+ ::= {`1 : τ+1 , `2 : τ+

2 , `3 : τ+3 },

τ+ ::= {`1 : τ+1 , `2 : τ+

2 , `3 : τ+3 , `4 : τ+

4 }, etc.

David Feller (Heriot Watt University) What Does this Notation Mean Anyway? July 19, 2017 22 / 30

Page 35: What Does this Notation Mean Anyway?daf3/presentation.pdf · 2017-07-19 · BNF-Style Notation as it is Used in Practice David Feller Supervisors: Fairouz Kamareddine and Joe Wells

Coinductive Definitions in Math-BNF

BNF is only used to inductively define sets of strings whereas Math-BNFmay be used to give coinductive definitions. In the example below P, Qand G are allowed to be of infinite length.

P,Q ::= Σi∈nGi | (P|Q)

G ::= a〈b〉.P | a(b).P | νa.P | τ.P | ♥.P

This is not a context free grammar!

David Feller (Heriot Watt University) What Does this Notation Mean Anyway? July 19, 2017 23 / 30

Page 36: What Does this Notation Mean Anyway?daf3/presentation.pdf · 2017-07-19 · BNF-Style Notation as it is Used in Practice David Feller Supervisors: Fairouz Kamareddine and Joe Wells

Coinductive Definitions in Math-BNF

BNF is only used to inductively define sets of strings whereas Math-BNFmay be used to give coinductive definitions. In the example below P, Qand G are allowed to be of infinite length.

P,Q ::= Σi∈nGi | (P|Q)

G ::= a〈b〉.P | a(b).P | νa.P | τ.P | ♥.P

This is not a context free grammar!

20

17

-07

-19

What Does this Notation Mean Anyway?

Coinductive Definitions in Math-BNF

Highlight BNF only produces CFGs

Page 37: What Does this Notation Mean Anyway?daf3/presentation.pdf · 2017-07-19 · BNF-Style Notation as it is Used in Practice David Feller Supervisors: Fairouz Kamareddine and Joe Wells

Metavariable Definitions in Math-BNFMath-BNF uses metavariables instead of BNF non-terminals.

The sets BNF meta-variables range over are not necessarily defined usingBNF productions of their own. Sometimes they may be defined with a pieceof mathematical text close to the abstract syntax itself. Cm inL ::= {m = Cm|m ∈ M} was defined using the following text:

Sometimes metavariables are not defined at all and are taken to range overalgebraic objects of an appropriate kind.

e.g. x in e = x | λx .e | e e

In order to deal with this one of two things are necessary:

Our understanding of Math-BNF must allow for the creation of countablymany generic algebraic objects (and possibly the creation of fresh algebraicobjects) as part of the syntax.

We must handle incomplete mathematics. That is to say, our model ofMath-BNF must handle the inclusion of arbitrary mathematical text robustlyenough to refer the reader to mathematical conventions.

David Feller (Heriot Watt University) What Does this Notation Mean Anyway? July 19, 2017 24 / 30

Page 38: What Does this Notation Mean Anyway?daf3/presentation.pdf · 2017-07-19 · BNF-Style Notation as it is Used in Practice David Feller Supervisors: Fairouz Kamareddine and Joe Wells

Metavariable Labelling Conventions in Math-BNF

Metavariable conventions also enable us to do various kinds of indexingand labelling by default, which we cannot do with BNF non-terminals.Separate instances of a metavariable x may be labelled in a subscript,superscript or both (e.g. x1, xn, x1, xn

k ). We may also write x ′, x ′′ etc.

We might write something like:

e = x | λx .e | e1 e2

Indexing conventions in mathematics can be used to show that twometavariables must take the same value, whereas BNF non-terminals arealways independent of one another.

David Feller (Heriot Watt University) What Does this Notation Mean Anyway? July 19, 2017 25 / 30

Page 39: What Does this Notation Mean Anyway?daf3/presentation.pdf · 2017-07-19 · BNF-Style Notation as it is Used in Practice David Feller Supervisors: Fairouz Kamareddine and Joe Wells

How Difficult is it to Deal with Metavariable LabellingConventions in Math-BNF?

Here is an example where the author has made use of some of themathematical uses of variables with indexes to alter the grammar.

Side conditions on production rules (Purple).

Arithmetic as part of the syntax (red).

E`,m ∈ ECtx`,mn ::= •[m = `] | λx .E`,m[` > 0] | 〈E`+1,m〉| E`−1,m[` > 0] | ! E`,m | E`,m e` | v ` E`,m[` > 0]| c E`,m[` = 0]

E`,m ∈ ECtx`,mv ::= •[m = `] | λx .E`,m[` > 0] | 〈E`+1,m〉| E`−1,m[` > 0] | ! E`,m | E`,m e` | v ` E`,m

This is not a context free grammar!

David Feller (Heriot Watt University) What Does this Notation Mean Anyway? July 19, 2017 26 / 30

Page 40: What Does this Notation Mean Anyway?daf3/presentation.pdf · 2017-07-19 · BNF-Style Notation as it is Used in Practice David Feller Supervisors: Fairouz Kamareddine and Joe Wells

How Difficult is it to Deal with Metavariable LabellingConventions in Math-BNF?

Here is an example where the author has made use of some of themathematical uses of variables with indexes to alter the grammar.

Side conditions on production rules (Purple).

Arithmetic as part of the syntax (red).

E`,m ∈ ECtx`,mn ::= •[m = `] | λx .E`,m[` > 0] | 〈E`+1,m〉| E`−1,m[` > 0] | ! E`,m | E`,m e` | v ` E`,m[` > 0]| c E`,m[` = 0]

E`,m ∈ ECtx`,mv ::= •[m = `] | λx .E`,m[` > 0] | 〈E`+1,m〉| E`−1,m[` > 0] | ! E`,m | E`,m e` | v ` E`,m

This is not a context free grammar!20

17

-07

-19

What Does this Notation Mean Anyway?

How Difficult is it to Deal with MetavariableLabelling Conventions in Math-BNF?

What can’t BNF do here?

Page 41: What Does this Notation Mean Anyway?daf3/presentation.pdf · 2017-07-19 · BNF-Style Notation as it is Used in Practice David Feller Supervisors: Fairouz Kamareddine and Joe Wells

Examples of Math-BNF

We take a look back at some of the expressions covered in this talk.

e = x | λx .e | e ev = λx .ea = A[v ]A = [ ] | A[λx .A]e

E`,m ∈ ECtx`,mn ::= •[m = `] | λx.E`,m [` > 0]

| 〈E`+1,m〉 |˜E`−1,m [` > 0]| ! E`,m

| E`,m e` | v` E`,m [` > 0] | c E`,m [` = 0]

E`,m ∈ ECtx`,mv ::= •[m = `] | λx.E`,m [` > 0]

| 〈E`+1,m〉 |˜E`−1,m [` > 0] | ! E`,m

| E`,m e` | v` E`,m

P,Q ::= Σi∈nGi | (P|Q)G ::= a〈b〉.P | a(b).P | νa.P | τ.P | ♥.P

u∈UVar = a set of identifiersk ∈ CVar = a set of identifierslam ∈ Lam=ULam+CLamulam ∈ ULam::=(λe(u∗k)call)clam ∈ CLam::=(λγ (u∗)call)call ∈ Call = UCall + CCallucall ∈ UCall ::= (fe∗q)`ccall ∈ CCall ::= (q e∗)γe, f ∈ UExp = UVar + ULamq ∈ CExp = CVar + CLamψ ∈ Lab = ULab + CLab` ∈ ULab = a set of labelsγ ∈ CLab = a set of labelspr ∈ Pr = {ulam : ulam ∈ Ulam,

closed(ulam)}

τ+ ::= bool|τ−1 → τ+2 | {`1 : τ+

1 , ..., `n : τ+n }|

α|τ+1 t τ

+2 |⊥|µα.τ

+

τ− ::= bool|τ+1 → τ−2 | {`1 : τ−1 , ..., `n : τ−n }|

α|τ−1 u τ−2 |>|µα.τ

David Feller (Heriot Watt University) What Does this Notation Mean Anyway? July 19, 2017 27 / 30

Page 42: What Does this Notation Mean Anyway?daf3/presentation.pdf · 2017-07-19 · BNF-Style Notation as it is Used in Practice David Feller Supervisors: Fairouz Kamareddine and Joe Wells

Examples of Math-BNF

We take a look back at some of the expressions covered in this talk.

e = x | λx .e | e ev = λx .ea = A[v ]A = [ ] | A[λx .A]e

E`,m ∈ ECtx`,mn ::= •[m = `] | λx.E`,m [` > 0]

| 〈E`+1,m〉 |˜E`−1,m [` > 0]| ! E`,m

| E`,m e` | v` E`,m [` > 0] | c E`,m [` = 0]

E`,m ∈ ECtx`,mv ::= •[m = `] | λx.E`,m [` > 0]

| 〈E`+1,m〉 |˜E`−1,m [` > 0] | ! E`,m

| E`,m e` | v` E`,m

P,Q ::= Σi∈nGi | (P|Q)G ::= a〈b〉.P | a(b).P | νa.P | τ.P | ♥.P

u∈UVar = a set of identifiersk ∈ CVar = a set of identifierslam ∈ Lam=ULam+CLamulam ∈ ULam::=(λe(u∗k)call)clam ∈ CLam::=(λγ (u∗)call)call ∈ Call = UCall + CCallucall ∈ UCall ::= (fe∗q)`ccall ∈ CCall ::= (q e∗)γe, f ∈ UExp = UVar + ULamq ∈ CExp = CVar + CLamψ ∈ Lab = ULab + CLab` ∈ ULab = a set of labelsγ ∈ CLab = a set of labelspr ∈ Pr = {ulam : ulam ∈ Ulam,

closed(ulam)}

τ+ ::= bool|τ−1 → τ+2 | {`1 : τ+

1 , ..., `n : τ+n }|

α|τ+1 t τ

+2 |⊥|µα.τ

+

τ− ::= bool|τ+1 → τ−2 | {`1 : τ−1 , ..., `n : τ−n }|

α|τ−1 u τ−2 |>|µα.τ

−20

17

-07

-19

What Does this Notation Mean Anyway?

Examples of Math-BNF

Mention notational differences and key points of departure from CFGs

Page 43: What Does this Notation Mean Anyway?daf3/presentation.pdf · 2017-07-19 · BNF-Style Notation as it is Used in Practice David Feller Supervisors: Fairouz Kamareddine and Joe Wells

Quick FixesWe explore some quick fixes we can try when evaluating the Math-BNFsyntax. A formal method for implementing some of these is presented inmore detail in the report.

List common metavariable declarations to separate metavariablesfrom concrete syntax.

Evaluate anything in curly brackets as though it were a set theoryexpression defining a set of strings and treat it as though it were ametavariable ranging over that set when it appears in the Math-BNFsyntax.

Assume any undeclared metavariable ranges over some appropriatecountable set of strings.

Treat syntax building rules as a set of constraints and solve for leastfixed point.

Expand any ellipses which involve repeating a character and/orincrementing an index into a corresponding set of BNF expressions.

Bracket any unbracketed expressions with two or more metavariablesbefore evaluating BNF.

David Feller (Heriot Watt University) What Does this Notation Mean Anyway? July 19, 2017 28 / 30

Page 44: What Does this Notation Mean Anyway?daf3/presentation.pdf · 2017-07-19 · BNF-Style Notation as it is Used in Practice David Feller Supervisors: Fairouz Kamareddine and Joe Wells

Why our Quick Fixes are not Sufficient

More serious issues written in bold.

Ignores problems arising from alpha equivalence and other sortsof equivalence.

Assumes that the process of solving for the smallest set can, ingeneral, be defined.

Still dealing only with strings.

Ignores internal structure of metavariables.

Ignores syntax representing computation.

Over simplifies bracketing.

No mention of syntactic variants.

May not deal with all uses of ellipses.

David Feller (Heriot Watt University) What Does this Notation Mean Anyway? July 19, 2017 29 / 30

Page 45: What Does this Notation Mean Anyway?daf3/presentation.pdf · 2017-07-19 · BNF-Style Notation as it is Used in Practice David Feller Supervisors: Fairouz Kamareddine and Joe Wells

Future Work

Work on a model which covers BNF, but which relates more closelyto trees.

Translate more complex operations which may be thought of in termsof manipulations on an abstract syntax tree to a representation in mymodel.

Continue documenting unusual uses of Math-BNF and testing andupdating my model.

Produce easy to navigate, accessible documentation withstraightforward definitions of any mathematical concepts I need touse.

David Feller (Heriot Watt University) What Does this Notation Mean Anyway? July 19, 2017 30 / 30