Programming Languages (CSC-302 98S)
Outline of Class 5: Syntax
Held: Wednesday, January 28, 1998
- Tomorrow at 4:15 in Science 2424 the department will be showing
"The Proof", a film about the proof of Fermat's last theorem.
This had been a major open problem in mathematics, and was only
solved in the past few years.
- The program I used to generate the syllabus got some counts wrong.
It's also taking a little bit longer to cover some topics. Hence,
I've removed the presentations from the
- While I'm trying to get the class outlines done in advance, it's looking
more and more doubtful that I'll always have them done the day in advance.
Sorry; it's an incredibly busy term for me.
- Don't forget that
assignment one is due
today (at the beginning of class).
- I was sorry to see so few of you at the exotic programming languages
discussion group. I hope to see more of you next week.
- The syntax of a language is (describes?) the way a language
looks: the symbols and combinations of symbols that form valid
- At times, the syntax describes a superset of the valid utterances;
if we said that every "noun-phrase transitive-verb noun-phrase" sequence
was an English sentence, we'd allow some meaningless sentences like
"the dog flew an ice-cream cone".
- The syntax is also used to assign "types" to utterances (e.g., this
is a noun-phrase, this is a sentence, this is a program, this is a
- From the syntactic perspective, a language is a potentially
infinite set of strings built from symbols in a base alphabet.
- A string is a fine linear sequence of symbols from the
- Often, we build a language from multiple grammars. One simple grammar
is used to build a simpler alphabet which the next grammar can then
process in more interesting ways.
- For example, the process of finding identifiers, numbers, and such
is much easier than that of finding the various types of statements
in a language.
- If it's possible to build a fast program to find identifiers and such,
this can simplify and speed the other program.
- The simple processing is often called lexical analysis.
- The more complicated processing is then called syntax analysis.
- How do you describe the syntax of the language?
- It depends on the language.
- If the language is finite, you could list all the valid utterances.
- If the language is infinite, you'd like a finite method of
describing the language.
- A grammar is a formal set of rules that describe the
valid sentences in a language. It defines the syntax
of the language.
- From one perspective, grammars provide predicates. Given a string,
a grammar can answer the question "is this string in the language".
- But grammars might be used for other purposes. They might
be used to generate strings in the language.
- As computer scientists, we look for grammars that provide computationally
efficient ways of determining whether or not a string is in a language.
- Often, we work with generative grammars, grammars whose
rules describe how to generate the strings of the language.
- The most typical form of grammar is the BNF ("Backus Naur Form") grammar,
but there are others.
- It turns out to be much harder to parse using grammars that have
multiple nonterminals on the left, so we'll work mostly with grammars
that have only one nonterminal on the left. These are called
context-free grammars, since the replacement of a nonterminal
requires no context. That is, we can replace a nonterminal without
considering the surrounding symbols.