what does this notation mean anyway
play

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


  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

  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

  3. Examples of BNF Backus Naur � digit � : ≡ O or 1 or 2 or 3 or 4 or 5 or 6 or � delimiter � ::= � operator � | � separator � | 7 or 8 or 9 � bracket � | � declarator � | � specificator � � integer � : ≡ � digit � or � integer �� digit � � operator � ::= � 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

  4. Examples of BNF What Does this Notation Mean Anyway? 2017-07-19 Backus Naur � digit � : ≡ O or 1 or 2 or 3 or 4 or 5 or 6 or � delimiter � ::= � operator � | � separator � | 7 or 8 or 9 � bracket � | � declarator � | � specificator � � integer � : ≡ � digit � or � integer �� digit � � operator � ::= � arithmetic operator � | � relational operator � | � logical operator � | � sequential operator � � arithmetic operator � ::= + | − | × | / | ÷ | ↑ � relational operator � ::= < | ≤ | = | ≥ | > | � = � logical operator � ::= ≡ | ⊂ | ∨ | ∧ |¬ Examples of BNF � sequential operator � ::= go to | if | then | else | for | do � separator � ::= , | . | I0 | : | ; | := | ⊔ | step | until | while | comment � bracket � ::= ( | ) | [ | ] | ‘ | ’ | begin | end Make clear Backus came first

  5. EBNF/ABNF Variants letter = “A” | “B” | “C” | “D” | “E” | “F” v → l | r l → id ([ v ( , v ) ∗ ]) ? | “G” | “H” | “I” | “J” | “K” | “L” | “M” | “N” | “O” | “P” | “Q” | “R” | “S” | “T” r → nat | “ string ” | | “U” | “V” | “W” | “X” | “Y” | “Z”; array[ v ( , v ) ∗ ]( v ) vowel = “A” | “E” | “I” | “O” | “U”; c → c && c | c || c | v == v | v ! = v consonant = letter − vowel; ::= 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

  6. EBNF/ABNF Variants What Does this Notation Mean Anyway? letter = “A” | “B” | “C” | “D” | “E” | “F” v → l | r l → id ([ v ( , v ) ∗ ]) ? 2017-07-19 | “G” | “H” | “I” | “J” | “K” | “L” | “M” | “N” | “O” | “P” | “Q” | “R” | “S” | “T” r → nat | “ string ” | | “U” | “V” | “W” | “X” | “Y” | “Z”; array[ v ( , v ) ∗ ]( v ) vowel = “A” | “E” | “I” | “O” | “U”; c → c && c | c || c | v == v | v ! = v consonant = letter − vowel; ::= may be written as =, : ≡ , - > , is , → , �→ , ← | may be written as or , or, newline EBNF/ABNF Variants 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. Right side Backus then Naur. Point out trivial differences. Put on overhead 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

  7. How Does BNF Work Normally? � DI � ::= - � PD � | � PD � Decimal integer � DI � � PD � := � DL � | � DL � . � DL � Positive decimal � PD � � DL � := � D � | � D � � DL � Digit list � DL � � D � := 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 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

  8. How Does BNF Work Normally? What Does this Notation Mean Anyway? 2017-07-19 � DI � ::= - � PD � | � PD � Decimal integer � DI � � PD � := � DL � | � DL � . � DL � Positive decimal � PD � � DL � := � D � | � D � � DL � Digit list � DL � � D � := 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 Digit � D � � DI � � PD � � DL � . � DL � � D � . � DL � 3 . � DL � How Does BNF Work Normally? 3 . � D � � DL � 3 . 1 � DL � 3 . 1 � D � 3 . 1 4 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 of productions is non-trivial. BNF does not deal with ambiguous strings w-out parsing conventions

  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 objects 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

  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

  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

Recommend


More recommend