Programming Languages
CSCI 230, Fall semester, 2009
To the Bottom of the Page
Instructor: Dr. Shieu-Hong
Lin
Tue/Thurs. 12:00~1:15.
Location: LIBR L141
TA: Stephanie E. Greer
Textbooks
- M.
Scott, Programming
Language Pragmatics, 3rd Ed., McGraw Hill, 2009.
- Stanley
Lippman, C++
Primer, 4th Ed., Addison Wesley, 2005.
- Cay S. Horstmann, Big Java, (3rd
Edition), John Wiley & Sons, 2007.
About weekly progress report:
(Download this template)
By Thursday each week, you should spend around 5~10
minutes to
- Add the latest progress made (from last Thursday to this Thursday)
into the report, and
- email the report to Dr. Lin.
*************************************************************************************************
Week 1: Introduction to programming languages. Progress report due: Thursday Sept. 3.
Reading
#1
- Read Chapter 1 of Programming Language Pragmatics.
(Discussion: Benjamin and Leah, Tuesday Sept. 8)
- Read the syntax document of the
BIOLA programming language, study this sample source program prime.txt written in
BIOLA to probe for prime numbers, download and unzip this zip
file it to play an interpreter (which can execute source programs
written in the Biola language), use it to run
the code in prime.txt.
See the snapshots of the loading and running
of prime.txt and the parse
tree of prime.txt generated by the interpreter.
Lab #1
Using the vector class
- Refresh your memory by reading the related sections
in C++ Primer and the online MSDN document on the member
functions of STL vector class.
- Create a C++ project and in the main function to work
on the vector class to do things as described in the following.
- Declare a vector strings and name it myVect. Use
the push_back
method of the vector class to store the following three strings into myVect:
- "radius=2; ",
- "area=3.14*radius*radius;" and
- "display area;" .
- Write a loop to display all the elements myVect[i] in myVect one
by one.
- Write a loop using a vector<string>::iterator iterator to iterate through the vectot
myVect
and to display all the elements in myVect one by one.
- Call the erase method
of the vector class to delete the first element myVect[0] in myVect.
- Call the insert
method of the vector class to insert a new string "display
radius;" right before the element currently holding "display
area;" in myVect.
- Call the clear method
to clear the vector myVect into an empty vetor.
- Declare a string object s and write a loop that uses getline(cin, s) to
read in a line into s and call
the push_back method to store it in the end of
the vector myVect
as long as s is not the string
".".
- Write a loop using a vector<string>::iterator iterator to iterate through the vectot
myVect
and to display all the elements in myVect one by one.
Week 2: Syntax of Programming Languages. Progress report due: Thursday Sept. 10.
- Reading
#2: Chapter 2 of Programming Language Pragmatics. Focus on Sections
2.1~2.2 and skim through Sections 2.3~2.4. (Discussion: Joshua and Kevin, Tuesday
Sept. 8)
Programming #1: Implementing a user interface class Due Thursday Sept. 10.
Week 3: Names, Scopes, and Binding. Progress report due: Thursday Sept. 17.
- Reading
#3: Sections 3.1~3.3, 3.5 of Programming Language Pragmatics. (Discussion: Godestablishedyou
and Jeremy, Tuesday Sept. 15)
Lab #2
Using a vector of vectors for
storing tokens of a given source program and another vector of vectors for
the corresponding token category information
- Download and
examine the type definitions regarding perLineTokenVector,
vectOfTokenVects, tokenCategory,
perLineCategoryVector, and vectOfCategoryVects in the beginning of this .cpp file.
Create a C++ project to compile this file and add code in the main
function to practice how we may store the tokens of the two-line sample
source program below and their
category information in terms of vectors of vectors as described in
the following.
- "radius=2;
",
- "area=3.14*radius*radius;"
- Declare a vectOfTokenVects
object (i.e. a vector<perLineTokenVector>
object), say vOfT,
for storing the tokens of the sample source program above.
- Declare a perLineTokenVector
object (i.e. a vector<string> object), say T, and call this object T
to perform the push_back
method 4 times to store the 4 tokens "radius", "=",
"2", and ";" as 4 strings respectively
in it. Call vOfT to perform the push_back method and store a copy of T in the end of vOfT.
- Call this object T
to perform the clear method to
empty itself as an empty vector and then call this object T to perform the push_back
method 8 times to store the 8 tokens "area",
"=", "3.14", "*", "radius", "*",
and "radius", ";" as 8 strings
respectively in it. Call vOfT to
perform the push_back
method and store a copy of T in the end of vOfT.
- Write a 2-level nested loop to print out from vOfT all the
tokens of the two-line sample source program.
- Declare a vectOfCategoryVects
object (i.e. a vector< perLineCategoryVector
> object), say vOfC,
for storing the category information of the tokens of the sample source
program above.
- Declare a perLineCategoryVector
object (i.e. a vector<tokenCategory>
object), say C, and call this
object C to perform the push_back
method 4 times to store the 4 tokenCategory symbols ID_NAME, ASSIGNMENT_OP,
NUMERICAL_LITERAL, and SEMICOLON corresponding to the categories of the
4 tokens in the first line of the sample program respectively into C. Call vOfC to perform the push_back method and
store a copy of C in the end of vOfC.
- Call this object C
to perform the clear method to
empty itself as an empty vector and then call this object C to perform the push_back method
8 times to store the 8 tokenCategory symbols ID_NAME, ASSIGNMENT_OP,
NUMERICAL_LITERAL, NUMERICAL_OP, ID_NAME, NUMERICAL_OP,
ID_NAME, and SEMICOLON
corresponding to the categories of the 8 tokens in the second line of the
sample program respectively into C.
Call vOfC to perform the push_back method and store a copy of C in the end of vOfC.
- Write a 2-level nested loop to print out from vOfC the
category information of all the tokens of the two-line sample source
program.
- Homework #1 on Regular expressions and Context-free grammars. Due: Thursday
Sept. 17.
Week
4: More on Names, Scopes, and Binding
- Programming #2 (The lexical scanner
module) due: Thursday, Sept. 24.
- Exploration case 1
on binding and memory storage: See Homework
#2 Due: Thursday
Oct. 8.
Week 5: C++ STL
Sequential Containers. Progress report due:
Thursday Oct. 1.
- Reading
#5: Chapter 9 of C++ Primer.
Week 6: C++ STL
Associative Containers, Basics of Semantics.
Progress report due: Thursday Oct. 8.
- Reading
#6: (i) Sections 10.1~10.3 of Chapter 10 of C++
Primer and (ii) Section 4.1 of Programming Language Pragmatics.
- Discussion
on Homework #1 (Philip, Maureen)
& Homework #2 (Trevor, Jonathan): Tuesday Oct. 6.
- Homework #2 on memory management and binding. Due: Thursday Oct. 8.
- Programming
#3 (Implementing an expression evaluation class) due: Thursday, Oct. 15.
Lab #3
Using a map<string,float> object as
a variable table for storing the information of names and current values
of variables.
- A map is internally a search tree storing
key-and-value pairs, which can be accessed through the use of iterators and calls to the appropriate methods.
Download and examine the code in map.cpp
and compile it to see how you can (i) insert new
key-and-value pairs, (ii) examine and print out all of the current
key-and-value pairs, (iii) search for a key-and-value pair with a five
key, (iv) erase a key-and-value pair, and (v)
modify the values of the pairs using a loop. Note that when printing out the contents in the map it is in
order of the keys even if the pairs were inserted into the map in any
random order. This is because the map is internally a search tree that
automatically provides a way to sort out things in order of the keys when
we traverse the search tree through the iterator.
- Another very convenient way to use a map is to view
it as an associative array. Given a valid non-negative integer key index i, an ordinary array X
maps it to the value X[i]. (Note that if
i is not a valid index, accessing X[i] can crash your program.) Given a valid
key string s,
a map<string,float>
object Y maps
it to the float value Y[i].
(Note that if s is not a key to any values currently stored
in the map, accessing Y[s] will create a new key-and-value pair to
map s to
some Y[s]
to something.) Download and examine the code in mapAsAssociativeArray.cpp and compile it to see
how you can (i) insert new key-and-value pairs,
(ii) examine and print out all of the current key-and-value pairs, (iii)
modify the value of a key-and-value pair, and (iv) erase
a key-and-value pair with a specific key.
Week 7: Control Flow.
Progress report due: Thursday Oct. 15.
- Reading
#7: Sections 6.1~6.6 of Chapter 6 of Programming Language
Pragmatics. (Discussion: Dustin
and Matthew)
Weeks 8~9: Type
Systems & Type Checking; Torrey Conference;
Midterm Test Progress report due: Thursday Oct. 22.
- Reading #8:
(i) Sections 7.1~7.2 on type systems, 7.7 on pointers, 7.10 on equality
test and assignment from Chapter
7 of Programming Language Pragmatics. (Discussion: Joshua and Kevin). (ii) Study the the following example on types and type checking.
Programming Language Showcase
#1: Logic Programming.
- Use Eclipse using to play with
the following sample logic programming programs: 1 and 2.
Midterm take-home open-book written test: Due Thursday Nov.
5.
- Cover all things from the textbook included in Readings #1~ #8.
Weeks 10~11: Introduction to
Object-Oriented Programming & Polymorphism Progress report due: Thursday Nov. 12.
Reading #10 Due, Thursday,
Nov. 12
- Study this example of encapsulation,
inheritance, and polymorphism on a class hierarchy of 2D figures.
- Sections
9.1~9.4 of Programming Language Pragmatics on Object-Oriented Programming &
Polymorphism. (Discussion:
Godestablishedyou and Jeremy).
- Read the C++ code
and download its C++
project & executable to explore the use of static members, virtual
methods, constructors, destructors, inheritance, dynamic binding, and
polymorphism. (Discussion:
Trevor, Jonathan)
Programming #4 (A partial
implementation of the interpreter): Due: Thursday, Nov. 19.
Weeks 12: Building a Runnable Program
Progress report due: Thursday Nov. 19.
Sample questions from earlier reading
reports
Reading #12:
Chapter 14 of Programming Language Pragmatics. (Discussion: Philip and Maureen) Due, Thursday,
Nov. 19
Weeks 13: Object-Oriented
Programming & Polymorphism in C++
Progress report due: Thursday Dec. 3.
Lab #4: Lab assignment on inheritance and polymorphism.
Reading #13: Chapter 13 and Chapter 15 of C++ Primer.
Programming
#5 (Full implementation of the interpreter) Thursday, Dec. 18.
*************************************************************************************************
Email
your source code (.h and .cpp files) and this self-evaluation report
of each programming assignment to our TA, Stephanie E. Greer.
To
the Top of the Page