Due: Monday, October 3, 2016, 11:59 pm

Part I: C Syntax

The purpose of this part is to understand the usage of .h and .c files, the keyword extern, and the concept of prototype in C.

You are expected to implement a stack by using an array. Your program should be able to use the stack to save a list of integers and print out the list in the original order and the reverse order.


  1. Create a cstk.h. The .h file should contain the necessary sturctures and the declarations of the member functions. In this project, we use the following structure and member functions.
      	typedef structure stack {
      		int* stack;
      		int top;
      	} Stack;
    • Stack *stk_create(int) creates a stack with the size specified by the int value
    • void stk_destroy (Stack*) recycles a stack
    • void stk_push(Stack*, int) adds a new value to the top of the stack
    • int stk_pop(Stack*) removes a value from the top of the stack
    • void stk_display(Stack*, int) prints out the list in the reverse order if the int value is 1, otherwise, prints out in the original order
  2. Create a cstk.c file. This file should contain the implementation of the member functions declared in the cstk.h file. In this project, you are expected to specify the capacity of your stack as a glocal variable int CSTK_MAX = 50; in cstk.c file. Use extern to make the global variable is accessable in the test file, cstktest.c.
  3. Download cstktest.c. Read the code and understand it. Compile and run the codes as follow

    gcc -o cstktest cstktest.c cstk.c


    Your output should be

    The original list: 0 1 2 3 4 5 6 7 8 9 
    The reversed list: 9 8 7 6 5 4 3 2 1 0 

Part II: Syntax of Selected Languages

In this project you'll start learning your selected languages.


  1. Write an example program in each language that demonstrates the rules for identifier naming, variable declarations and identifier scoping. Focus on any special rules or capabilities of your language. Name your programs to task1.xx (e.g. task1.py, task1.java). Make a wiki page with the code and a brief explanation how the scoping rules apply to the code.

  2. Write an example program in each language that executes a binary search on a list or array of numbers. Make it a function/method, if possible. Name your programs to task2.xx. Make a wiki page that explains the basic syntax of the language, using the binary search program as an example.

  3. Write an example program in each language that demonstrates all of the basic built-in types and how to construct aggregate types (e.g., records, classes or structures). The program should demonstrate which of the standard suite of operators (+-/*%) manipulate which types and what the resulting type of each operation is. Use it to explain the type system in your language. Name your programs to task3.xx.


  1. A perfectly acceptable extension for any assignment going forward is to do a third language.
  2. Write other example programs that show unique features of the syntax, naming, or scoping in the selected language.
  3. If the selected language has a built-in capability for binary search, include an example of using it.
  4. Come up with an example of just how horribly you can write the binary search program using the selected language, making it as difficult as possible to understand what is going on. Use this as an example of how syntactic or semantic rules permit obfuscation.
  5. Make a compilable and runnable haiku in the selected language. Less strict forms of poetry are also acceptable.
  6. Demonstrate whether functions are a basic data type in your language. Can a variable hold an arbitrary function?
  7. Make your stack more robust so that it can handle the overflow.
  8. Create new member functions for your stack.


The submission of this project has three components:

  1. Codes: Your cstk.h, cstk.c, and cstktest.c of part I, your source codes for tasks of part II, and your source codes for extensions should be submitted to the fileserver. Please make the filename of your source codes reflect the tasks or extensions.Note that the quality of your comments counts toward your grade.
  2. README: You need to submit a README file to the fileserver for your C codes of this project. The README file can be a .txt file. It should be well-organized in a way that readers can easily know the usage and the outputs of the source codes in C and the selected languages. In addition, the known bugs of your codes should also be indicated in the README file. Please also indicate the version of your C complier, your operationg system, and its version in the README file.
  3. Wiki write-up: The write-up of this project should have the following elements.
    • Title of the project and your name
    • You are expected to have a section for each task of part II. Every secotion should contain the snapshot of your sample programs, the outputs, and your explanations.
    • If you take extensions in the selected languages, you are expected to have a section for each extension, providing sample programs, outputs, and explanations.

Please note that it is your responsibility to explicitly indicate the extensions you have taken. If you take the extensions in C stack, please indicate explicitly in the codes and README file. If you take the extension in selected languages, please indicate explicitly in your wiki write-up.

© 2016 Ying Li. Page last modified: .