What Does this Notation Mean Anyway? BNF-Style Notation as it is - - PowerPoint PPT Presentation

what does this notation mean anyway
SMART_READER_LITE
LIVE PREVIEW

What Does this Notation Mean Anyway? BNF-Style Notation as it is - - PowerPoint PPT Presentation

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


slide-1
SLIDE 1

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

slide-2
SLIDE 2

Motivation

No universal standard for how BNF-style notation is used in Practice. Most existing standards relate only to languages as sets of ASCII strings. BNF-style notation often ambiguous so must be augmented for choosing 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 must be written to guarantee it meets an author’s requirements. We cannot know the circumstances under which we might derive contradictions in the systems it specifies unless another model is provided in a system that is clearly and unambiguously defined.

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

slide-3
SLIDE 3

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 integerdigit

Naur

delimiter ::= operator | separator | bracket | declarator | specificator

  • perator ::= arithmetic operator |

relational operator | logical operator | sequential operator arithmetic operator ::= +| − | × | / | ÷ | ↑ relational operator ::=< | ≤ | = | ≥ | > | = logical operator ::= ≡ | ⊂ | ∨ | ∧ |¬ sequential operator ::= go to | if | then | else | for | do separator ::=, |.|I0| : |; | := | ⊔ | step | until | while | comment bracket ::= (|)|[|]|‘|’| begin | end

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

slide-4
SLIDE 4

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 integerdigit

Naur

delimiter ::= operator | separator | bracket | declarator | specificator

  • perator ::= arithmetic operator |

relational operator | logical operator | sequential operator arithmetic operator ::= +| − | × | / | ÷ | ↑ relational operator ::=< | ≤ | = | ≥ | > | = logical operator ::= ≡ | ⊂ | ∨ | ∧ |¬ sequential operator ::= go to | if | then | else | for | do separator ::=, |.|I0| : |; | := | ⊔ | step | until | while | comment bracket ::= (|)|[|]|‘|’| begin | end

2017-07-19

What Does this Notation Mean Anyway? Examples of BNF Make clear Backus came first

slide-5
SLIDE 5

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|r l → id([v(,v)∗])? r → nat| “string” | array[v(,v)∗](v) c → c&&c|c||c|v==v|v! =v

::= may be written as =, :≡, ->, is, →, →, ← | may be written as or, or, newline Either terminals or non-terminals may be picked out, usually non-terminals are surrounded by triangle brackets whereas terminals may be picked out with 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

slide-6
SLIDE 6

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|r l → id([v(,v)∗])? r → nat| “string” | array[v(,v)∗](v) c → c&&c|c||c|v==v|v! =v

::= may be written as =, :≡, ->, is, →, →, ← | may be written as or, or, newline Either terminals or non-terminals may be picked out, usually non-terminals are surrounded by triangle brackets whereas terminals may be picked out with quote marks or underlines. My work is not concerned with these differences.

2017-07-19

What Does this Notation Mean Anyway? EBNF/ABNF Variants Right side Backus then Naur. Point out trivial differences. Put on

  • verhead all differences. 2 slides. List additional variants.

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

slide-7
SLIDE 7

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

slide-8
SLIDE 8

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

2017-07-19

What 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 can be readily converted into BNF is that BNF is a language for building sets of strings and the only notion of equality it deals with easily is string equality. It is possible to derive 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 author writes their grammar with a parser in mind, inferring a sensible parse tree from a set

  • f productions is non-trivial.

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

slide-9
SLIDE 9

Why did People Start Using BNF-Style Notation Differently?

BNF only deals with strings. The only sets it deals with are sets of

  • strings. The only notion of tree equality it supports comes from parse

trees, which may be ambiguous. The syntactic entities it recognises are strings. Many authors want to use the notation to talk about trees and sets directly and use more complex expressions while doing so. Many authors who use BNF-Style notation work with mathematical

  • bjects and want to be able to use mathematical conventions when

defining their grammars. Sometimes authors invent notation which gets picked up more widely. Authors often like to miss out pieces of syntax that are fairly standard in order to make their grammars easier for humans to read. There a fairly consistent way in which BNF-style notation has come to be used in the literature which is particularly distinct from BNF. We call this Math-BNF.

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

slide-10
SLIDE 10

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

slide-11
SLIDE 11

Roughly how is Math-BNF Evaluated?

Substitution of metavariables for instances of the things they represent (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 set theory notation). Grouping together of metavariables and syntax operators (e.g. by using brackets). Production of structures representing equivalence of statements (e.g α-equivalence). Each rule produces a collection of all the things which can be produced through its legal application within the smallest possible context and the variable ranges over all such collections. Often the things produced by these rules bear a resemblance to tree-like structures (although other structures are possible).

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

slide-12
SLIDE 12

Roughly how is Math-BNF Evaluated?

Substitution of metavariables for instances of the things they represent (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 set theory notation). Grouping together of metavariables and syntax operators (e.g. by using brackets). Production of structures representing equivalence of statements (e.g α-equivalence). Each rule produces a collection of all the things which can be produced through its legal application within the smallest possible context and the variable ranges over all such collections. Often the things produced by these rules bear a resemblance to tree-like structures (although other structures are possible).

2017-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.

slide-13
SLIDE 13

How does Math-BNF Abbreviate BNF Notation?

Terminal symbols not separated from metavariables. Math-BNF e = x | λx.e | e e C = [ ]|λx.C|e C “BNF” e = x | λx.e | ee C = [ ] | λx.C|eC 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

slide-14
SLIDE 14

How does Math-BNF Abbreviate BNF Notation?

Terminal symbols not separated from metavariables. Math-BNF e = x | λx.e | e e C = [ ]|λx.C|e C “BNF” e = x | λx.e | ee C = [ ] | λx.C|eC Some convention for separating metavariables from other syntax is needed.

2017-07-19

What Does this Notation Mean Anyway? How does Math-BNF Abbreviate BNF Notation? These are fairly basic differences, we’ll explore more complex ones later

slide-15
SLIDE 15

Other Abbreviations in the Math-BNF Grammar

Bracketing frequently omitted. Conventions for choosing undefined metavariables. Math-BNF e = x | λx.e | e e C = [ ]|λx.C|e C “BNF” x = v|x′ e = x | (λx.e) | (ee) C = [ ] | (λx.C)|(eC)

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

slide-16
SLIDE 16

Other Abbreviations in the Math-BNF Grammar

Bracketing frequently omitted. Conventions for choosing undefined metavariables. Math-BNF e = x | λx.e | e e C = [ ]|λx.C|e C “BNF” x = v|x′ e = x | (λx.e) | (ee) C = [ ] | (λx.C)|(eC)

2017-07-19

What Does this Notation Mean Anyway? Other Abbreviations in the Math-BNF Grammar also bracketing automatically allowed even if not present in grammar

slide-17
SLIDE 17

Tree Operations as Part of Syntax Evaluation

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

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

slide-18
SLIDE 18

Tree Operations as Part of Syntax Evaluation

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

2017-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 indicating computation(dissapears in unparsing + needs to be constructed when parsing).

slide-19
SLIDE 19

Tree Operations as Part of Syntax Evaluation

Unlike BNF, Math-BNF may include tree operations as part of the evaluation of its syntax. e = x | λx.e | e e A = [ ] | 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

slide-20
SLIDE 20

Tree Operations as Part of Syntax Evaluation

Unlike BNF, Math-BNF may include tree operations as part of the evaluation of its syntax. e = x | λx.e | e e A = [ ] | 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

slide-21
SLIDE 21

Tree Operations as Part of Syntax Evaluation

Unlike BNF, Math-BNF may include tree operations as part of the evaluation of its syntax. e = x | λx.e | e e A = [ ] | A[λx.A] e @ [ ] A [ ] λ x x1 A [ ] e x x2 @ Root(A) λ x x1 A [ ] e x x2

2017-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.

slide-22
SLIDE 22

Tree Operations as Part of Syntax Evaluation

Unlike BNF, Math-BNF may include tree operations as part of the evaluation of its syntax. e = x | λx.e | e e A = [ ] | 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

slide-23
SLIDE 23

Tree Operations as Part of Syntax Evaluation

Unlike BNF, Math-BNF may include tree operations as part of the evaluation of its syntax. e = x | λx.e | e e A = [ ] | A[λx.A] e @ λ x1 [ ] x2 ((λx1.[ ])x2)

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

slide-24
SLIDE 24

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 case the 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

slide-25
SLIDE 25

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 case the first A is ((λx.[ ])e) and the second is [ ] (((λx.(λx.[ ]))e)e)

2017-07-19

What Does this Notation Mean Anyway? Do Tree Operations in Math-BNF have a BNF Equivalent? search for pumping lemma of context free languages Say whether this can be done in BNF.

slide-26
SLIDE 26

Math-BNF and α-equivalence

Unlike BNF which only produces sets of strings, statements produced using Math-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

slide-27
SLIDE 27

Math-BNF and α-equivalence

Unlike BNF which only produces sets of strings, statements produced using Math-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

2017-07-19

What Does this Notation Mean Anyway? Math-BNF and α-equivalence Explain example at the bottom in detail

slide-28
SLIDE 28

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 conditions arises: 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 would this work? No — Is y a subterm of (λy.y)?

◮ Yes — Does this imply that (λx.x) = (λy.y)? ◮ 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

slide-29
SLIDE 29

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

We look at some of the particular problems we might have in trying to evaluate arbitrary BNF-Grammars under α equivalence. Lots of different notions of α-equality (e.g. λ and π calculus are different). A general notion is needed. The notion of a fresh variable may place unusual restrictions on what set theory we can use (No AOC and a restricted powerset axiom). BNF says nothing about α-equivalence classes. Binding also requires that we think about different representations when dealing with syntax trees.

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

slide-30
SLIDE 30

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

We look at some of the particular problems we might have in trying to evaluate arbitrary BNF-Grammars under α equivalence. Lots of different notions of α-equality (e.g. λ and π calculus are different). A general notion is needed. The notion of a fresh variable may place unusual restrictions on what set theory we can use (No AOC and a restricted powerset axiom). BNF says nothing about α-equivalence classes. Binding also requires that we think about different representations when dealing with syntax trees.

2017-07-19

What Does this Notation Mean Anyway? How Difficult is it to Deal with α-equivalence in 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.

slide-31
SLIDE 31

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 the set is not a set theory ‘=’, but part of the syntax of the grammar being defined.

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

slide-32
SLIDE 32

Other Uses of Set Theory in Math-BNF Syntax

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

u∈UVar = a set of identifiers k ∈ CVar = a set of identifiers lam ∈ Lam=ULam+CLam ulam ∈ ULam::=(λe(u∗k)call) clam ∈ CLam::=(λγ(u∗)call) call ∈ Call = UCall + CCall ucall ∈ UCall ::= (fe∗q)ℓ ccall ∈ CCall ::= (q e∗)γ e, f ∈ UExp = UVar + ULam q ∈ CExp = CVar + CLam ψ ∈ Lab = ULab + CLab ℓ ∈ ULab = a set of labels γ ∈ CLab = a set of labels pr ∈ Pr = {ulam : ulam ∈ Ulam, closed(ulam)}

Variant defining a set, ◦, and a metavariable, ∗, ranging over it. ∗ ∈ ◦ ::= = used to indicate set theory evaluation, but set theory still mixed with Math-BNF. “Closed” doesn’t refer to normal set theoretic concept of closure. UVar, CVar, ULab, CLab must be different + good size.

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

slide-33
SLIDE 33

Other Uses of Set Theory in Math-BNF Syntax

Here we examine how sets interact with other objects in the Math-BNF notation as well as some variant syntax. u∈UVar = a set of identifiers k ∈ CVar = a set of identifiers lam ∈ Lam=ULam+CLam ulam ∈ ULam::=(λe(u∗k)call) clam ∈ CLam::=(λγ(u∗)call) call ∈ Call = UCall + CCall ucall ∈ UCall ::= (fe∗q)ℓ ccall ∈ CCall ::= (q e∗)γ e, f ∈ UExp = UVar + ULam q ∈ CExp = CVar + CLam ψ ∈ Lab = ULab + CLab ℓ ∈ ULab = a set of labels γ ∈ CLab = a set of labels pr ∈ Pr = {ulam : ulam ∈ Ulam, closed(ulam)} Variant defining a set, ◦, and a metavariable, ∗, ranging over it. ∗ ∈ ◦ ::= = used to indicate set theory evaluation, but set theory still mixed with Math-BNF. “Closed” doesn’t refer to normal set theoretic concept of closure. UVar, CVar, ULab, CLab must be different + good size.

2017-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 being produced by the Math-BNF to determine the set theory constraint. It’s a concept 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.

slide-34
SLIDE 34

Different Syntax Building Operators in Math-BNF

Unlike BNF, Math-BNF incorporates meta-level syntax for building lists of production rules (e.g. ellipses, overbars) τ + ::= bool | τ −

1 → τ + 2 | {ℓ1 : τ + 1 , ..., ℓn : τ + n } | α | τ + 1 ⊔ τ + 2 |⊥| µα.τ +

τ − ::= bool | τ +

1 → τ − 2 | {ℓ1 : τ − 1 , ..., ℓn : τ − n } | α |τ − 1 ⊓ τ − 2 |⊤| µα.τ −

Here a whole chunk of text is repeated and indexes on the variables are increased 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

slide-35
SLIDE 35

Coinductive Definitions in Math-BNF

BNF is only used to inductively define sets of strings whereas Math-BNF may be used to give coinductive definitions. In the example below P, Q and G are allowed to be of infinite length. P, Q ::= Σi∈nGi | (P|Q) G ::= ab.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

slide-36
SLIDE 36

Coinductive Definitions in Math-BNF

BNF is only used to inductively define sets of strings whereas Math-BNF may be used to give coinductive definitions. In the example below P, Q and G are allowed to be of infinite length. P, Q ::= Σi∈nGi | (P|Q) G ::= ab.P | a(b).P | νa.P | τ.P | ♥.P This is not a context free grammar!

2017-07-19

What Does this Notation Mean Anyway? Coinductive Definitions in Math-BNF Highlight BNF only produces CFGs

slide-37
SLIDE 37

Metavariable Definitions in Math-BNF

Math-BNF uses metavariables instead of BNF non-terminals.

The sets BNF meta-variables range over are not necessarily defined using BNF productions of their own. Sometimes they may be defined with a piece

  • f mathematical text close to the abstract syntax itself. Cm in

L ::= {m = Cm|m ∈ M} was defined using the following text: Sometimes metavariables are not defined at all and are taken to range over algebraic 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 countably many generic algebraic objects (and possibly the creation of fresh algebraic

  • bjects) as part of the syntax.

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

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

slide-38
SLIDE 38

Metavariable Labelling Conventions in Math-BNF

Metavariable conventions also enable us to do various kinds of indexing and 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 two metavariables must take the same value, whereas BNF non-terminals are always independent of one another.

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

slide-39
SLIDE 39

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

Here is an example where the author has made use of some of the mathematical 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ℓ,m

n

::= •[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ℓ,m

v

::= •[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

slide-40
SLIDE 40

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

Here is an example where the author has made use of some of the mathematical 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ℓ,m

n

::= •[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ℓ,m

v

::= •[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!

2017-07-19

What Does this Notation Mean Anyway? How Difficult is it to Deal with Metavariable Labelling Conventions in Math-BNF? What can’t BNF do here?

slide-41
SLIDE 41

Examples of Math-BNF

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

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

Eℓ,m ∈ ECtxℓ,m

n

::= •[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ℓ,m

v

::= •[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 ::= ab.P | a(b).P | νa.P | τ.P | ♥.P

u∈UVar = a set of identifiers k ∈ CVar = a set of identifiers lam ∈ Lam=ULam+CLam ulam ∈ ULam::=(λe(u∗k)call) clam ∈ CLam::=(λγ(u∗)call) call ∈ Call = UCall + CCall ucall ∈ UCall ::= (fe∗q)ℓ ccall ∈ CCall ::= (q e∗)γ e, f ∈ UExp = UVar + ULam q ∈ CExp = CVar + CLam ψ ∈ Lab = ULab + CLab ℓ ∈ ULab = a set of labels γ ∈ CLab = a set of labels pr ∈ Pr = {ulam : ulam ∈ Ulam, closed(ulam)} τ+ ::= bool|τ−

1

→ τ+

2 | {ℓ1 : τ+ 1 , ..., ℓn : τ+ n }|

α|τ+

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

τ− ::= bool|τ+

1

→ τ−

2 | {ℓ1 : τ− 1 , ..., ℓn : τ− n }|

α|τ−

1

⊓ τ−

2 |⊤|µα.τ−

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

slide-42
SLIDE 42

Examples of Math-BNF

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

e = x | λx.e | e e v = λx.e a = A[v] A = [ ] | A[λx.A]e Eℓ,m ∈ ECtxℓ,m

n ::= •[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ℓ,m v ::= •[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 ::= ab.P | a(b).P | νa.P | τ.P | ♥.P u∈UVar = a set of identifiers k ∈ CVar = a set of identifiers lam ∈ Lam=ULam+CLam ulam ∈ ULam::=(λe(u∗k)call) clam ∈ CLam::=(λγ(u∗)call) call ∈ Call = UCall + CCall ucall ∈ UCall ::= (fe∗q)ℓ ccall ∈ CCall ::= (q e∗)γ e, f ∈ UExp = UVar + ULam q ∈ CExp = CVar + CLam ψ ∈ Lab = ULab + CLab ℓ ∈ ULab = a set of labels γ ∈ CLab = a set of labels pr ∈ Pr = {ulam : ulam ∈ Ulam, closed(ulam)} τ+ ::= bool|τ−

1 → τ+ 2 | {ℓ1 : τ+ 1 , ..., ℓn : τ+ n }| α|τ+ 1 ⊔ τ+ 2 |⊥|µα.τ+ τ− ::= bool|τ+ 1 → τ− 2 | {ℓ1 : τ− 1 , ..., ℓn : τ− n }| α|τ− 1 ⊓ τ− 2 |⊤|µα.τ−

2017-07-19

What Does this Notation Mean Anyway? Examples of Math-BNF Mention notational differences and key points of departure from CFGs

slide-43
SLIDE 43

Quick Fixes

We explore some quick fixes we can try when evaluating the Math-BNF

  • syntax. A formal method for implementing some of these is presented in

more detail in the report. List common metavariable declarations to separate metavariables from concrete syntax. Evaluate anything in curly brackets as though it were a set theory expression defining a set of strings and treat it as though it were a metavariable ranging over that set when it appears in the Math-BNF syntax. Assume any undeclared metavariable ranges over some appropriate countable set of strings. Treat syntax building rules as a set of constraints and solve for least fixed point. Expand any ellipses which involve repeating a character and/or incrementing an index into a corresponding set of BNF expressions. Bracket any unbracketed expressions with two or more metavariables before evaluating BNF.

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

slide-44
SLIDE 44

Why our Quick Fixes are not Sufficient

More serious issues written in bold. Ignores problems arising from alpha equivalence and other sorts

  • f equivalence.

Assumes that the process of solving for the smallest set can, in general, 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

slide-45
SLIDE 45

Future Work

Work on a model which covers BNF, but which relates more closely to trees. Translate more complex operations which may be thought of in terms

  • f manipulations on an abstract syntax tree to a representation in my

model. Continue documenting unusual uses of Math-BNF and testing and updating my model. Produce easy to navigate, accessible documentation with straightforward definitions of any mathematical concepts I need to use.

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