[CSUSB]
>> [CNS]
>> [Comp Sci]
>> [R J Botting]
>>
03
Brief summary
| XBNF | \TeX | Set Operation |
|---|---|---|
| | | \cup | union |
| & | \cap | intersection |
| ~ | - | complement |
| >< | ? | Cartesian product |
| in | \epsilon | membership |
| <== | ? | containment |
| ==> | \subseteq | subset or equal |
| <<= | ? | containment |
| =>> | \subset | subset and not equal |
| |S| | |S| | cardinality, number of elements in S |
| {} | ? | the null set |
| S^n | S^n | a string of n elements each in S |
| #S | S^* | a string of any number of elements each in S including none |
Notice that I put terminals in quotations and link non-terminals to their definition.
Extended BNF
When preparing notes I don't usually use the {}[] notation.
I like to use {} and [] for other purposes.
I tend to write
The WHILE Language
Here is my personal definition of the WHILE language compare it
with our text book's. Is it more powerful or not?
| Type | LHS | RHS | Languages defined | Language accepted by |
|---|---|---|---|---|
| 0 | string | string | Recursively Enumerable | Nondeterministic Turing Machine |
| 1 | shorter_string | string | context-sensitive | Linear Bounded Turing Machine |
| 2 | nonterminal | string | ? | ? |
| 3 | nonterminal | term nonterminal | term | regular, right linear | finite state machine |
| 3 | nonterminal | nonterminal term | term | regular, left linear | finite state machine |
Ambiguity
Theoretical books at the graduate level often have ambiguous grammars
because they define:
Net
We can remove this easily by adding an extra production/definition:
Net
Because it is easy to remove..... most texts do not worry about it.
Terminators and Separators
Notice that the semicolon in programming languages is used in
two very different ways. In the C/C++/Java family the semicolon
is an essential terminating part of a statement that contains
an expression:
x = ++x + x++;
However in the Algol/Pascal/Ada tradition the semicolon is not part of a statement but is put between two statements:
Both approaches have advantages. It is worth learning to switch between the modes.
. . . . . . . . . ( end of section Syntax) <<Contents | Index>>
Questions
In top down we assume that the whole fits the Binary_number and
try to match that against the alternative forms:
There will be more on this in chapter 4.
Explain Indirect Recursion
Here is an example
Net
What is the difference between a Lexical Unit and a Vocabulary
A Vocabulary is a collection of lexical units. A lexical unit
is a member of the vocabulary.
Do the Chomsky Types form a hierarchy.
Yes. All type 3 grammars are Type 2, all Type 2's are Type 1's and
all type 1's are also type 0.
Further, they form a strict hierarchy: there are languages that can be defined by a type 0 grammar but not by a type 1, and languages of type 1 that can not be defined using a type 2, and so on.
A key moment in Computer Science is the discovery by Floyd that although Algol 60 was defined using BNF it could not be completely be defined by a context free grammar like BNF. The problem is that we need to express type checking rules so that we are not allowed to write silly statements like multiplying a string by an amount of money. This started the search for an equally way of expressing the restrictions on the BNF rules. These came to be called static semantics.
Why WHILE
We need a simple example of a programming language for use in text
books and other publications. WHILE is the simplest structured language
that has a loop in it. Simpler means easier examples. The ability
to express loops is needed to get a language that is powerful enough
to be interesting.
Can you do exercise 4 on pages 31 and 32
NO! The expression "(a+c)/d$" contain two parentheses "()" and
the parentheses are not in the grammar. So, the given grammar
can not fit the given string.
I think that there are missing definitions:
Why is the Bohm Proof that Gotos are not needed important
To be precise it is the Bohm & Jaccopini Proof.
It is important because at about the time that it was published people had observed that programs that had lots of Goto statements where hard to understand. Edsger Dijkstra's letter "Gotos considered harmful" notes that he found student work harder to understand when his students used Gotos.
In other words: just when we we getting the feeling that the Goto statement was not a good idea, Bohm and Jaccopini proved that we didn't need it. And so the structured paradigm arrived.... with about 200 papers on removing Gotos being published in the next year or so!
There is no truth to Donald Knuth's joke that Professor Goto of Tokyo University was very angry when he saw all the papers on this topic.
Can you explain the rules about negation on page 21
The book has the equivalent of:
In practice (not theory) it is worth adding extra definitions and given good names to the nonterminals in a grammar:
Why does the program in question 6 (page 32) reverse the assignment of t and a
The code is
What does "od" mean in the WHILE language
"od" is the reverse of "do". This is a convention invented by
the Algol 68 team that terminated each "do" with an "od" and
each "if" by a "fi". The alternatives include the Ada convention
of "do"...."end do" and "if"...."end if", or the C/C++/Java
use of "{" and "}". Also compare with the use
of start and end tags in XML/HTML/SGML:
<body> ... </body>
<ol> .... </ol>and so on.
Does the Java code in question 5 on page 32 work
No. There are semicolons missing. See
[ Terminators and Separators ]
above.
I'm also a suspicious of the "write" function!
I think this piece of code started out in Pascal....
. . . . . . . . . ( end of section Questions) <<Contents | Index>>
Exercises
. . . . . . . . . ( end of section Exercises) <<Contents | Index>>
Laboratory 3
I plan to point you at web sites that are full of the syntax
(BNF) of languages. I think I will ask each person to
explore alone, and then report to the group (one sentence, one URL)
at the end of the lab session what they have found.
Possible start:
[ http://www.csci.csusb.edu/dick/samples/ ]
Next
Study chapter 3 on semantics pages 34 to 47 inclusive.
[ 04.html ]
. . . . . . . . . ( end of section CSCI620 Session 3) <<Contents | Index>>
Glossary