效绵鼎 BNF Notation Grammars for programming languages are often written in BNF (Backus-Naur Form ) Variables are words in <...>Example: <statement>. Terminals are often multicharacter strings indicated by boldface or underline;Example: while or WHILE .17
BNF Notation ◼ Grammars for programming languages are often written in BNF (Backus-Naur Form ). ◼ Variables are words in <…>; Example: <statement>. ◼ Terminals are often multicharacter strings indicated by boldface or underline; Example: while or WHILE. 17
效绵鼎 BNF Notation-(2) Symbol ::is often used for - Symbol|is used for“or.” o A shorthand for a list of productions with the same left side. Example:S->0S1 01 is shorthand for S->0S1 and S -01. .18
BNF Notation – (2) ◼ Symbol ::= is often used for ->. ◼ Symbol | is used for “ or.” A shorthand for a list of productions with the same left side. ◼ Example: S -> 0S1 | 01 is shorthand for S -> 0S1 and S -> 01. 18
效绵鼎 BNF Notation -Kleene Closure ■ Symbol ..is used for "one or more. Example:<digit>:=0123456789 <unsigned integer>:=<digit>... ■ Translation:Replace a...with a new variable A and productions A->Aa a. .19
BNF Notation – Kleene Closure ◼ Symbol … is used for “ one or more.” ◼ Example: <digit> ::= 0|1|2|3|4|5|6|7|8|9 <unsigned integer> ::= <digit>… ◼ Translation: Replace … with a new variable A and productions A -> A | . 19
效绵鼎 Example:Kleene Closure Grammar for unsigned integers can be replaced by: U>UD D D->0112134516171819 .20
Example: Kleene Closure ◼ Grammar for unsigned integers can be replaced by: U -> UD | D D -> 0|1|2|3|4|5|6|7|8|9 20
绵鼎 BNF Notation:Optional Elements Surround one or more symbols by [..to make them optional. Example:<statement>::=if <condition>then <statement>[else <statement>] Translation:replace [a]by a new variable A with productions A->aE. 21
BNF Notation: Optional Elements ◼ Surround one or more symbols by […] to make them optional. ◼ Example: <statement> ::= if <condition> then <statement> [; else <statement>] ◼ Translation: replace [] by a new variable A with productions A -> | ε. 21