ECE 209 / CSCI 255 Assignment 7B

This is not a full assignment. It's one-half of one.

Due date

This assignment must be submitted as a single file named RLvartab.c for Assignment 7B of the ECE 209.602 section on UNCA moodle by 11:45 PM on 30 November.

Your program should be written in standard ANSI C.

Getting started

Be sure you have read the RL Assignment overview.

Your task

Modification B is performed in the RLVTinsert and the RLVTLookup functions within RLvartab.c.

The first modification is very small. Only two statements are required.

        /* RL Modification B -- part 1:
         * The new node is created (as newNode) and its variable
         * field has been initialized to point to p.
         * Your *only* job is to insert it into the list
         * right after prevNode.
         * Only TWO lines of code are required for this!

The second modification is a bit more. It requires completing a while that contains an if-else. It's actually only about five lines of code. Those five lines are the traditional code for searching a linked list.

    /* RL Modification B -- part 2:
     * Write a little loop that moves presNode through the
     * chain until either searchVar is found in the Target
     * field (using strncmp to test) or dummyNode is reached.
     * The while loop is similar to the one found in RLVTinsert;
     * but it is much simpler.  Since you are not inserting, you don't
     * have to do that prevNode->next stuff.
     * Return NULL if you don't find the node.
     * A single while loop and an if-else was removed from here.
     * The return of NULL that remains should be the else of your if-else.

What should happen

Your program should now be able to print the message that it is Interpreting RL and a few others. That's pretty much all you'll see.


Draw the linked list out on a piece of paper to make sure you know what you are doing. If you must Wikipediate, these are singly linked lists with dummy nodes.

Instructor fopa

In order to see if you program is running OK, add the following section of code in your main routine, right after the call to interpretRL. Try to use the RL variables A, CAT, COW, and F but not U in your test input.

   if (1) {
     /* Put the variables you want printed in the following array
      * But always leave NULL at the end!
     char *printThese[] = { "A", "CAT", "COW", "F", "U", NULL } ;
     struct RLVariableNode *var ;
     char **varName ;
     for (varName = printThese; *varName != NULL; ++varName) {
       printf("Looking up variable %s\n", *varName) ;
       var = RLVTlookup(RLvars, *varName) ;
       if (var == NULL) {
         printf("  NULL returned on lookup for %s\n", *varName ) ;
       } else {
         printf("  %s is %.0f\n", *varName, var->value) ;

I'm also going to use this as my test input.

A = F + 10
CAT = 2009 | 255
COW = CAT + 209