Programming Languages (CSC-302 98S)
Outline of Class 7: More Grammars
Held: Monday, February 2, 1998
- Assignment one is now
graded (at least all that I received by Friday are graded).
- A set of notes on that
assignment are also available. I don't guarantee that I'll produce
notes for all assignments.
- Since it is nearly impossible to give numerical evaluations of
textual answers, I used a check-based system. A check means that
you got a question mostly right, perhaps with a few errors. A
check plus means that you provided an especially insightful answer.
A check minus means that there were significant problems with
your answer. A zero means that your answer was unacceptable. I then
tallied your results to come up with a letter grade.
- Don't forget about today's brown bag lunch. Today is the second part of the
- Don't forget about tomorrow's exotic programming languages group meeting.
- This Thursday at 4:15, selected math and CS faculty will be discussing
summer research opportunities. Come hear how you can get both money and
credit while participating in interesting projects.
- This Thursday at 7:30, Mike Jipping from Hope college will be speaking
on threads in Java. His talk is based in part on work done with
undergraduates as part of Hope's REU program.
- Today we'll begin the class with a
quiz. The quiz won't be
available until class time.
- Recall that last class we worked on developing a grammar for
arithmetical expressions and found a way to add precedence to the
- Today we'll look at associativity in the same grammar.
- Have we solved the precedence problem? No. You'll observe
that we can still misparse the original expression (although with a
- How do we handle precedence?
- By considering which tree is correct.
- By considering why the incorrect tree is incorrect.
- By trying to change the grammar to eliminate the incorrect tree.
- Why is the incorrect tree incorrect? Because there is
unparenthesized subtraction to "the right of" subtraction.
- What should we do? Come up with a category for
"no unparenthesized subtraction".
- Do we have such a category? Yes, we called it
Exp ::= Exp AddOp Term
- Have we changed the language? No, but the proof is more
- We could further extend this grammar in many ways.
- Include the unary operators.
Note that each at most one unary operator is typically used
-+num is meaningless, as is
- Include exponentiation. Is exponentiation left or right associative?
- Include other operations.
- Function calls.
- These extensions are left as an exercise to the reader.