C:\Users\brock\Documents\CSCI 255\NetBeans\RL Assign\RLparse.c
/* This file contains a section for modification */

/*
 * Outline file for RL compilation
 * Lots of work to be done here!
 *
 * Copyright J. Dean Brock, 2010
 * This file released under terms of the GNU General Public License
 *
 */


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>

#include "RLparse.h"
#include "RLtoken.h"

void UpCaseName(char *s) {
    while (*s) {
        *s = toupper(*s) ;
        ++s ;
    }
}


struct RLAssignmentNode *parseRL(FILE * f) {
    enum TokenType T1, T2, T3, T4, T5, T6 ;
    char valTar[RLVARSIZE+1] ;
    char valOp1[RLVARSIZE+1] ;
    char valOp2[RLVARSIZE+1] ;
    char betternot[RLVARSIZE] ;
    struct RLAssignmentNode *head, *tail, *present ;

    head = tail = (struct RLAssignmentNode *) NULL ;

    while (1) {
        T1 = getNextToken(stdin, valTar) ;
        if (T1 == tokEoF || T1 == tokErr)
            return head ;
        T2 = getNextToken(stdin, betternot) ;
        T3 = getNextToken(stdin, valOp1) ;
        T4 = getNextToken(stdin, betternot) ;
        T5 = getNextToken(stdin, valOp2) ;
        T6 = getNextToken(stdin, betternot) ;
        if (T1 == tokVar
              && T2 == tokEq
              && (T3 == tokVar || T3 == tokConst)
              && (T4 == tokSer || T4 == tokPar)
              && (T5 == tokVar || T5 == tokConst)
              && T6 == tokEoL) {
            UpCaseName(valTar) ;
            UpCaseName(valOp1) ;   /* Does nothing is digits */
            UpCaseName(valOp2) ;
            /* Tokens are loaded.  Ready to allocate! */

            present = (struct RLAssignmentNode *)malloc(sizeof *present) ;
            present->next = (struct RLAssignmentNode *) NULL ;

            /* RL Modification A:
             * valTar, valOp1, and valOp2 are loaded with the token values
             * and T3, T4, and T5 are loaded with the token types needed
             * to fill in the fields of present.
             *
             * Your task is to write the code to fill in this fields.
             *
             * Use strncpy to copy the variables.
             * Use atof to convert strings to constant values.
             *
             * Twenty lines of code were deleted here.
             * This code contained three if-then-else statements.
             *
             */

            if (head == (struct RLAssignmentNode *)NULL) {
                head = present ;
                tail = present ;
            } else {
                tail->next = present ;
                tail = present ;
            }
        } else
            return head ;
    }
}