Lab Assignment--Tokenizing and Parsing


Lab Code

To get the sample and exercise code, please use the following commands in the directory that you have created for this lab:
    wget www.labs.cs.uregina.ca/330/Linux/Lab3.zip
    unzip Lab3.zip

Part 1-Examine and Modify Existing Code

Use the starting code (files: HALmod.cpp, HALmod.h, and main.cpp)
  1. Store the answer to the following questions as comments at the beginning of main.cpp:
    1. What is Dr. Hilderman's code tokenizing based on (ie. what delimeter(s) separate(s) his words)?
    2. What are two reasons why his tokens are strings instead of c strings
  2. Add functionality to the processCommand function so that "lo" will also cause the shell to exit

Part 2-Extend the Code

We want to be able to turn the tokens array into an array of c strings (In other words, in the format of char **). Build the following functions and call them from main:

A sample run might look something like the following

a049840[8]%./demo
HALshell> This is a test
The words in reverse are: test a is This
HALshell> to see what happens
The words in reverse are: happens what see to
HALshell> It is a success
The words in reverse are: success a is It
HALshell> lo
The words in reverse are: lo

HALshell: terminating ...

When you run your code through valgrind using:
valgrind --leak-check=yes ./demo
A message like the following should be displayed:

==23683== 
==23683== HEAP SUMMARY:
==23683==     in use at exit: 0 bytes in 0 blocks
==23683==   total heap usage: 46 allocs, 46 frees, 992 bytes allocated
==23683== 
==23683== All heap blocks were freed -- no leaks are possible
==23683== 
==23683== For counts of detected and suppressed errors, rerun with: -v
==23683== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

Deliverables:

Submit 4 files to URCourses:
  1. code for HALmod.cpp
  2. code for HALmod.h
  3. code for main.cpp
  4. script of run using valgrind

Notes