Exam 2 Study Guide
Apology
This "Study Guide" is really too late to serve as a guide for studying.
It might better be called a "last minute checklist." I apologize for
not being able to get something to you sooner.
Exercise 2
My code for Exercise 2 is now available. Links to the code are below.
While working on it, I noticed that the copy of JavaLexemes that I made
available to you was leaving the ending quote on the character and
String literals. If you go to the web page for the exercise, the link
to JavaLexemes.zip will give you an updated version that fixes this
problem.
Also, I reworked JavaTokenizer and JavaToken compared to what I handed
out in class. The current versions use interfaces for handling
the lists of keywords, operators, token types. These interfaces are an
implementation detail, not anything that you will be tested on.
- [ TestTokenizer.java ]
This is the main class, virtually unchanged from what I gave out
in class. Note that by printing jt.nextToken() it actually calls the
JavaToken class' toString() method.
- [ JavaToken.java ]
Here you can see the completed toString() method, as well as my
implementation of the constructors that I finally decided on. There
is a generic constructor, plus special ones for capturing the values
of character, fixed-point, and floating-point literals. The Accessor
methods have not been tested; there are intended to be used by the
parser.
Note that all the manifest constants have been moved into
interfaces, which this class "implements." That means that the
constants can be used by name without having to put a class name in
front of them.
- [ JavaTokenizer.java ]
Again, this class implements several interfaces just so it can use
the constants named in them.
This is a pretty complete tokenizer. (It won't handle things like
"i+++ j" correctly -- that would have to be written "i++ + j".) It
takes care of the fact that JavaLexemes does not process periods at
all. Once it has established that a lexeme is not a number
(floating-point numbers can have a period in them), it checks if there
are any periods in the lexeme, and if so, uses a StringTokenizer to
break the lexeme up into alternating identifiers and periods.
The following files define the interfaces used to manage fields and
constants that need to be accessed from multiple classes. Note that
fields declared in interfaces are automatically public, static, and
final.
- [ JavaKeywords.java ]
- [ JavaOperators.java ]
- [ JavaTokenTypes.java ]
- [ JavaLexemeTypes.java ]
Exam Topics
The exam will cover Exercise 2, lecture notes, and material from
Chapters 4, 5, 6, 7, and sections 1-5 of Chapter 8 of the Sebesta text.
Here is a checklist of things you should be able to do:
- Identify the lexemes and tokens in Java programs.
- Work with iterators, as in Exercise 2.
- Override the toString() method as in Exercise 2.
- Know how to convert a lexeme into a token as in Exercise 2.
- Be able to tell the scope and lifetimes of variables defined in
different parts of Java, C, and C++ programs.
- Know what parts of memory are allocated for static variables,
local variables, and dynamically allocated variables.
- Explain named constants.
- Know what steps the new operator invokes when a class is
instantiated.
- Be able to work with primitive and pointer data types.
- Be able to calculate the address of any element in a
multidimensional array given the array's starting address, the element
size, and whether the array is stored in row major or column major
order.
- Know what associative arrays, records, and unions are.
- Be able to work with data conversions and casts.
- Know how to work with break and continue statements in Java,
C, and C++.
- Be able to describe the behavior of guarded commands. Be able to
define nondeterministic execution in this context.
- Be able to define call by reference, call by value, and call by
name. Be able to give examples of each and/or to identify them.
- Be able to define in, out, and in-out parameters. Be able to give
examples of each and/or to identify them.
This checklist may be incomplete!