DOC PREVIEW
Penn CIT 594 - CIT 594 LECTURE NOTES

This preview shows page 1-2-3-4 out of 13 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 13 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 13 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 13 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 13 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 13 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

BNFMetalanguagesSlide 3Slide 4BNF uses recursionBNF Examples IBNF Examples IIBNF Examples IIIBNF Examples IVExtended BNFVariationsLimitations of BNFThe EndJan 13, 2019BNFMetalanguagesA metalanguage is a language used to talk about a language (usually a different one)We can use English as its own metalanguage (e.g. describing English grammar in English)It is essential to distinguish between the metalanguage terms and the object language termsBNFBNF stands for either Backus-Naur Form or Backus Normal FormBNF is a metalanguage used to describe the grammar of a programming languageBNF is formal and preciseBNF is a notation for context-free grammarsBNF is essential in compiler constructionThere are many dialects of BNF in use, but……the differences are almost always minorBNF< > indicate a nonterminal that needs to be further expanded, e.g. <variable>Symbols not enclosed in < > are terminals; they represent themselves, e.g. if, while, (The symbol ::= means is defined asThe symbol | means or; it separates alternatives, e.g. <addop> ::= + | -This is all there is to “plain” BNF; but we will discuss extended BNF (EBNF) later in this lectureBNF uses recursion<integer> ::= <digit> | <integer> <digit> or<integer> ::= <digit> | <digit> <integer>Recursion is all that is needed (at least, in a formal sense)"Extended BNF" allows repetition as well as recursionRepetition is usually better when using BNF to construct a compilerBNF Examples I<digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9<if statement> ::= if ( <condition> ) <statement> | if ( <condition> ) <statement> else <statement>BNF Examples II <unsigned integer> ::= <digit> | <unsigned integer> <digit><integer> ::= <unsigned integer> | + <unsigned integer> | - <unsigned integer>BNF Examples III<identifier> ::= <letter> | <identifier> <letter> | <identifier> <digit><block> ::= { <statement list> }<statement list> ::= <statement> | <statement list> <statement>BNF Examples IV<statement> ::= <block> | <assignment statement> | <break statement> | <continue statement> | <do statement> | <for loop> | <goto statement> | <if statement> | . . .Extended BNFThe following are pretty standard:[ ] enclose an optional part of the ruleExample:<if statement> ::= if ( <condition> ) <statement> [ else <statement> ]{ } mean the enclosed can be repeated any number of times (including zero)Example:<parameter list> ::= ( ) | ( { <parameter> , } <parameter> )VariationsThe preceding notation is the original and most common notationBNF was designed before we had boldface, color, more than one font, etc.A typical modern variation might: Use boldface to indicate multi-character terminalsQuote single-character terminals (because boldface isn’t so obvious in this case)Example:if_statement ::= if "(" condition ")" statement [ else state m ent ]Limitations of BNFNo easy way to impose length limitations, such as maximum length of variable namesNo easy way to describe ranges, such as 1 to 31No way at all to impose distributed requirements, such as, a variable must be declared before it is usedDescribes only syntax, not semanticsNothing clearly better has been devisedThe


View Full Document

Penn CIT 594 - CIT 594 LECTURE NOTES

Documents in this Course
Trees

Trees

17 pages

Searching

Searching

24 pages

Pruning

Pruning

11 pages

Arrays

Arrays

17 pages

Stacks

Stacks

30 pages

Recursion

Recursion

25 pages

Hashing

Hashing

24 pages

Recursion

Recursion

24 pages

Graphs

Graphs

25 pages

Storage

Storage

37 pages

Trees

Trees

21 pages

Arrays

Arrays

24 pages

Hashing

Hashing

24 pages

Recursion

Recursion

25 pages

Graphs

Graphs

23 pages

Graphs

Graphs

25 pages

Stacks

Stacks

25 pages

Recursion

Recursion

25 pages

Quicksort

Quicksort

21 pages

Quicksort

Quicksort

21 pages

Graphs

Graphs

25 pages

Recursion

Recursion

25 pages

Searching

Searching

24 pages

Counting

Counting

20 pages

HTML

HTML

18 pages

Recursion

Recursion

24 pages

Pruning

Pruning

11 pages

Graphs

Graphs

25 pages

Load more
Download CIT 594 LECTURE NOTES
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view CIT 594 LECTURE NOTES and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view CIT 594 LECTURE NOTES 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?