Presentation is loading. Please wait.

Presentation is loading. Please wait.

September 13th Grammars.

Similar presentations


Presentation on theme: "September 13th Grammars."— Presentation transcript:

1 September 13th Grammars

2 Grammars They are a way of describing the syntax of programming languages We will be using BNF grammar (as in Mini-Language Core) Syntax diagrams (in Pascal) BNF grammar Was invented in 1958 as a way of describing Algol 58 by John Backus

3 BNF grammars BNF grammar is context-free grammar
Noam Chomsky – classified grammars Context-free grammar Regular grammar Context-sensitiver grammar

4 Characteristics of grammar
A grammar consists of A four-tuple A set of terminals A set of non-terminals A set of rules (or productions) A start (or goal) symbol

5 Uses of grammars It can be used to generate legal sentences in a programming language It can be used to determine whether a given sentence in a programming language is correct parsing

6 What did we learn from Mini-Language Core’s BNF
It described the language well enough for most of us to write a program in an unfamiliar language We could determine whether a given statement we wrote in Mini-Language Core was correct It really only told us about syntax, not about semantics There were a number of things that we could not determine from the grammar

7 Terminology Lexemes – lowest level syntactic units
Token – is a category of lexemes index = 2 * count + 17; Index, count are identifiers =, *, + are operators 2, 17 are integer literals ; is a separator or terminator Metalanguage – is a language used to describe other languages Aside: identifiers can reference variables, constants, methods, programs, etc.

8 Potential Problems A grammar may be ambiguous
Two different parse trees may be generated for the same expression.

9 Sections 3.4 and later Less important in this class – read to be able to answer homework questions but don’t agonize over the material in axiomatic and denotational semantics.


Download ppt "September 13th Grammars."

Similar presentations


Ads by Google